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

다중 libs를 ---\n로 병합해서 처리 가능하도록 개선 #400

Merged
merged 1 commit into from
Apr 19, 2024
Merged
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
15 changes: 13 additions & 2 deletions internal/policy-template/policy-template-rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/open-policy-agent/opa/ast"
"github.com/openinfradev/tks-api/internal/model"
"github.com/openinfradev/tks-api/pkg/domain"
"golang.org/x/exp/maps"
)
Expand Down Expand Up @@ -281,7 +282,7 @@ func MergeRegoAndLibs(rego string, libs []string) string {

result := re.ReplaceAllString(rego, "")

for _, lib := range libs {
for _, lib := range processLibs(libs) {
result += re2.ReplaceAllString(lib, "")
}

Expand Down Expand Up @@ -367,6 +368,16 @@ func createKey(key string, isLast bool) *domain.ParameterDef {
return newDef
}

func processLibs(libs []string) []string {
// libs 에 --- 로 코딩되어 여러 개가 한 번에 들어온 경우 분할
newLibs := []string{}
for _, lib := range libs {
newLibs = append(newLibs, strings.Split(stripCarriageReturn(lib), model.FILE_DELIMETER)...)
}

return newLibs
}

func CompileRegoWithLibs(rego string, libs []string) (compiler *ast.Compiler, err error) {
modules := map[string]*ast.Module{}

Expand All @@ -379,7 +390,7 @@ func CompileRegoWithLibs(rego string, libs []string) (compiler *ast.Compiler, er

modules[regoPackage] = regoModule

for i, lib := range libs {
for i, lib := range processLibs(libs) {
// Lib이 공백이면 무시
if len(strings.TrimSpace(lib)) == 0 {
continue
Expand Down
Loading