From 34de52f2f35264bd9004fc46b0d38c9784eac22c Mon Sep 17 00:00:00 2001 From: donggyu Date: Mon, 22 Apr 2024 16:29:32 +0900 Subject: [PATCH] Revert "Merge pull request #410 from sangkenlee/opa-format" This reverts commit 823ad900e9f4c0bef464b4fd86f663c49c376137, reversing changes made to 5c16eeaab2186d91a6afd40d692b20806521b6ce. --- .../policy-template/policy-template-rego.go | 30 ------------------- internal/policy-template/tkspolicytemplate.go | 4 +-- internal/usecase/policy-template.go | 6 ---- 3 files changed, 2 insertions(+), 38 deletions(-) diff --git a/internal/policy-template/policy-template-rego.go b/internal/policy-template/policy-template-rego.go index ab2665fa..8a9e3731 100644 --- a/internal/policy-template/policy-template-rego.go +++ b/internal/policy-template/policy-template-rego.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/open-policy-agent/opa/ast" - "github.com/open-policy-agent/opa/format" "github.com/open-policy-agent/opa/types" "github.com/openinfradev/tks-api/internal/model" "github.com/openinfradev/tks-api/pkg/domain" @@ -559,32 +558,3 @@ func GetPackageFromRegoCode(regoCode string) string { return "" } - -func FormatRegoCode(rego string) string { - packageName := GetPackageFromRegoCode(rego) - - // 패키지 명을 파싱할 수 없으면 포맷팅할 수 있는 코드가 아닐 것이므로 그냥 리턴 - if packageName == "" { - return rego - } - - bytes, err := format.Source("rego", []byte(rego)) - - if err != nil { - return rego - } - - return strings.Replace(string(bytes), "\t", " ", -1) -} - -func FormatLibCode(libs []string) []string { - processedLibs := processLibs(libs) - - result := make([]string, len(processedLibs)) - - for i, lib := range processedLibs { - result[i] = FormatRegoCode(lib) - } - - return result -} diff --git a/internal/policy-template/tkspolicytemplate.go b/internal/policy-template/tkspolicytemplate.go index 9cb8e27f..45c2f2a3 100644 --- a/internal/policy-template/tkspolicytemplate.go +++ b/internal/policy-template/tkspolicytemplate.go @@ -47,8 +47,8 @@ type Validation struct { type Target struct { Target string `json:"target,omitempty"` - Rego string `json:"rego,omitempty" yaml:"rego,omitempty"` - Libs []string `json:"libs,omitempty" yaml:"libs,omitempty"` + Rego string `json:"rego,omitempty" yaml:"rego,omitempty,flow"` + Libs []string `json:"libs,omitempty" yaml:"libs,omitempty,flow"` Code []Code `json:"code,omitempty"` } diff --git a/internal/usecase/policy-template.go b/internal/usecase/policy-template.go index 3d60b872..b235e781 100644 --- a/internal/usecase/policy-template.go +++ b/internal/usecase/policy-template.go @@ -117,9 +117,6 @@ func (u *PolicyTemplateUsecase) Create(ctx context.Context, dto model.PolicyTemp userId := user.GetUserId() dto.CreatorId = &userId - dto.Rego = policytemplate.FormatRegoCode(dto.Rego) - dto.Libs = policytemplate.FormatLibCode(dto.Libs) - id, err := u.repo.Create(ctx, dto) if err != nil { @@ -481,9 +478,6 @@ func (u *PolicyTemplateUsecase) CreatePolicyTemplateVersion(ctx context.Context, return "", httpErrors.NewBadRequestError(err, "PT_INVALID_PARAMETER_SCHEMA", "") } - rego = policytemplate.FormatRegoCode(rego) - libs = policytemplate.FormatLibCode(libs) - return u.repo.CreatePolicyTemplateVersion(ctx, policyTemplateId, newVersion, schema, rego, libs) }