Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

정책 템플릿 버전업 관련 기능 수정 #355

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/delivery/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ const (
Admin_AddPermittedPolicyTemplatesForOrganization
Admin_DeletePermittedPolicyTemplatesForOrganization

// ClusterPolicyStatus
ListClusterPolicyStatus
GetClusterPolicyTemplateStatus
UpdateClusterPolicyTemplateStatus
// StackPolicyStatus
ListStackPolicyStatus
GetStackPolicyTemplateStatus
UpdateStackPolicyTemplateStatus

// Policy
GetMandatoryPolicies
Expand Down
42 changes: 21 additions & 21 deletions internal/delivery/api/generated_endpoints.go.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,17 +735,17 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "Admin_DeletePermittedPolicyTemplatesForOrganization",
Group: "PolicyTemplate",
},
ListClusterPolicyStatus: {
Name: "ListClusterPolicyStatus",
Group: "ClusterPolicyStatus",
ListStackPolicyStatus: {
Name: "ListStackPolicyStatus",
Group: "StackPolicyStatus",
},
GetClusterPolicyTemplateStatus: {
Name: "GetClusterPolicyTemplateStatus",
Group: "ClusterPolicyStatus",
GetStackPolicyTemplateStatus: {
Name: "GetStackPolicyTemplateStatus",
Group: "StackPolicyStatus",
},
UpdateClusterPolicyTemplateStatus: {
Name: "UpdateClusterPolicyTemplateStatus",
Group: "ClusterPolicyStatus",
UpdateStackPolicyTemplateStatus: {
Name: "UpdateStackPolicyTemplateStatus",
Group: "StackPolicyStatus",
},
GetMandatoryPolicies: {
Name: "GetMandatoryPolicies",
Expand Down Expand Up @@ -1244,12 +1244,12 @@ func (e Endpoint) String() string {
return "Admin_AddPermittedPolicyTemplatesForOrganization"
case Admin_DeletePermittedPolicyTemplatesForOrganization:
return "Admin_DeletePermittedPolicyTemplatesForOrganization"
case ListClusterPolicyStatus:
return "ListClusterPolicyStatus"
case GetClusterPolicyTemplateStatus:
return "GetClusterPolicyTemplateStatus"
case UpdateClusterPolicyTemplateStatus:
return "UpdateClusterPolicyTemplateStatus"
case ListStackPolicyStatus:
return "ListStackPolicyStatus"
case GetStackPolicyTemplateStatus:
return "GetStackPolicyTemplateStatus"
case UpdateStackPolicyTemplateStatus:
return "UpdateStackPolicyTemplateStatus"
case GetMandatoryPolicies:
return "GetMandatoryPolicies"
case SetMandatoryPolicies:
Expand Down Expand Up @@ -1686,12 +1686,12 @@ func GetEndpoint(name string) Endpoint {
return Admin_AddPermittedPolicyTemplatesForOrganization
case "Admin_DeletePermittedPolicyTemplatesForOrganization":
return Admin_DeletePermittedPolicyTemplatesForOrganization
case "ListClusterPolicyStatus":
return ListClusterPolicyStatus
case "GetClusterPolicyTemplateStatus":
return GetClusterPolicyTemplateStatus
case "UpdateClusterPolicyTemplateStatus":
return UpdateClusterPolicyTemplateStatus
case "ListStackPolicyStatus":
return ListStackPolicyStatus
case "GetStackPolicyTemplateStatus":
return GetStackPolicyTemplateStatus
case "UpdateStackPolicyTemplateStatus":
return UpdateStackPolicyTemplateStatus
case "GetMandatoryPolicies":
return GetMandatoryPolicies
case "SetMandatoryPolicies":
Expand Down
89 changes: 46 additions & 43 deletions internal/delivery/http/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ type IPolicyHandler interface {
GetMandatoryPolicies(w http.ResponseWriter, r *http.Request)
SetMandatoryPolicies(w http.ResponseWriter, r *http.Request)
ExistsPolicyName(w http.ResponseWriter, r *http.Request)
ListClusterPolicyStatus(w http.ResponseWriter, r *http.Request)
GetClusterPolicyTemplateStatus(w http.ResponseWriter, r *http.Request)
UpdateClusterPolicyTemplateStatus(w http.ResponseWriter, r *http.Request)
ListStackPolicyStatus(w http.ResponseWriter, r *http.Request)
GetStackPolicyTemplateStatus(w http.ResponseWriter, r *http.Request)
UpdateStackPolicyTemplateStatus(w http.ResponseWriter, r *http.Request)
GetPolicyEdit(w http.ResponseWriter, r *http.Request)
GetPolicyStatistics(w http.ResponseWriter, r *http.Request)
AddPoliciesForStack(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -601,69 +601,71 @@ func (h *PolicyHandler) ExistsPolicyName(w http.ResponseWriter, r *http.Request)
ResponseJSON(w, r, http.StatusOK, out)
}

// ListClusterPolicyStatus godoc
// ListStackPolicyStatus godoc
//
// @Tags ClusterPolicyStatus
// @Summary [ListClusterPolicyStatus] 클러스터의 정책과 정책 템플릿, 버전 조회
// @Tags StackPolicyStatus
// @Summary [ListStackPolicyStatus] 클러스터의 정책과 정책 템플릿, 버전 조회
// @Description 클러스터의 정책과 정책 템플릿, 버전 등을 포함한 상태 목록을 조회한다.
// @Accept json
// @Produce json
// @Param clusterId path string true "클러스터 식별자(uuid)"
// @Param pageSize query string false "pageSize"
// @Param pageNumber query string false "pageNumber"
// @Param sortColumn query string false "sortColumn"
// @Param sortOrder query string false "sortOrder"
// @Param filters query []string false "filters"
// @Success 200 {object} domain.ListClusterPolicyStatusResponse
// @Router /clusters/{clusterId}/policy-status [get]
// @Param organizationId path string true "조직 식별자(o로 시작)"
// @Param stackId path string true "스택 식별자"
// @Param pageSize query string false "pageSize"
// @Param pageNumber query string false "pageNumber"
// @Param sortColumn query string false "sortColumn"
// @Param sortOrder query string false "sortOrder"
// @Param filters query []string false "filters"
// @Success 200 {object} domain.ListStackPolicyStatusResponse
// @Router /organizations/{organizationId}/stacks/{stackId}/policy-status [get]
// @Security JWT
func (h *PolicyHandler) ListClusterPolicyStatus(w http.ResponseWriter, r *http.Request) {
func (h *PolicyHandler) ListStackPolicyStatus(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

clusterId, ok := vars["clusterId"]
stackId, ok := vars["stackId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid clusterId"),
"C_INVALID_CLUSTER_ID", ""))
"C_INVALID_STACK_ID", ""))
return
}

urlParams := r.URL.Query()

pg := pagination.NewPagination(&urlParams)

policyStatuses, err := h.usecase.ListClusterPolicyStatus(r.Context(), clusterId, pg)
policyStatuses, err := h.usecase.ListStackPolicyStatus(r.Context(), stackId, pg)

if err != nil {
ErrorJSON(w, r, err)
return
}

out := domain.ListClusterPolicyStatusResponse{
out := domain.ListStackPolicyStatusResponse{
Polices: policyStatuses,
}

ResponseJSON(w, r, http.StatusOK, out)
}

// GetClusterPolicyTemplateStatus godoc
// GetStackPolicyTemplateStatus godoc
//
// @Tags ClusterPolicyStatus
// @Summary [GetClusterPolicyTemplateStatus] 클러스터 템플릿 상태 상세 조회
// @Tags StackPolicyStatus
// @Summary [GetStackPolicyTemplateStatus] 클러스터 템플릿 상태 상세 조회
// @Description 템플릿의 클러스터 버전 등 상태를 조회한다.
// @Accept json
// @Produce json
// @Param clusterId path string true "클러스터 식별자(uuid)"
// @Param templateId path string true "정책 템플릿 식별자(uuid)"
// @Success 200 {object} domain.GetClusterPolicyTemplateStatusResponse
// @Router /clusters/{clusterId}/policy-templates/{policyTemplateId} [get]
// @Param organizationId path string true "조직 식별자(o로 시작)"
// @Param stackId path string true "스택 식별자"
// @Param policyTemplateId path string true "정책 템플릿 식별자(uuid)"
// @Success 200 {object} domain.GetStackPolicyTemplateStatusResponse
// @Router /organizations/{organizationId}/stacks/{stackId}/policy-templates/{policyTemplateId} [get]
// @Security JWT
func (h *PolicyHandler) GetClusterPolicyTemplateStatus(w http.ResponseWriter, r *http.Request) {
func (h *PolicyHandler) GetStackPolicyTemplateStatus(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

clusterId, ok := vars["clusterId"]
stackId, ok := vars["stackId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid clusterId"),
"C_INVALID_CLUSTER_ID", ""))
"C_INVALID_STACK_ID", ""))
return
}

Expand All @@ -680,7 +682,7 @@ func (h *PolicyHandler) GetClusterPolicyTemplateStatus(w http.ResponseWriter, r
return
}

out, err := h.usecase.GetClusterPolicyTemplateStatus(r.Context(), clusterId, id)
out, err := h.usecase.GetStackPolicyTemplateStatus(r.Context(), stackId, id)

if err != nil {
ErrorJSON(w, r, err)
Expand All @@ -690,26 +692,27 @@ func (h *PolicyHandler) GetClusterPolicyTemplateStatus(w http.ResponseWriter, r
ResponseJSON(w, r, http.StatusOK, out)
}

// UpdateClusterPolicyTemplateStatus godoc
// UpdateStackPolicyTemplateStatus godoc
//
// @Tags ClusterPolicyStatus
// @Summary [UpdateClusterPolicyTemplateStatus] 템플릿 버전 업데이트
// @Tags StackPolicyStatus
// @Summary [UpdateStackPolicyTemplateStatus] 템플릿 버전 업데이트
// @Description 해당 템플릿의 버전 업데이트 및 연관된 정책의 새 기본값을 설정한다.
// @Accept json
// @Produce json
// @Param clusterId path string true "클러스터 식별자(uuid)"
// @Param templateId path string true "정책 템플릿 식별자(uuid)"
// @Param body body domain.UpdateClusterPolicyTemplateStatusRequest true "update cluster policy template status request"
// @Success 200 {object} nil
// @Router /clusters/{clusterId}/policy-templates/{policyTemplateId} [patch]
// @Param organizationId path string true "조직 식별자(o로 시작)"
// @Param stackId path string true "스택 식별자"
// @Param policyTemplateId path string true "정책 템플릿 식별자(uuid)"
// @Param body body domain.UpdateStackPolicyTemplateStatusRequest true "update stack policy template status request"
// @Success 200 {object} nil
// @Router /organizations/{organizationId}/stacks/{stackId}/policy-templates/{policyTemplateId} [patch]
// @Security JWT
func (h *PolicyHandler) UpdateClusterPolicyTemplateStatus(w http.ResponseWriter, r *http.Request) {
func (h *PolicyHandler) UpdateStackPolicyTemplateStatus(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

clusterId, ok := vars["clusterId"]
stackId, ok := vars["stackId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid clusterId"),
"C_INVALID_CLUSTER_ID", ""))
"C_INVALID_STACK_ID", ""))
return
}

Expand All @@ -719,7 +722,7 @@ func (h *PolicyHandler) UpdateClusterPolicyTemplateStatus(w http.ResponseWriter,
return
}

input := domain.UpdateClusterPolicyTemplateStatusRequest{}
input := domain.UpdateStackPolicyTemplateStatusRequest{}

err := UnmarshalRequestInput(r, &input)

Expand All @@ -735,7 +738,7 @@ func (h *PolicyHandler) UpdateClusterPolicyTemplateStatus(w http.ResponseWriter,
return
}

err = h.usecase.UpdateClusterPolicyTemplateStatus(r.Context(), clusterId, id,
err = h.usecase.UpdateStackPolicyTemplateStatus(r.Context(), stackId, id,
input.TemplateCurrentVersion, input.TemplateTargetVerson)

if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/model/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ func newPolicy() *Permission {
api.Admin_ExistsPolicyTemplateName,
api.Admin_ExistsPolicyTemplateKind,

// ClusterPolicyStatus
api.ListClusterPolicyStatus,
api.GetClusterPolicyTemplateStatus,
// StackPolicyStatus
api.ListStackPolicyStatus,
api.GetStackPolicyTemplateStatus,

// Policy
api.GetMandatoryPolicies,
Expand Down Expand Up @@ -339,7 +339,7 @@ func newPolicy() *Permission {
api.Admin_UpdatePolicyTemplate,

// ClusterPolicyStatus
api.UpdateClusterPolicyTemplateStatus,
api.UpdateStackPolicyTemplateStatus,

// Policy
api.UpdatePolicy,
Expand Down
4 changes: 1 addition & 3 deletions internal/policy-template/paramdef-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func GetNewParamDefs(paramdefs1 []*domain.ParameterDef, paramdefs2 []*domain.Par
if paramdef1 == nil {
// Not found, it's new parameter
result = append(result, paramdef2)
}

if !CompareParamDef(paramdef2, paramdef1) {
} else if !CompareParamDef(paramdef2, paramdef1) {
return nil, fmt.Errorf("not compatible, parameter definition of '%s' is changed", paramdef2.Key)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (r *PolicyRepository) FetchByClusterIdAndTemplaeId(ctx context.Context, clu
Where("cluster_id = ?", clusterId)

res := r.db.WithContext(ctx).Preload(clause.Associations).
Where("template_id = ?").Where("id in (?)", subQueryClusterId).Find(&out)
Where("template_id = ?", templateId).Where("id in (?)", subQueryClusterId).Find(&out)

if res.Error != nil {
return nil, res.Error
Expand Down
6 changes: 3 additions & 3 deletions internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/policies", customMiddleware.Handle(internalApi.AddPoliciesForStack, http.HandlerFunc(policyHandler.AddPoliciesForStack))).Methods(http.MethodPost)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/policies", customMiddleware.Handle(internalApi.DeletePoliciesForStack, http.HandlerFunc(policyHandler.DeletePoliciesForStack))).Methods(http.MethodPut)

r.Handle(API_PREFIX+API_VERSION+"/clusters/{clusterId}/policy-status", customMiddleware.Handle(internalApi.ListClusterPolicyStatus, http.HandlerFunc(policyHandler.ListClusterPolicyStatus))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/clusters/{clusterId}/policy-templates/{policyTemplateId}", customMiddleware.Handle(internalApi.GetClusterPolicyTemplateStatus, http.HandlerFunc(policyHandler.GetClusterPolicyTemplateStatus))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/clusters/{clusterId}/policy-templates/{policyTemplateId}", customMiddleware.Handle(internalApi.UpdateClusterPolicyTemplateStatus, http.HandlerFunc(policyHandler.UpdateClusterPolicyTemplateStatus))).Methods(http.MethodPatch)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/policy-status", customMiddleware.Handle(internalApi.ListStackPolicyStatus, http.HandlerFunc(policyHandler.ListStackPolicyStatus))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/policy-templates/{policyTemplateId}", customMiddleware.Handle(internalApi.GetStackPolicyTemplateStatus, http.HandlerFunc(policyHandler.GetStackPolicyTemplateStatus))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/stacks/{stackId}/policy-templates/{policyTemplateId}", customMiddleware.Handle(internalApi.UpdateStackPolicyTemplateStatus, http.HandlerFunc(policyHandler.UpdateStackPolicyTemplateStatus))).Methods(http.MethodPatch)

// assets
r.PathPrefix("/api/").HandlerFunc(http.NotFound)
Expand Down
Loading
Loading