From 54c0aca53ac20bb16704b15aa0284eb421ef5e7a Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Tue, 23 Jul 2024 15:07:05 +0900 Subject: [PATCH] feature. add GetCloudServices to stack-template API --- api/swagger/docs.go | 136 +++++++++++++++-------- api/swagger/swagger.json | 136 +++++++++++++++-------- api/swagger/swagger.yaml | 93 ++++++++++------ internal/delivery/api/endpoint.go | 1 + internal/delivery/http/stack-template.go | 55 +++++++-- internal/route/route.go | 1 + internal/usecase/stack-template.go | 23 ++++ pkg/domain/stack-template.go | 4 + 8 files changed, 314 insertions(+), 135 deletions(-) diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 9aff60bb..fdcedb78 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -8136,6 +8136,13 @@ const docTemplate = `{ ], "summary": "Get Organization StackTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "type": "string", "description": "pageSize", @@ -8198,6 +8205,13 @@ const docTemplate = `{ ], "summary": "Remove organization stackTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "Remove organization stack templates request", "name": "body", @@ -8232,6 +8246,13 @@ const docTemplate = `{ ], "summary": "Add organization stackTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "Add organization stack templates request", "name": "body", @@ -8249,6 +8270,43 @@ const docTemplate = `{ } } }, + "/organizations/{organizationId}/stack-templates/cloud-services": { + "get": { + "security": [ + { + "JWT": [] + } + ], + "description": "Get Organization CloudServices", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "StackTemplates" + ], + "summary": "Get Organization CloudServices", + "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetStackTemplatesResponse" + } + } + } + } + }, "/organizations/{organizationId}/stack-templates/{stackTemplateId}": { "get": { "security": [ @@ -8267,6 +8325,22 @@ const docTemplate = `{ "StackTemplates" ], "summary": "Get Organization StackTemplate", + "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "stackTemplateId", + "name": "stackTemplateId", + "in": "path", + "required": true + } + ], "responses": { "200": { "description": "OK", @@ -13702,6 +13776,7 @@ const docTemplate = `{ "github_com_openinfradev_tks-api_pkg_domain.ImportClusterRequest": { "type": "object", "required": [ + "kubeconfig", "name", "organizationId", "stackTemplateId" @@ -13716,18 +13791,27 @@ const docTemplate = `{ "description": { "type": "string" }, - "kubeconfig": { + "domains": { "type": "array", "items": { - "type": "integer" + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ClusterDomain" } }, + "kubeconfig": { + "type": "string" + }, "name": { "type": "string" }, "organizationId": { "type": "string" }, + "policyIds": { + "type": "array", + "items": { + "type": "string" + } + }, "stackTemplateId": { "type": "string" } @@ -13744,30 +13828,20 @@ const docTemplate = `{ "github_com_openinfradev_tks-api_pkg_domain.ImportStackRequest": { "type": "object", "required": [ - "cloudService", + "kubeconfig", "name", "stackTemplateId" ], "properties": { - "cloudAccountId": { - "type": "string" - }, - "cloudService": { - "type": "string", - "enum": [ - "AWS", - "BYOH" - ] - }, - "clusterId": { - "type": "string" - }, "description": { "type": "string" }, "domain": { "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.StackDomain" }, + "kubeconfig": { + "type": "string" + }, "name": { "type": "string" }, @@ -13779,36 +13853,6 @@ const docTemplate = `{ }, "stackTemplateId": { "type": "string" - }, - "tksCpNode": { - "type": "integer" - }, - "tksCpNodeMax": { - "type": "integer" - }, - "tksCpNodeType": { - "type": "string" - }, - "tksInfraNode": { - "type": "integer" - }, - "tksInfraNodeMax": { - "type": "integer" - }, - "tksInfraNodeType": { - "type": "string" - }, - "tksUserNode": { - "type": "integer" - }, - "tksUserNodeMax": { - "type": "integer" - }, - "tksUserNodeType": { - "type": "string" - }, - "userClusterEndpoint": { - "type": "string" } } }, diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 48a9e924..df599c82 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -8130,6 +8130,13 @@ ], "summary": "Get Organization StackTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "type": "string", "description": "pageSize", @@ -8192,6 +8199,13 @@ ], "summary": "Remove organization stackTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "Remove organization stack templates request", "name": "body", @@ -8226,6 +8240,13 @@ ], "summary": "Add organization stackTemplates", "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, { "description": "Add organization stack templates request", "name": "body", @@ -8243,6 +8264,43 @@ } } }, + "/organizations/{organizationId}/stack-templates/cloud-services": { + "get": { + "security": [ + { + "JWT": [] + } + ], + "description": "Get Organization CloudServices", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "StackTemplates" + ], + "summary": "Get Organization CloudServices", + "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetStackTemplatesResponse" + } + } + } + } + }, "/organizations/{organizationId}/stack-templates/{stackTemplateId}": { "get": { "security": [ @@ -8261,6 +8319,22 @@ "StackTemplates" ], "summary": "Get Organization StackTemplate", + "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "stackTemplateId", + "name": "stackTemplateId", + "in": "path", + "required": true + } + ], "responses": { "200": { "description": "OK", @@ -13696,6 +13770,7 @@ "github_com_openinfradev_tks-api_pkg_domain.ImportClusterRequest": { "type": "object", "required": [ + "kubeconfig", "name", "organizationId", "stackTemplateId" @@ -13710,18 +13785,27 @@ "description": { "type": "string" }, - "kubeconfig": { + "domains": { "type": "array", "items": { - "type": "integer" + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.ClusterDomain" } }, + "kubeconfig": { + "type": "string" + }, "name": { "type": "string" }, "organizationId": { "type": "string" }, + "policyIds": { + "type": "array", + "items": { + "type": "string" + } + }, "stackTemplateId": { "type": "string" } @@ -13738,30 +13822,20 @@ "github_com_openinfradev_tks-api_pkg_domain.ImportStackRequest": { "type": "object", "required": [ - "cloudService", + "kubeconfig", "name", "stackTemplateId" ], "properties": { - "cloudAccountId": { - "type": "string" - }, - "cloudService": { - "type": "string", - "enum": [ - "AWS", - "BYOH" - ] - }, - "clusterId": { - "type": "string" - }, "description": { "type": "string" }, "domain": { "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.StackDomain" }, + "kubeconfig": { + "type": "string" + }, "name": { "type": "string" }, @@ -13773,36 +13847,6 @@ }, "stackTemplateId": { "type": "string" - }, - "tksCpNode": { - "type": "integer" - }, - "tksCpNodeMax": { - "type": "integer" - }, - "tksCpNodeType": { - "type": "string" - }, - "tksInfraNode": { - "type": "integer" - }, - "tksInfraNodeMax": { - "type": "integer" - }, - "tksInfraNodeType": { - "type": "string" - }, - "tksUserNode": { - "type": "integer" - }, - "tksUserNodeMax": { - "type": "integer" - }, - "tksUserNodeType": { - "type": "string" - }, - "userClusterEndpoint": { - "type": "string" } } }, diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 2c0a0d7a..d18429fe 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -2158,17 +2158,24 @@ definitions: type: string description: type: string - kubeconfig: + domains: items: - type: integer + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.ClusterDomain' type: array + kubeconfig: + type: string name: type: string organizationId: type: string + policyIds: + items: + type: string + type: array stackTemplateId: type: string required: + - kubeconfig - name - organizationId - stackTemplateId @@ -2180,19 +2187,12 @@ definitions: type: object github_com_openinfradev_tks-api_pkg_domain.ImportStackRequest: properties: - cloudAccountId: - type: string - cloudService: - enum: - - AWS - - BYOH - type: string - clusterId: - type: string description: type: string domain: $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.StackDomain' + kubeconfig: + type: string name: type: string policyIds: @@ -2201,28 +2201,8 @@ definitions: type: array stackTemplateId: type: string - tksCpNode: - type: integer - tksCpNodeMax: - type: integer - tksCpNodeType: - type: string - tksInfraNode: - type: integer - tksInfraNodeMax: - type: integer - tksInfraNodeType: - type: string - tksUserNode: - type: integer - tksUserNodeMax: - type: integer - tksUserNodeType: - type: string - userClusterEndpoint: - type: string required: - - cloudService + - kubeconfig - name - stackTemplateId type: object @@ -9666,6 +9646,11 @@ paths: - application/json description: Get Organization StackTemplates parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: pageSize in: query name: pageSize @@ -9706,6 +9691,11 @@ paths: - application/json description: Add organization stackTemplates parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: Add organization stack templates request in: body name: body @@ -9727,6 +9717,11 @@ paths: - application/json description: Remove organization stackTemplates parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string - description: Remove organization stack templates request in: body name: body @@ -9748,6 +9743,17 @@ paths: consumes: - application/json description: Get Organization StackTemplate + parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string + - description: stackTemplateId + in: path + name: stackTemplateId + required: true + type: string produces: - application/json responses: @@ -9760,6 +9766,29 @@ paths: summary: Get Organization StackTemplate tags: - StackTemplates + /organizations/{organizationId}/stack-templates/cloud-services: + get: + consumes: + - application/json + description: Get Organization CloudServices + parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetStackTemplatesResponse' + security: + - JWT: [] + summary: Get Organization CloudServices + tags: + - StackTemplates /organizations/{organizationId}/stacks: get: consumes: diff --git a/internal/delivery/api/endpoint.go b/internal/delivery/api/endpoint.go index d8099b20..423df5d0 100644 --- a/internal/delivery/api/endpoint.go +++ b/internal/delivery/api/endpoint.go @@ -111,6 +111,7 @@ const ( GetOrganizationStackTemplate AddOrganizationStackTemplates RemoveOrganizationStackTemplates + GetOrganizationCloudServices // Dashboard CreateDashboard diff --git a/internal/delivery/http/stack-template.go b/internal/delivery/http/stack-template.go index 78faf378..3cdf43a3 100644 --- a/internal/delivery/http/stack-template.go +++ b/internal/delivery/http/stack-template.go @@ -350,12 +350,13 @@ func (h *StackTemplateHandler) UpdateStackTemplateOrganizations(w http.ResponseW // @Description Get Organization StackTemplates // @Accept json // @Produce json -// @Param pageSize query string false "pageSize" -// @Param pageNumber query string false "pageNumber" -// @Param soertColumn query string false "sortColumn" -// @Param sortOrder query string false "sortOrder" -// @Param filters query []string false "filters" -// @Success 200 {object} domain.GetStackTemplatesResponse +// @Param organizationId path string true "organizationId" +// @Param pageSize query string false "pageSize" +// @Param pageNumber query string false "pageNumber" +// @Param soertColumn query string false "sortColumn" +// @Param sortOrder query string false "sortOrder" +// @Param filters query []string false "filters" +// @Success 200 {object} domain.GetStackTemplatesResponse // @Router /organizations/{organizationId}/stack-templates [get] // @Security JWT func (h *StackTemplateHandler) GetOrganizationStackTemplates(w http.ResponseWriter, r *http.Request) { @@ -401,6 +402,34 @@ func (h *StackTemplateHandler) GetOrganizationStackTemplates(w http.ResponseWrit ResponseJSON(w, r, http.StatusOK, out) } +// GetOrganizationCloudServices godoc +// +// @Tags StackTemplates +// @Summary Get Organization CloudServices +// @Description Get Organization CloudServices +// @Accept json +// @Produce json +// @Param organizationId path string true "organizationId" +// @Success 200 {object} domain.GetStackTemplatesResponse +// @Router /organizations/{organizationId}/stack-templates/cloud-services [get] +// @Security JWT +func (h *StackTemplateHandler) GetOrganizationCloudServices(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + organizationId, ok := vars["organizationId"] + if !ok { + ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid organizationId"), "C_INVALID_ORGANIZATION_ID", "")) + return + } + cloudServices, err := h.usecase.GetCloudServices(r.Context(), organizationId) + if err != nil { + ErrorJSON(w, r, err) + return + } + var out domain.GetCloudServicesResponse + out.CloudServices = cloudServices + ResponseJSON(w, r, http.StatusOK, out) +} + // GetOrganizationStackTemplate godoc // // @Tags StackTemplates @@ -408,7 +437,9 @@ func (h *StackTemplateHandler) GetOrganizationStackTemplates(w http.ResponseWrit // @Description Get Organization StackTemplate // @Accept json // @Produce json -// @Success 200 {object} domain.GetStackTemplateResponse +// @Param organizationId path string true "organizationId" +// @Param stackTemplateId path string true "stackTemplateId" +// @Success 200 {object} domain.GetStackTemplateResponse // @Router /organizations/{organizationId}/stack-templates/{stackTemplateId} [get] // @Security JWT func (h *StackTemplateHandler) GetOrganizationStackTemplate(w http.ResponseWriter, r *http.Request) { @@ -500,8 +531,9 @@ func (h *StackTemplateHandler) CheckStackTemplateName(w http.ResponseWriter, r * // @Description Add organization stackTemplates // @Accept json // @Produce json -// @Param body body domain.AddOrganizationStackTemplatesRequest true "Add organization stack templates request" -// @Success 200 {object} nil +// @Param organizationId path string true "organizationId" +// @Param body body domain.AddOrganizationStackTemplatesRequest true "Add organization stack templates request" +// @Success 200 {object} nil // @Router /organizations/{organizationId}/stack-templates [post] // @Security JWT func (h *StackTemplateHandler) AddOrganizationStackTemplates(w http.ResponseWriter, r *http.Request) { @@ -534,8 +566,9 @@ func (h *StackTemplateHandler) AddOrganizationStackTemplates(w http.ResponseWrit // @Description Remove organization stackTemplates // @Accept json // @Produce json -// @Param body body domain.RemoveOrganizationStackTemplatesRequest true "Remove organization stack templates request" -// @Success 200 {object} nil +// @Param organizationId path string true "organizationId" +// @Param body body domain.RemoveOrganizationStackTemplatesRequest true "Remove organization stack templates request" +// @Success 200 {object} nil // @Router /organizations/{organizationId}/stack-templates [put] // @Security JWT func (h *StackTemplateHandler) RemoveOrganizationStackTemplates(w http.ResponseWriter, r *http.Request) { diff --git a/internal/route/route.go b/internal/route/route.go index 79341469..df7e5304 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -198,6 +198,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/stack-templates/{stackTemplateId}", customMiddleware.Handle(internalApi.Admin_UpdateStackTemplate, http.HandlerFunc(stackTemplateHandler.UpdateStackTemplate))).Methods(http.MethodPut) r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/stack-templates/{stackTemplateId}", customMiddleware.Handle(internalApi.Admin_DeleteStackTemplate, http.HandlerFunc(stackTemplateHandler.DeleteStackTemplate))).Methods(http.MethodDelete) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stack-templates", customMiddleware.Handle(internalApi.GetOrganizationStackTemplates, http.HandlerFunc(stackTemplateHandler.GetOrganizationStackTemplates))).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stack-templates/cloud-services", customMiddleware.Handle(internalApi.GetOrganizationCloudServices, http.HandlerFunc(stackTemplateHandler.GetOrganizationCloudServices))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stack-templates/{stackTemplateId}", customMiddleware.Handle(internalApi.GetOrganizationStackTemplate, http.HandlerFunc(stackTemplateHandler.GetOrganizationStackTemplate))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stack-templates", customMiddleware.Handle(internalApi.AddOrganizationStackTemplates, http.HandlerFunc(stackTemplateHandler.AddOrganizationStackTemplates))).Methods(http.MethodPost) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stack-templates", customMiddleware.Handle(internalApi.RemoveOrganizationStackTemplates, http.HandlerFunc(stackTemplateHandler.RemoveOrganizationStackTemplates))).Methods(http.MethodPut) diff --git a/internal/usecase/stack-template.go b/internal/usecase/stack-template.go index 41c95a46..feedea43 100644 --- a/internal/usecase/stack-template.go +++ b/internal/usecase/stack-template.go @@ -33,6 +33,7 @@ type IStackTemplateUsecase interface { AddOrganizationStackTemplates(ctx context.Context, organizationId string, stackTemplateIds []string) error RemoveOrganizationStackTemplates(ctx context.Context, organizationId string, stackTemplateIds []string) error GetTemplateIds(ctx context.Context) ([]string, error) + GetCloudServices(ctx context.Context, organizationId string) ([]string, error) } type StackTemplateUsecase struct { @@ -278,6 +279,28 @@ func (u *StackTemplateUsecase) GetTemplateIds(ctx context.Context) (out []string return } +func (u *StackTemplateUsecase) GetCloudServices(ctx context.Context, organizationId string) (out []string, err error) { + stackTemplates, err := u.repo.FetchWithOrganization(ctx, organizationId, nil) + if err != nil { + return nil, err + } + + for _, stackTemplate := range stackTemplates { + bExist := false + for _, val := range out { + if val == stackTemplate.CloudService { + bExist = true + break + } + } + + if !bExist { + out = append(out, stackTemplate.CloudService) + } + } + return +} + func servicesFromIds(serviceIds []string) []byte { services := "[" for i, serviceId := range serviceIds { diff --git a/pkg/domain/stack-template.go b/pkg/domain/stack-template.go index a2cdaca4..a66f035f 100644 --- a/pkg/domain/stack-template.go +++ b/pkg/domain/stack-template.go @@ -116,3 +116,7 @@ type RemoveOrganizationStackTemplatesRequest struct { type GetStackTemplateTemplateIdsResponse struct { TemplateIds []string `json:"templateIds"` } + +type GetCloudServicesResponse struct { + CloudServices []string `json:"cloudServices"` +}