From a60dcd25cb8df17abbaa3b99ca677b6d10a77b8b Mon Sep 17 00:00:00 2001 From: Yordan Kinkov <yordan.kinkov@vereign.com> Date: Tue, 19 Jul 2022 13:27:00 +0300 Subject: [PATCH] #32 add proper filename during sync --- cmd/sync/main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/sync/main.go b/cmd/sync/main.go index 87eb6f4b..7f2c2fb0 100644 --- a/cmd/sync/main.go +++ b/cmd/sync/main.go @@ -161,10 +161,9 @@ func createPolicy(p string, d os.DirEntry) (*Policy, error) { return nil, fmt.Errorf("failed to get policy filename, name, version and group out of policy path: %s", p) } - filename := ss[len(ss)-1] // last element in the array is filename - version := ss[len(ss)-2] // second last element is the version - name := ss[len(ss)-3] // third last element is the policy name - group := ss[len(ss)-4] // fourth last element is the policy group + version := ss[len(ss)-2] // second last element is the version + name := ss[len(ss)-3] // third last element is the policy name + group := ss[len(ss)-4] // fourth last element is the policy group bytes, err := os.ReadFile(p) if err != nil { return nil, err @@ -178,8 +177,11 @@ func createPolicy(p string, d os.DirEntry) (*Policy, error) { } data := string(dataBytes) + // generate filename for DB from pattern {group}/{name}/{version}/policy.rego + dbFilename := group + "/" + name + "/" + version + "/" + policyFilename + return &Policy{ - Filename: filename, + Filename: dbFilename, Name: name, Group: group, Version: version, -- GitLab