Skip to content

Commit

Permalink
fix(ui): correct method type in cluster certificate upload
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotxx committed Oct 4, 2024
1 parent 1f19a58 commit 6bef0da
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 64 deletions.
58 changes: 57 additions & 1 deletion api/openapispec/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,62 @@ var doc = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/authn": {
"get": {
"description": "This endpoint returns an authn result.",
"produces": [
"application/json"
],
"tags": [
"authn"
],
"summary": "Get returns an authn result of user's token.",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"type": "string"
}
},
"404": {
"description": "Not Found",
"schema": {
"type": "string"
}
},
"405": {
"description": "Method Not Allowed",
"schema": {
"type": "string"
}
},
"429": {
"description": "Too Many Requests",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "string"
}
}
}
}
},
"/endpoints": {
"get": {
"description": "List all registered endpoints in the router",
Expand Down Expand Up @@ -1659,7 +1715,7 @@ var doc = `{
"description": "ClusterDisplayName is the display name of cluster to be created",
"type": "string"
},
"kubeconfig": {
"kubeConfig": {
"description": "ClusterKubeConfig is the kubeconfig of cluster to be created",
"type": "string"
}
Expand Down
58 changes: 57 additions & 1 deletion api/openapispec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,62 @@
"version": "1.0"
},
"paths": {
"/authn": {
"get": {
"description": "This endpoint returns an authn result.",
"produces": [
"application/json"
],
"tags": [
"authn"
],
"summary": "Get returns an authn result of user's token.",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"type": "string"
}
},
"404": {
"description": "Not Found",
"schema": {
"type": "string"
}
},
"405": {
"description": "Method Not Allowed",
"schema": {
"type": "string"
}
},
"429": {
"description": "Too Many Requests",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "string"
}
}
}
}
},
"/endpoints": {
"get": {
"description": "List all registered endpoints in the router",
Expand Down Expand Up @@ -1642,7 +1698,7 @@
"description": "ClusterDisplayName is the display name of cluster to be created",
"type": "string"
},
"kubeconfig": {
"kubeConfig": {
"description": "ClusterKubeConfig is the kubeconfig of cluster to be created",
"type": "string"
}
Expand Down
39 changes: 38 additions & 1 deletion api/openapispec/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ definitions:
displayName:
description: ClusterDisplayName is the display name of cluster to be created
type: string
kubeconfig:
kubeConfig:
description: ClusterKubeConfig is the kubeconfig of cluster to be created
type: string
type: object
Expand Down Expand Up @@ -175,6 +175,43 @@ info:
title: Karpor
version: "1.0"
paths:
/authn:
get:
description: This endpoint returns an authn result.
produces:
- application/json
responses:
"200":
description: OK
schema:
type: string
"400":
description: Bad Request
schema:
type: string
"401":
description: Unauthorized
schema:
type: string
"404":
description: Not Found
schema:
type: string
"405":
description: Method Not Allowed
schema:
type: string
"429":
description: Too Many Requests
schema:
type: string
"500":
description: Internal Server Error
schema:
type: string
summary: Get returns an authn result of user's token.
tags:
- authn
/endpoints:
get:
consumes:
Expand Down
14 changes: 7 additions & 7 deletions pkg/core/handler/authn/authn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
// @Description This endpoint returns an authn result.
// @Tags authn
// @Produce json
// @Success 200 {string} string "OK"
// @Failure 400 {string} string "Bad Request"
// @Failure 401 {string} string "Unauthorized"
// @Failure 404 {string} string "Not Found"
// @Failure 405 {string} string "Method Not Allowed"
// @Failure 429 {string} string "Too Many Requests"
// @Failure 500 {string} string "Internal Server Error"
// @Success 200 {string} string "OK"
// @Failure 400 {string} string "Bad Request"
// @Failure 401 {string} string "Unauthorized"
// @Failure 404 {string} string "Not Found"
// @Failure 405 {string} string "Method Not Allowed"
// @Failure 429 {string} string "Too Many Requests"
// @Failure 500 {string} string "Internal Server Error"
// @Router /authn [get]
func Get() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/handler/cluster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var sortCriteriaMap = map[string]cluster.SortCriteria{
type ClusterPayload struct {
ClusterDisplayName string `json:"displayName"` // ClusterDisplayName is the display name of cluster to be created
ClusterDescription string `json:"description"` // ClusterDescription is the description of cluster to be created
ClusterKubeConfig string `json:"kubeconfig"` // ClusterKubeConfig is the kubeconfig of cluster to be created
ClusterKubeConfig string `json:"kubeConfig"` // ClusterKubeConfig is the kubeconfig of cluster to be created
}

type UploadData struct {
Expand Down
20 changes: 10 additions & 10 deletions pkg/core/manager/cluster/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestCreateCluster(t *testing.T) {
clusterName string
displayName string
description string
kubeconfig string
kubeConfig string
expectError bool
expectedErrorMessage string
}{
Expand All @@ -141,15 +141,15 @@ func TestCreateCluster(t *testing.T) {
clusterName: "new-cluster",
displayName: "New Cluster",
description: "This is a new cluster.",
kubeconfig: newMockKubeConfig(),
kubeConfig: newMockKubeConfig(),
expectError: false,
},
{
name: "Attempt to create an existing cluster",
clusterName: "existing-cluster",
displayName: "Existing Cluster",
description: "This cluster already exists.",
kubeconfig: newMockKubeConfig(),
kubeConfig: newMockKubeConfig(),
expectError: true,
expectedErrorMessage: "cluster existing-cluster already exists. Try updating it instead",
},
Expand All @@ -158,7 +158,7 @@ func TestCreateCluster(t *testing.T) {
clusterName: "invalid-kubeconfig-cluster",
displayName: "Invalid KubeConfig Cluster",
description: "This cluster has invalid kubeconfig.",
kubeconfig: "invalid",
kubeConfig: "invalid",
expectError: true,
expectedErrorMessage: "failed to parse kubeconfig",
},
Expand All @@ -172,7 +172,7 @@ func TestCreateCluster(t *testing.T) {
tc.clusterName,
tc.displayName,
tc.description,
tc.kubeconfig,
tc.kubeConfig,
)

if tc.expectError {
Expand Down Expand Up @@ -272,27 +272,27 @@ func TestUpdateCredential(t *testing.T) {
testCases := []struct {
name string
clusterName string
kubeconfig string
kubeConfig string
expectError bool
expectedError string
}{
{
name: "Update credential successfully",
clusterName: "existing-cluster",
kubeconfig: newMockKubeConfig(),
kubeConfig: newMockKubeConfig(),
expectError: false,
},
{
name: "Attempt to update credential for non-existing cluster",
clusterName: "non-existing-cluster",
kubeconfig: newMockKubeConfig(),
kubeConfig: newMockKubeConfig(),
expectError: true,
expectedError: "\"non-existing-cluster\" not found",
},
{
name: "Update credential with invalid kubeconfig",
clusterName: "existing-cluster",
kubeconfig: "invalid-kubeconfig",
kubeConfig: "invalid-kubeconfig",
expectError: true,
expectedError: "failed to parse kubeconfig",
},
Expand All @@ -304,7 +304,7 @@ func TestUpdateCredential(t *testing.T) {
context.TODO(),
&multicluster.MultiClusterClient{},
tc.clusterName,
tc.kubeconfig,
tc.kubeConfig,
)
if tc.expectError {
require.Error(t, err)
Expand Down
Loading

0 comments on commit 6bef0da

Please sign in to comment.