Skip to content

Commit

Permalink
Revert "Merge pull request openinfradev#410 from sangkenlee/opa-format"
Browse files Browse the repository at this point in the history
This reverts commit 823ad90, reversing
changes made to 5c16eea.
  • Loading branch information
cho4036 committed Apr 22, 2024
1 parent 823ad90 commit 34de52f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
30 changes: 0 additions & 30 deletions internal/policy-template/policy-template-rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions internal/policy-template/tkspolicytemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
6 changes: 0 additions & 6 deletions internal/usecase/policy-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 34de52f

Please sign in to comment.