Skip to content

Commit

Permalink
add validation on request
Browse files Browse the repository at this point in the history
  • Loading branch information
sangkenlee committed Mar 11, 2024
1 parent d84d983 commit 03333a2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
17 changes: 13 additions & 4 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7924,6 +7924,10 @@ const docTemplate = `{
},
"github_com_openinfradev_tks-api_pkg_domain.CreatePolicyTemplateRequest": {
"type": "object",
"required": [
"kind",
"rego"
],
"properties": {
"deprecated": {
"type": "boolean",
Expand Down Expand Up @@ -7971,10 +7975,6 @@ const docTemplate = `{
],
"example": "medium"
},
"target": {
"type": "string",
"example": "admission.k8s.gatekeeper.sh"
},
"templateName": {
"type": "string",
"example": "필수 Label 검사"
Expand All @@ -7983,6 +7983,12 @@ const docTemplate = `{
},
"github_com_openinfradev_tks-api_pkg_domain.CreatePolicyTemplateVersionRequest": {
"type": "object",
"required": [
"currentVersion",
"expectedVersion",
"rego",
"versionUpType"
],
"properties": {
"currentVersion": {
"type": "string",
Expand Down Expand Up @@ -9905,6 +9911,9 @@ const docTemplate = `{
},
"github_com_openinfradev_tks-api_pkg_domain.RegoCompileRequest": {
"type": "object",
"required": [
"rego"
],
"properties": {
"rego": {
"type": "string",
Expand Down
17 changes: 13 additions & 4 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7918,6 +7918,10 @@
},
"github_com_openinfradev_tks-api_pkg_domain.CreatePolicyTemplateRequest": {
"type": "object",
"required": [
"kind",
"rego"
],
"properties": {
"deprecated": {
"type": "boolean",
Expand Down Expand Up @@ -7965,10 +7969,6 @@
],
"example": "medium"
},
"target": {
"type": "string",
"example": "admission.k8s.gatekeeper.sh"
},
"templateName": {
"type": "string",
"example": "필수 Label 검사"
Expand All @@ -7977,6 +7977,12 @@
},
"github_com_openinfradev_tks-api_pkg_domain.CreatePolicyTemplateVersionRequest": {
"type": "object",
"required": [
"currentVersion",
"expectedVersion",
"rego",
"versionUpType"
],
"properties": {
"currentVersion": {
"type": "string",
Expand Down Expand Up @@ -9899,6 +9905,9 @@
},
"github_com_openinfradev_tks-api_pkg_domain.RegoCompileRequest": {
"type": "object",
"required": [
"rego"
],
"properties": {
"rego": {
"type": "string",
Expand Down
13 changes: 10 additions & 3 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,12 @@ definitions:
- high
example: medium
type: string
target:
example: admission.k8s.gatekeeper.sh
type: string
templateName:
example: 필수 Label 검사
type: string
required:
- kind
- rego
type: object
github_com_openinfradev_tks-api_pkg_domain.CreatePolicyTemplateVersionRequest:
properties:
Expand Down Expand Up @@ -968,6 +968,11 @@ definitions:
- patch
example: minor
type: string
required:
- currentVersion
- expectedVersion
- rego
- versionUpType
type: object
github_com_openinfradev_tks-api_pkg_domain.CreatePolicyTemplateVersionResponse:
properties:
Expand Down Expand Up @@ -2223,6 +2228,8 @@ definitions:
rego:
example: Rego 코드
type: string
required:
- rego
type: object
github_com_openinfradev_tks-api_pkg_domain.RegoCompileResponse:
properties:
Expand Down
23 changes: 11 additions & 12 deletions pkg/domain/policy-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,30 @@ type PolicyTemplate struct {
}

type CreateCommonPolicyTemplateRequest struct {
TemplateName string `json:"templateName" example:"필수 Label 검사"`
Kind string `json:"kind" example:"K8sRequiredLabels"`
TemplateName string `json:"templateName" example:"필수 Label 검사" validate:"name"`
Kind string `json:"kind" example:"K8sRequiredLabels" validate:"required"`
Severity string `json:"severity" enums:"low,medium,high" example:"medium"`
Deprecated bool `json:"deprecated" example:"false"`
Description string `json:"description,omitempty" example:"이 정책은 ..."`
ParametersSchema []ParameterDef `json:"parametersSchema,omitempty"`
// "type: object\nproperties: message:\n type: string\n labels:\n type: array\n items:\n type: object\n properties:\n key:\n type: string\n allowedRegex:\n type: string"

Rego string `json:"rego" example:"rego 코드"`
Rego string `json:"rego" example:"rego 코드" validate:"required"`
Libs []string `json:"libs" example:"rego 코드"`

// Tags []string `json:"tags,omitempty" example:"k8s,label"`
}

type CreatePolicyTemplateRequest struct {
TemplateName string `json:"templateName" example:"필수 Label 검사"`
Kind string `json:"kind" example:"K8sRequiredLabels"`
TemplateName string `json:"templateName" example:"필수 Label 검사" validate:"name"`
Kind string `json:"kind" example:"K8sRequiredLabels" validate:"required"`
Severity string `json:"severity" enums:"low,medium,high" example:"medium"`
Deprecated bool `json:"deprecated" example:"false"`
Target string `json:"target,omitempty" example:"admission.k8s.gatekeeper.sh"`
Description string `json:"description,omitempty" example:"이 정책은 ..."`
ParametersSchema []ParameterDef `json:"parametersSchema,omitempty"`
// "type: object\nproperties: message:\n type: string\n labels:\n type: array\n items:\n type: object\n properties:\n key:\n type: string\n allowedRegex:\n type: string"

Rego string `json:"rego" example:"rego 코드"`
Rego string `json:"rego" example:"rego 코드" validate:"required"`
Libs []string `json:"libs" example:"rego 코드"`

PermittedOrganizationIds []string `json:"permittedOrganizationIds"`
Expand Down Expand Up @@ -210,14 +209,14 @@ type GetOrganizationPolicyTemplateVersionResponse struct {
}

type CreatePolicyTemplateVersionRequest struct {
VersionUpType string `json:"versionUpType" enums:"major,minor,patch" example:"minor"`
CurrentVersion string `json:"currentVersion" example:"v1.0.0"`
ExpectedVersion string `json:"expectedVersion" example:"v1.1.0"`
VersionUpType string `json:"versionUpType" enums:"major,minor,patch" example:"minor" validate:"required"`
CurrentVersion string `json:"currentVersion" example:"v1.0.0" validate:"required"`
ExpectedVersion string `json:"expectedVersion" example:"v1.1.0" validate:"required"`

ParametersSchema []ParameterDef `json:"parametersSchema,omitempty"`
// "type: object\nproperties: message:\n type: string\n labels:\n type: array\n items:\n type: object\n properties:\n key:\n type: string\n allowedRegex:\n type: string"

Rego string `json:"rego" example:"rego 코드"`
Rego string `json:"rego" example:"rego 코드" validate:"required"`
Libs []string `json:"libs" example:"rego 코드"`
}

Expand Down Expand Up @@ -286,7 +285,7 @@ type ParameterDef struct {
}

type RegoCompileRequest struct {
Rego string `json:"rego" example:"Rego 코드"`
Rego string `json:"rego" example:"Rego 코드" validate:"required"`
}

type RegoCompieError struct {
Expand Down

0 comments on commit 03333a2

Please sign in to comment.