Skip to content

Commit

Permalink
canceled infinite append of opa obj from repo
Browse files Browse the repository at this point in the history
  • Loading branch information
YiscahLevySilas1 committed Nov 7, 2021
1 parent 6cec1b5 commit c4e0136
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
44 changes: 24 additions & 20 deletions gitregostore/gitstoremethods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,30 @@ func TestInitGitRegoStoreFromRelease(t *testing.T) {
// fmt.Println(gs.URL)
}

func TestInitGitRegoStoreFromRepo(t *testing.T) {
// baseUrl := "https://api.github.com/repos"
// owner := "armosec"
// repository := "regolibrary"
// path := "git/trees"
// tag := ""
// branch := "dev"
// frequency := 15
// gs := InitGitRegoStore(baseUrl, owner, repository, path, tag, branch, frequency)
// if gs.Controls == nil {
// t.Errorf("failed to decode controls")
// }
// if gs.Frameworks == nil {
// t.Errorf("failed to decode frameworks")
// }
// if gs.Rules == nil {
// t.Errorf("failed to decode rules")
// }
// fmt.Println(gs.URL)
}
// func TestInitGitRegoStoreFromRepo(t *testing.T) {
// baseUrl := "https://api.github.com/repos"
// owner := "armosec"
// repository := "regolibrary"
// path := "git/trees"
// tag := ""
// branch := "dev"
// frequency := 1
// gs := InitGitRegoStore(baseUrl, owner, repository, path, tag, branch, frequency)
// if gs.Controls == nil {
// t.Errorf("failed to decode controls")
// }
// if gs.Frameworks == nil {
// t.Errorf("failed to decode frameworks")
// }
// if gs.Rules == nil {
// t.Errorf("failed to decode rules")
// }
// fmt.Println(gs.URL)
// time.Sleep(time.Duration(frequency) * time.Minute)
// if len(gs.Frameworks) > 4 {
// t.Errorf("failed to decode controls")
// }
// }

func TestGetPoliciesMethods(t *testing.T) {
gs := InitDefaultGitRegoStore(-1)
Expand Down
18 changes: 9 additions & 9 deletions gitregostore/gitstoreutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ func (gs *GitRegoStore) setObjectsFromRepoOnce() error {
if err != nil {
return fmt.Errorf("failed to unmarshal response body from '%s', reason: %s", gs.URL, err.Error())
}
gs.frameworksLock.Lock()
gs.controlsLock.Lock()
gs.rulesLock.Lock()
defer gs.frameworksLock.Unlock()
defer gs.controlsLock.Unlock()
defer gs.rulesLock.Unlock()
gs.Frameworks = []opapolicy.Framework{}
gs.Controls = []opapolicy.Control{}
gs.Rules = []opapolicy.PolicyRule{}

// use only json files from relevant dirs
for _, path := range trees.TREE {
Expand Down Expand Up @@ -157,8 +166,6 @@ func (gs *GitRegoStore) setFramework(respStr string) error {
if err := JSONDecoder(respStr).Decode(framework); err != nil {
return err
}
gs.frameworksLock.Lock()
defer gs.frameworksLock.Unlock()
gs.Frameworks = append(gs.Frameworks, *framework)
return nil
}
Expand All @@ -168,10 +175,7 @@ func (gs *GitRegoStore) setControl(respStr string) error {
if err := JSONDecoder(respStr).Decode(control); err != nil {
return err
}
gs.controlsLock.Lock()
defer gs.controlsLock.Unlock()
gs.Controls = append(gs.Controls, *control)

return nil
}

Expand All @@ -186,11 +190,7 @@ func (gs *GitRegoStore) setRulesWithRawRego(respStr string, path string) error {
return err
}
rule.Rule = respString

gs.rulesLock.Lock()
defer gs.rulesLock.Unlock()
gs.Rules = append(gs.Rules, *rule)

return nil
}

Expand Down

0 comments on commit c4e0136

Please sign in to comment.