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

k8s 정책 동기화 #320

Merged
merged 1 commit into from
Apr 2, 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
1 change: 1 addition & 0 deletions internal/delivery/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const (
UpdatePolicy
UpdatePolicyTargetClusters
ExistsPolicyName
GetPolicyEdit

// OrganizationPolicyTemplate
ListPolicyTemplate
Expand Down
8 changes: 8 additions & 0 deletions internal/delivery/api/generated_endpoints.go.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "ExistsPolicyName",
Group: "Policy",
},
GetPolicyEdit: {
Name: "GetPolicyEdit",
Group: "Policy",
},
ListPolicyTemplate: {
Name: "ListPolicyTemplate",
Group: "OrganizationPolicyTemplate",
Expand Down Expand Up @@ -1194,6 +1198,8 @@ func (e Endpoint) String() string {
return "UpdatePolicyTargetClusters"
case ExistsPolicyName:
return "ExistsPolicyName"
case GetPolicyEdit:
return "GetPolicyEdit"
case ListPolicyTemplate:
return "ListPolicyTemplate"
case CreatePolicyTemplate:
Expand Down Expand Up @@ -1608,6 +1614,8 @@ func GetEndpoint(name string) Endpoint {
return UpdatePolicyTargetClusters
case "ExistsPolicyName":
return ExistsPolicyName
case "GetPolicyEdit":
return GetPolicyEdit
case "ListPolicyTemplate":
return ListPolicyTemplate
case "CreatePolicyTemplate":
Expand Down
185 changes: 131 additions & 54 deletions internal/delivery/http/policy-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,39 @@ func (h *PolicyTemplateHandler) Admin_ListPolicyTemplateVersions(w http.Response
// @Router /admin/policy-templates/{policyTemplateId}/statistics [get]
// @Security JWT
func (h *PolicyTemplateHandler) Admin_ListPolicyTemplateStatistics(w http.ResponseWriter, r *http.Request) {
// result := admin_domain.ListPolicyTemplateStatisticsResponse{
// PolicyTemplateStatistics: []admin_domain.PolicyTemplateStatistics{
// {
// OrganizationId: util.UUIDGen(),
// OrganizationName: "개발팀",
// UsageCount: 10,
// },
// {
// OrganizationId: util.UUIDGen(),
// OrganizationName: "운영팀",
// UsageCount: 5,
// },
// },
// }
// util.JsonResponse(w, result)
vars := mux.Vars(r)
policyTemplateId, ok := vars["policyTemplateId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid policyTemplateId"), "C_INVALID_POLICY_TEMPLATE_ID", ""))
return
}

id, err := uuid.Parse(policyTemplateId)
if err != nil {
log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err)
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "C_INVALID_POLICY_TEMPLATE_ID", ""))
return
}

usageCounts, err := h.usecase.ListPolicyTemplateStatistics(r.Context(), nil, id)

if err != nil {
log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err)

ErrorJSON(w, r, err)
return
}

var out admin_domain.ListPolicyTemplateStatisticsResponse
out.PolicyTemplateStatistics = make([]admin_domain.PolicyTemplateStatistics, len(usageCounts))
for i, usageCount := range usageCounts {
if err := serializer.Map(r.Context(), usageCount, &out.PolicyTemplateStatistics[i]); err != nil {
log.Info(r.Context(), err)
continue
}
}

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

// Admin_GetPolicyTemplateDeploy godoc
Expand All @@ -398,18 +416,31 @@ func (h *PolicyTemplateHandler) Admin_ListPolicyTemplateStatistics(w http.Respon
// @Router /admin/policy-templates/{policyTemplateId}/deploy [get]
// @Security JWT
func (h *PolicyTemplateHandler) Admin_GetPolicyTemplateDeploy(w http.ResponseWriter, r *http.Request) {
// c1 := util.UUIDGen()
// c2 := util.UUIDGen()
// c3 := util.UUIDGen()

// result := admin_domain.GetPolicyTemplateDeployResponse{
// DeployVersion: map[string]string{
// c1: "v1.0.1",
// c2: "v1.1.0",
// c3: "v1.1.0",
// },
// }
// util.JsonResponse(w, result)
vars := mux.Vars(r)

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

id, err := uuid.Parse(policyTemplateId)
if err != nil {
log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err)
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "C_INVALID_POLICY_TEMPLATE_ID", ""))
return
}

out, err := h.usecase.GetPolicyTemplateDeploy(r.Context(), nil, id)

if err != nil {
log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err)

ErrorJSON(w, r, err)
return
}

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

// Admin_GetPolicyTemplateVersion godoc
Expand Down Expand Up @@ -748,6 +779,9 @@ func (h *PolicyTemplateHandler) CreatePolicyTemplate(w http.ResponseWriter, r *h
log.Info(r.Context(), err)
}

// // no converter found for *[]domain.ParameterDef -> []*domain.ParameterDef
// dto.ParametersSchema = input.ParametersSchema

dto.Type = "organization"
dto.OrganizationId = &organizationId

Expand Down Expand Up @@ -1063,21 +1097,45 @@ func (h *PolicyTemplateHandler) ListPolicyTemplateVersions(w http.ResponseWriter
// @Router /organizations/{organizationId}/policy-templates/{policyTemplateId}/statistics [get]
// @Security JWT
func (h *PolicyTemplateHandler) ListPolicyTemplateStatistics(w http.ResponseWriter, r *http.Request) {
// result := domain.ListPolicyTemplateStatisticsResponse{
// PolicyTemplateStatistics: []domain.PolicyTemplateStatistics{
// {
// OrganizationId: util.UUIDGen(),
// OrganizationName: "개발팀",
// UsageCount: 10,
// },
// {
// OrganizationId: util.UUIDGen(),
// OrganizationName: "운영팀",
// UsageCount: 5,
// },
// },
// }
// util.JsonResponse(w, result)
vars := mux.Vars(r)
organizationId, ok := vars["organizationId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid organizationId"),
"C_INVALID_ORGANIZATION_ID", ""))
return
}

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

id, err := uuid.Parse(policyTemplateId)
if err != nil {
log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err)
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "C_INVALID_POLICY_TEMPLATE_ID", ""))
return
}

usageCounts, err := h.usecase.ListPolicyTemplateStatistics(r.Context(), &organizationId, id)

if err != nil {
log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err)

ErrorJSON(w, r, err)
return
}

var out domain.ListPolicyTemplateStatisticsResponse
out.PolicyTemplateStatistics = make([]domain.PolicyTemplateStatistics, len(usageCounts))
for i, usageCount := range usageCounts {
if err := serializer.Map(r.Context(), usageCount, &out.PolicyTemplateStatistics[i]); err != nil {
log.Info(r.Context(), err)
continue
}
}
ResponseJSON(w, r, http.StatusOK, out)
}

// GetPolicyTemplateDeploy godoc
Expand All @@ -1093,18 +1151,37 @@ func (h *PolicyTemplateHandler) ListPolicyTemplateStatistics(w http.ResponseWrit
// @Router /organizations/{organizationId}/policy-templates/{policyTemplateId}/deploy [get]
// @Security JWT
func (h *PolicyTemplateHandler) GetPolicyTemplateDeploy(w http.ResponseWriter, r *http.Request) {
// c1 := util.UUIDGen()
// c2 := util.UUIDGen()
// c3 := util.UUIDGen()

// result := domain.GetPolicyTemplateDeployResponse{
// DeployVersion: map[string]string{
// c1: "v1.0.1",
// c2: "v1.1.0",
// c3: "v1.1.0",
// },
// }
// util.JsonResponse(w, result)
vars := mux.Vars(r)
organizationId, ok := vars["organizationId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid organizationId"),
"C_INVALID_ORGANIZATION_ID", ""))
return
}

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

id, err := uuid.Parse(policyTemplateId)
if err != nil {
log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err)
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "C_INVALID_POLICY_TEMPLATE_ID", ""))
return
}

out, err := h.usecase.GetPolicyTemplateDeploy(r.Context(), &organizationId, id)

if err != nil {
log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err)

ErrorJSON(w, r, err)
return
}

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

// GetPolicyTemplateVersion godoc
Expand Down
Loading
Loading