Skip to content

Commit

Permalink
Merge pull request #351 from sangkenlee/add_api
Browse files Browse the repository at this point in the history
다음 api 추가
  • Loading branch information
ktkfree authored Apr 8, 2024
2 parents c6dac83 + f20bd69 commit d2241f6
Show file tree
Hide file tree
Showing 18 changed files with 815 additions and 41 deletions.
4 changes: 4 additions & 0 deletions internal/delivery/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ const (
Admin_ExistsPolicyTemplateKind
Admin_ExistsPolicyTemplateName
Admin_ExtractParameters
Admin_AddPermittedPolicyTemplatesForOrganization
Admin_DeletePermittedPolicyTemplatesForOrganization

// ClusterPolicyStatus
ListClusterPolicyStatus
Expand All @@ -252,6 +254,8 @@ const (
UpdatePolicyTargetClusters
ExistsPolicyName
GetPolicyEdit
AddPoliciesForStack
DeletePoliciesForStack

// OrganizationPolicyTemplate
ListPolicyTemplate
Expand Down
32 changes: 32 additions & 0 deletions internal/delivery/api/generated_endpoints.go.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,14 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "Admin_ExtractParameters",
Group: "PolicyTemplate",
},
Admin_AddPermittedPolicyTemplatesForOrganization: {
Name: "Admin_AddPermittedPolicyTemplatesForOrganization",
Group: "PolicyTemplate",
},
Admin_DeletePermittedPolicyTemplatesForOrganization: {
Name: "Admin_DeletePermittedPolicyTemplatesForOrganization",
Group: "PolicyTemplate",
},
ListClusterPolicyStatus: {
Name: "ListClusterPolicyStatus",
Group: "ClusterPolicyStatus",
Expand Down Expand Up @@ -783,6 +791,14 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "GetPolicyEdit",
Group: "Policy",
},
AddPoliciesForStack: {
Name: "AddPoliciesForStack",
Group: "Policy",
},
DeletePoliciesForStack: {
Name: "DeletePoliciesForStack",
Group: "Policy",
},
ListPolicyTemplate: {
Name: "ListPolicyTemplate",
Group: "OrganizationPolicyTemplate",
Expand Down Expand Up @@ -1224,6 +1240,10 @@ func (e Endpoint) String() string {
return "Admin_ExistsPolicyTemplateName"
case Admin_ExtractParameters:
return "Admin_ExtractParameters"
case Admin_AddPermittedPolicyTemplatesForOrganization:
return "Admin_AddPermittedPolicyTemplatesForOrganization"
case Admin_DeletePermittedPolicyTemplatesForOrganization:
return "Admin_DeletePermittedPolicyTemplatesForOrganization"
case ListClusterPolicyStatus:
return "ListClusterPolicyStatus"
case GetClusterPolicyTemplateStatus:
Expand Down Expand Up @@ -1252,6 +1272,10 @@ func (e Endpoint) String() string {
return "ExistsPolicyName"
case GetPolicyEdit:
return "GetPolicyEdit"
case AddPoliciesForStack:
return "AddPoliciesForStack"
case DeletePoliciesForStack:
return "DeletePoliciesForStack"
case ListPolicyTemplate:
return "ListPolicyTemplate"
case CreatePolicyTemplate:
Expand Down Expand Up @@ -1658,6 +1682,10 @@ func GetEndpoint(name string) Endpoint {
return Admin_ExistsPolicyTemplateName
case "Admin_ExtractParameters":
return Admin_ExtractParameters
case "Admin_AddPermittedPolicyTemplatesForOrganization":
return Admin_AddPermittedPolicyTemplatesForOrganization
case "Admin_DeletePermittedPolicyTemplatesForOrganization":
return Admin_DeletePermittedPolicyTemplatesForOrganization
case "ListClusterPolicyStatus":
return ListClusterPolicyStatus
case "GetClusterPolicyTemplateStatus":
Expand Down Expand Up @@ -1686,6 +1714,10 @@ func GetEndpoint(name string) Endpoint {
return ExistsPolicyName
case "GetPolicyEdit":
return GetPolicyEdit
case "AddPoliciesForStack":
return AddPoliciesForStack
case "DeletePoliciesForStack":
return DeletePoliciesForStack
case "ListPolicyTemplate":
return ListPolicyTemplate
case "CreatePolicyTemplate":
Expand Down
163 changes: 156 additions & 7 deletions internal/delivery/http/policy-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type IPolicyTemplateHandler interface {
Admin_DeletePolicyTemplateVersion(w http.ResponseWriter, r *http.Request)
Admin_ListPolicyTemplateVersions(w http.ResponseWriter, r *http.Request)
Admin_ExtractParameters(w http.ResponseWriter, r *http.Request)
Admin_AddPermittedPolicyTemplatesForOrganization(w http.ResponseWriter, r *http.Request)
Admin_UpdatePermittedPolicyTemplatesForOrganization(w http.ResponseWriter, r *http.Request)
Admin_DeletePermittedPolicyTemplatesForOrganization(w http.ResponseWriter, r *http.Request)

CreatePolicyTemplate(w http.ResponseWriter, r *http.Request)
UpdatePolicyTemplate(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -747,6 +750,159 @@ func (h *PolicyTemplateHandler) Admin_ExistsPolicyTemplateKind(w http.ResponseWr
ResponseJSON(w, r, http.StatusOK, out)
}

// Admin_AddPermittedPolicyTemplatesForOrganization godoc
//
// @Tags PolicyTemplate
// @Summary [Admin_AddPermittedPolicyTemplatesForOrganization] 특정 조직에 대해 허용된 tks 템플릿 목록 추가
// @Description 특정 조직에 대해 허용된 tks 템플릿 목록을 추가한다.
// @Accept json
// @Produce json
// @Param organizationId path string true "조직 식별자(o로 시작)"
// @Param body body admin_domain.AddPermittedPolicyTemplatesForOrganizationRequest true "update pemitted policy template request"
// @Success 200 {object} nil
// @Router /admin/organizations/{organizationId}/policyTemplates [post]
// @Security JWT
func (h *PolicyTemplateHandler) Admin_AddPermittedPolicyTemplatesForOrganization(w http.ResponseWriter, r *http.Request) {
// TODO: API 형상 추후 반드시 검토

vars := mux.Vars(r)
organizationId, ok := vars["organizationId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("organizationId not found in path"),
"C_INVALID_ORGANIZATION_ID", ""))
return
}

input := admin_domain.AddPermittedPolicyTemplatesForOrganizationRequest{}

err := UnmarshalRequestInput(r, &input)

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

ids := make([]uuid.UUID, len(input.PolicyTemplateIds))

for i, policyTemplateId := range input.PolicyTemplateIds {
id, err := uuid.Parse(policyTemplateId)
if err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "C_INVALID_POLICY_TEMPLATE_ID", ""))
return
}
ids[i] = id
}

err = h.usecase.AddPermittedPolicyTemplatesForOrganization(r.Context(), organizationId, ids)

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

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

func (h *PolicyTemplateHandler) Admin_UpdatePermittedPolicyTemplatesForOrganization(w http.ResponseWriter, r *http.Request) {
// TODO: API 형상 추후 반드시 검토

vars := mux.Vars(r)
organizationId, ok := vars["organizationId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("organizationId not found in path"),
"C_INVALID_ORGANIZATION_ID", ""))
return
}

input := admin_domain.UpdatePermittedPolicyTemplatesForOrganizationRequest{}

err := UnmarshalRequestInput(r, &input)

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

ids := make([]uuid.UUID, len(input.PolicyTemplateIds))

for i, policyTemplateId := range input.PolicyTemplateIds {
id, err := uuid.Parse(policyTemplateId)
if err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "C_INVALID_POLICY_TEMPLATE_ID", ""))
return
}
ids[i] = id
}

err = h.usecase.UpdatePermittedPolicyTemplatesForOrganization(r.Context(), organizationId, ids)

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

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

// Admin_DeletePermittedPolicyTemplatesForOrganization godoc
//
// @Tags PolicyTemplate
// @Summary [Admin_DeletePermittedPolicyTemplatesForOrganization] 특정 조직에 대해 허용된 tks 템플릿 목록 제거
// @Description 특정 조직에 대해 허용된 tks 템플릿의 허용 상태를 해제(제거)한다. tks 우형 템플릿에 대해서만 동작하고 organization 유형 템플릿에 대해서는 거부된다.
// @Accept json
// @Produce json
// @Param organizationId path string true "조직 식별자(o로 시작)"
// @Param body body admin_domain.DeletePermittedPolicyTemplatesForOrganizationRequest true "delete pemitted policy template request"
// @Success 200 {object} nil
// @Router /admin/organizations/{organizationId}/policyTemplates [put]
// @Security JWT
func (h *PolicyTemplateHandler) Admin_DeletePermittedPolicyTemplatesForOrganization(w http.ResponseWriter, r *http.Request) {
// TODO: API 형상 추후 반드시 검토

vars := mux.Vars(r)
organizationId, ok := vars["organizationId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("organizationId not found in path"),
"C_INVALID_ORGANIZATION_ID", ""))
return
}

input := admin_domain.DeletePermittedPolicyTemplatesForOrganizationRequest{}

err := UnmarshalRequestInput(r, &input)

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

ids := make([]uuid.UUID, len(input.PolicyTemplateIds))

for i, policyTemplateId := range input.PolicyTemplateIds {
id, err := uuid.Parse(policyTemplateId)
if err != nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "C_INVALID_POLICY_TEMPLATE_ID", ""))
return
}
ids[i] = id
}

err = h.usecase.DeletePermittedPolicyTemplatesForOrganization(r.Context(), organizationId, ids)

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

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

// CompileRego godoc
//
// @Tags PolicyTemplate
Expand Down Expand Up @@ -1583,12 +1739,5 @@ func (h *PolicyTemplateHandler) ExtractParameters(w http.ResponseWriter, r *http
log.Info(r.Context(), err)
}

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

ErrorJSON(w, r, err)
return
}

ResponseJSON(w, r, http.StatusCreated, response)
}
Loading

0 comments on commit d2241f6

Please sign in to comment.