From 27faa78455eb58685123846d54ec3bd97a4d26f8 Mon Sep 17 00:00:00 2001 From: sangkenlee Date: Fri, 19 Apr 2024 00:10:48 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A4=EC=A4=91=20libs=EB=A5=BC=20---\n?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=91=ED=95=A9=ED=95=B4=EC=84=9C=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/policy-template/policy-template-rego.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/policy-template/policy-template-rego.go b/internal/policy-template/policy-template-rego.go index 867f36c3..e5f83937 100644 --- a/internal/policy-template/policy-template-rego.go +++ b/internal/policy-template/policy-template-rego.go @@ -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" ) @@ -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, "") } @@ -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{} @@ -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