diff --git a/api/swagger/docs.go b/api/swagger/docs.go index b1c8289d..dd929f03 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -11266,12 +11266,21 @@ const docTemplate = `{ }, "github_com_openinfradev_tks-api_pkg_domain.CreatePolicyRequest": { "type": "object", + "required": [ + "enforcementAction", + "policyName" + ], "properties": { "description": { "type": "string" }, "enforcementAction": { "type": "string", + "enum": [ + "deny", + "dryrun", + "warn" + ], "example": "deny" }, "mandatory": { @@ -11333,7 +11342,9 @@ const docTemplate = `{ "type": "object", "required": [ "kind", - "rego" + "rego", + "severity", + "templateName" ], "properties": { "deprecated": { @@ -15068,12 +15079,22 @@ const docTemplate = `{ }, "github_com_openinfradev_tks-api_pkg_domain.UpdatePolicyRequest": { "type": "object", + "required": [ + "enforcementAction", + "policyName" + ], "properties": { "description": { "type": "string" }, "enforcementAction": { - "type": "string" + "type": "string", + "enum": [ + "deny", + "dryrun", + "warn" + ], + "example": "deny" }, "mandatory": { "type": "boolean" @@ -15110,6 +15131,9 @@ const docTemplate = `{ }, "github_com_openinfradev_tks-api_pkg_domain.UpdatePolicyTemplateRequest": { "type": "object", + "required": [ + "templateName" + ], "properties": { "deprecated": { "type": "boolean", @@ -15237,11 +15261,22 @@ const docTemplate = `{ "github_com_openinfradev_tks-api_pkg_domain.UpdateStackTemplateRequest": { "type": "object", "required": [ - "serviceIds" + "kubeType", + "kubeVersion", + "organizationIds", + "platform", + "serviceIds", + "template", + "version" ], "properties": { "cloudService": { - "type": "string" + "type": "string", + "enum": [ + "AWS", + "AZZURE", + "GCP" + ] }, "description": { "type": "string" @@ -15252,6 +15287,12 @@ const docTemplate = `{ "kubeVersion": { "type": "string" }, + "organizationIds": { + "type": "array", + "items": { + "type": "string" + } + }, "platform": { "type": "string" }, @@ -15265,7 +15306,11 @@ const docTemplate = `{ "type": "string" }, "templateType": { - "type": "string" + "type": "string", + "enum": [ + "STANDARD", + "MSA" + ] }, "version": { "type": "string" @@ -15633,7 +15678,9 @@ const docTemplate = `{ "type": "object", "required": [ "kind", - "rego" + "rego", + "severity", + "templateName" ], "properties": { "deprecated": { @@ -15987,6 +16034,9 @@ const docTemplate = `{ }, "github_com_openinfradev_tks-api_pkg_domain_admin.UpdatePolicyTemplateRequest": { "type": "object", + "required": [ + "templateName" + ], "properties": { "deprecated": { "type": "boolean", diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index c33a4906..9169d042 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -11260,12 +11260,21 @@ }, "github_com_openinfradev_tks-api_pkg_domain.CreatePolicyRequest": { "type": "object", + "required": [ + "enforcementAction", + "policyName" + ], "properties": { "description": { "type": "string" }, "enforcementAction": { "type": "string", + "enum": [ + "deny", + "dryrun", + "warn" + ], "example": "deny" }, "mandatory": { @@ -11327,7 +11336,9 @@ "type": "object", "required": [ "kind", - "rego" + "rego", + "severity", + "templateName" ], "properties": { "deprecated": { @@ -15062,12 +15073,22 @@ }, "github_com_openinfradev_tks-api_pkg_domain.UpdatePolicyRequest": { "type": "object", + "required": [ + "enforcementAction", + "policyName" + ], "properties": { "description": { "type": "string" }, "enforcementAction": { - "type": "string" + "type": "string", + "enum": [ + "deny", + "dryrun", + "warn" + ], + "example": "deny" }, "mandatory": { "type": "boolean" @@ -15104,6 +15125,9 @@ }, "github_com_openinfradev_tks-api_pkg_domain.UpdatePolicyTemplateRequest": { "type": "object", + "required": [ + "templateName" + ], "properties": { "deprecated": { "type": "boolean", @@ -15231,11 +15255,22 @@ "github_com_openinfradev_tks-api_pkg_domain.UpdateStackTemplateRequest": { "type": "object", "required": [ - "serviceIds" + "kubeType", + "kubeVersion", + "organizationIds", + "platform", + "serviceIds", + "template", + "version" ], "properties": { "cloudService": { - "type": "string" + "type": "string", + "enum": [ + "AWS", + "AZZURE", + "GCP" + ] }, "description": { "type": "string" @@ -15246,6 +15281,12 @@ "kubeVersion": { "type": "string" }, + "organizationIds": { + "type": "array", + "items": { + "type": "string" + } + }, "platform": { "type": "string" }, @@ -15259,7 +15300,11 @@ "type": "string" }, "templateType": { - "type": "string" + "type": "string", + "enum": [ + "STANDARD", + "MSA" + ] }, "version": { "type": "string" @@ -15627,7 +15672,9 @@ "type": "object", "required": [ "kind", - "rego" + "rego", + "severity", + "templateName" ], "properties": { "deprecated": { @@ -15981,6 +16028,9 @@ }, "github_com_openinfradev_tks-api_pkg_domain_admin.UpdatePolicyTemplateRequest": { "type": "object", + "required": [ + "templateName" + ], "properties": { "deprecated": { "type": "boolean", diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index ce870a9e..0d4d6e9a 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -965,6 +965,10 @@ definitions: description: type: string enforcementAction: + enum: + - deny + - dryrun + - warn example: deny type: string mandatory: @@ -993,6 +997,9 @@ definitions: templateId: example: d98ef5f1-4a68-4047-a446-2207787ce3ff type: string + required: + - enforcementAction + - policyName type: object github_com_openinfradev_tks-api_pkg_domain.CreatePolicyResponse: properties: @@ -1046,6 +1053,8 @@ definitions: required: - kind - rego + - severity + - templateName type: object github_com_openinfradev_tks-api_pkg_domain.CreatePolicyTemplateVersionRequest: properties: @@ -3492,6 +3501,11 @@ definitions: description: type: string enforcementAction: + enum: + - deny + - dryrun + - warn + example: deny type: string mandatory: type: boolean @@ -3515,6 +3529,9 @@ definitions: templateId: example: d98ef5f1-4a68-4047-a446-2207787ce3ff type: string + required: + - enforcementAction + - policyName type: object github_com_openinfradev_tks-api_pkg_domain.UpdatePolicyTemplateRequest: properties: @@ -3537,6 +3554,8 @@ definitions: templateName: example: 필수 Label 검사 type: string + required: + - templateName type: object github_com_openinfradev_tks-api_pkg_domain.UpdatePrimaryClusterRequest: properties: @@ -3602,6 +3621,10 @@ definitions: github_com_openinfradev_tks-api_pkg_domain.UpdateStackTemplateRequest: properties: cloudService: + enum: + - AWS + - AZZURE + - GCP type: string description: type: string @@ -3609,6 +3632,10 @@ definitions: type: string kubeVersion: type: string + organizationIds: + items: + type: string + type: array platform: type: string serviceIds: @@ -3618,11 +3645,20 @@ definitions: template: type: string templateType: + enum: + - STANDARD + - MSA type: string version: type: string required: + - kubeType + - kubeVersion + - organizationIds + - platform - serviceIds + - template + - version type: object github_com_openinfradev_tks-api_pkg_domain.UpdateSystemNotificationRequest: properties: @@ -3906,6 +3942,8 @@ definitions: required: - kind - rego + - severity + - templateName type: object github_com_openinfradev_tks-api_pkg_domain_admin.CreatePolicyTemplateVersionRequest: properties: @@ -4129,6 +4167,8 @@ definitions: templateName: example: 필수 Label 검사 type: string + required: + - templateName type: object github_com_openinfradev_tks-api_pkg_httpErrors.RestError: properties: diff --git a/internal/delivery/http/organization.go b/internal/delivery/http/organization.go index 4821dbdd..524e78ae 100644 --- a/internal/delivery/http/organization.go +++ b/internal/delivery/http/organization.go @@ -197,8 +197,6 @@ func (h *OrganizationHandler) GetOrganizations(w http.ResponseWriter, r *http.Re if err = serializer.Map(r.Context(), organization, &out.Organizations[i]); err != nil { log.Error(r.Context(), err) } - - log.Info(r.Context(), organization) } if out.Pagination, err = pg.Response(r.Context()); err != nil { diff --git a/internal/delivery/http/stack-template.go b/internal/delivery/http/stack-template.go index 23815272..708c769f 100644 --- a/internal/delivery/http/stack-template.go +++ b/internal/delivery/http/stack-template.go @@ -193,8 +193,15 @@ func (h *StackTemplateHandler) UpdateStackTemplate(w http.ResponseWriter, r *htt return } + input := domain.UpdateStackTemplateRequest{} + err = UnmarshalRequestInput(r, &input) + if err != nil { + ErrorJSON(w, r, err) + return + } + var dto model.StackTemplate - if err := serializer.Map(r.Context(), r, &dto); err != nil { + if err := serializer.Map(r.Context(), input, &dto); err != nil { log.Info(r.Context(), err) } dto.ID = stackTemplateId diff --git a/internal/usecase/stack-template.go b/internal/usecase/stack-template.go index 2eb0c715..403372c3 100644 --- a/internal/usecase/stack-template.go +++ b/internal/usecase/stack-template.go @@ -56,21 +56,7 @@ func (u *StackTemplateUsecase) Create(ctx context.Context, dto model.StackTempla return uuid.Nil, httpErrors.NewBadRequestError(fmt.Errorf("duplicate stackTemplate name"), "ST_CREATE_ALREADY_EXISTED_NAME", "") } - services := "[" - for i, serviceId := range dto.ServiceIds { - if i > 1 { - services = services + "," - } - switch serviceId { - case "LMA": - services = services + internal.SERVICE_LMA - case "SERVICE_MESH": - services = services + internal.SERVICE_SERVICE_MESH - } - } - services = services + "]" - dto.Services = []byte(services) - + dto.Services = servicesFromIds(dto.ServiceIds) stackTemplateId, err = u.repo.Create(ctx, dto) if err != nil { return uuid.Nil, httpErrors.NewInternalServerError(err, "", "") @@ -92,10 +78,17 @@ func (u *StackTemplateUsecase) Update(ctx context.Context, dto model.StackTempla return httpErrors.NewBadRequestError(err, "ST_NOT_EXISTED_STACK_TEMPLATE", "") } + dto.Services = servicesFromIds(dto.ServiceIds) err = u.repo.Update(ctx, dto) if err != nil { return err } + + err = u.UpdateOrganizations(ctx, dto) + if err != nil { + return err + } + return nil } @@ -233,3 +226,20 @@ func (u *StackTemplateUsecase) RemoveOrganizationStackTemplates(ctx context.Cont return nil } + +func servicesFromIds(serviceIds []string) []byte { + services := "[" + for i, serviceId := range serviceIds { + if i > 0 { + services = services + "," + } + switch serviceId { + case "LMA": + services = services + internal.SERVICE_LMA + case "SERVICE_MESH": + services = services + internal.SERVICE_SERVICE_MESH + } + } + services = services + "]" + return []byte(services) +} diff --git a/internal/usecase/stack.go b/internal/usecase/stack.go index 08cf81e8..00f42648 100644 --- a/internal/usecase/stack.go +++ b/internal/usecase/stack.go @@ -121,6 +121,12 @@ func (u *StackUsecase) Create(ctx context.Context, dto model.Stack) (stackId dom } } + var conf domain.StackConfResponse + if err := serializer.Map(ctx, dto.Conf, &conf); err != nil { + log.Error(ctx, err) + return "", httpErrors.NewInternalServerError(errors.Wrap(err, "Invalid node conf"), "", "") + } + workflow := "tks-stack-create" workflowId, err := u.argo.SumbitWorkflowFromWftpl(ctx, workflow, argowf.SubmitOptions{ Parameters: []string{ @@ -132,7 +138,7 @@ func (u *StackUsecase) Create(ctx context.Context, dto model.Stack) (stackId dom "stack_template_id=" + dto.StackTemplateId.String(), "creator=" + user.GetUserId().String(), "base_repo_branch=" + viper.GetString("revision"), - "infra_conf=" + strings.Replace(helper.ModelToJson(dto.Conf), "\"", "\\\"", -1), + "infra_conf=" + strings.Replace(helper.ModelToJson(conf), "\"", "\\\"", -1), "cloud_service=" + dto.CloudService, "cluster_endpoint=" + dto.ClusterEndpoint, "policy_ids=" + strings.Join(dto.PolicyIds, ","), diff --git a/pkg/domain/stack-template.go b/pkg/domain/stack-template.go index e5bce152..b4287d7d 100644 --- a/pkg/domain/stack-template.go +++ b/pkg/domain/stack-template.go @@ -62,17 +62,15 @@ type GetStackTemplateResponse struct { } type CreateStackTemplateRequest struct { - Name string `json:"name" validate:"required,name"` - Description string `json:"description"` - Version string `json:"version" validate:"required"` - - CloudService string `json:"cloudService" validate:"oneof=AWS AZZURE GCP"` - Platform string `json:"platform" validate:"required"` - TemplateType string `json:"templateType" validate:"oneof=STANDARD MSA"` - Template string `json:"template" validate:"required"` - KubeVersion string `json:"kubeVersion" validate:"required"` - KubeType string `json:"kubeType" validate:"required"` - + Name string `json:"name" validate:"required,name"` + Description string `json:"description"` + Version string `json:"version" validate:"required"` + CloudService string `json:"cloudService" validate:"oneof=AWS AZZURE GCP"` + Platform string `json:"platform" validate:"required"` + TemplateType string `json:"templateType" validate:"oneof=STANDARD MSA"` + Template string `json:"template" validate:"required"` + KubeVersion string `json:"kubeVersion" validate:"required"` + KubeType string `json:"kubeType" validate:"required"` OrganizationIds []string `json:"organizationIds" validate:"required"` ServiceIds []string `json:"serviceIds" validate:"required"` } @@ -82,15 +80,16 @@ type CreateStackTemplateResponse struct { } type UpdateStackTemplateRequest struct { - Description string `json:"description"` - Template string `json:"template"` - TemplateType string `json:"templateType"` - CloudService string `json:"cloudService"` - Version string `json:"version"` - Platform string `json:"platform"` - KubeVersion string `json:"kubeVersion"` - KubeType string `json:"kubeType"` - ServiceIds []string `json:"serviceIds" validate:"required"` + Description string `json:"description"` + Version string `json:"version" validate:"required"` + CloudService string `json:"cloudService" validate:"oneof=AWS AZZURE GCP"` + Platform string `json:"platform" validate:"required"` + TemplateType string `json:"templateType" validate:"oneof=STANDARD MSA"` + Template string `json:"template" validate:"required"` + KubeVersion string `json:"kubeVersion" validate:"required"` + KubeType string `json:"kubeType" validate:"required"` + OrganizationIds []string `json:"organizationIds" validate:"required"` + ServiceIds []string `json:"serviceIds" validate:"required"` } type GetStackTemplateServicesResponse struct {