Skip to content

Commit

Permalink
manage backward compatibility in Gitregostore (#439)
Browse files Browse the repository at this point in the history
Corrects the backward compatibility regarding security frameworks, and deprecates backward compatibility regarding controlIDs that were changed.
  • Loading branch information
YiscahLevySilas1 authored Jun 22, 2023
1 parent 251b8c1 commit 281c02f
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 515 deletions.
193 changes: 0 additions & 193 deletions gitregostore/backwardCompatibility.go

This file was deleted.

73 changes: 0 additions & 73 deletions gitregostore/backwardCompatibility_test.go

This file was deleted.

22 changes: 6 additions & 16 deletions gitregostore/gitstoremethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
)

const (
supportBackwardCompatibility = true
TypeCompliance = "compliance"
TypeSecurity = "security"
TypeCompliance = "compliance"
TypeSecurity = "security"
)

// =============================================================
Expand Down Expand Up @@ -95,9 +94,7 @@ func (gs *GitRegoStore) GetOPAControlByName(controlName string) (*opapolicy.Cont
defer gs.controlsLock.RUnlock()

for _, controlToPin := range gs.Controls {
// If backward compatibility is supported, extract from patched control name the new name.
if !strings.EqualFold(controlToPin.Name, controlName) &&
(!supportBackwardCompatibility || !strings.EqualFold(controlToPin.Name, baseControlName(controlToPin.ControlID, controlName))) {
if !strings.EqualFold(controlToPin.Name, controlName) {
continue
}

Expand Down Expand Up @@ -125,9 +122,7 @@ func (gs *GitRegoStore) GetOPAControlByID(controlID string) (*opapolicy.Control,

func (gs *GitRegoStore) getOPAControlByID(controlID string) (*opapolicy.Control, error) {
for _, controlToPin := range gs.Controls {
// If backward compatibility is supported, try to find if the controlID sent has a new controlID
if !strings.EqualFold(controlToPin.ControlID, controlID) &&
(!supportBackwardCompatibility || !strings.EqualFold(controlToPin.ControlID, newControlID(controlID))) {
if !strings.EqualFold(controlToPin.ControlID, controlID) {
continue
}

Expand Down Expand Up @@ -157,9 +152,7 @@ func (gs *GitRegoStore) GetOPAControlByFrameworkNameAndControlName(frameworkName
}

for _, controlToPin := range fw.Controls {
// If backward compatibility is supported, extract from patched control name the new name.
if !strings.EqualFold(controlToPin.Name, controlName) &&
(!supportBackwardCompatibility || !strings.EqualFold(controlToPin.Name, baseControlName(controlToPin.ControlID, controlName))) {
if !strings.EqualFold(controlToPin.Name, controlName) {
continue
}

Expand Down Expand Up @@ -379,11 +372,9 @@ func (gs *GitRegoStore) GetOPAFrameworkByName(frameworkName string) (*opapolicy.
}

func (gs *GitRegoStore) getOPAFrameworkByName(frameworkName string) (*opapolicy.Framework, error) {
const supportBackwardCompatibilityFramework = true

for _, frameworkToPin := range gs.Frameworks {
// If backward compatibility is supported,try to compare the new CIS name.
if !strings.EqualFold(frameworkToPin.Name, frameworkName) && (!supportBackwardCompatibilityFramework || !strings.EqualFold(frameworkToPin.Name, newFrameworkName(frameworkName))) {
if !strings.EqualFold(frameworkToPin.Name, frameworkName) {
continue
}

Expand Down Expand Up @@ -496,7 +487,6 @@ func (gs *GitRegoStore) fillControlsAndControlIDsInFramework(fw *opapolicy.Frame
// if there are controls, need to populate only the rules.
for i := range fw.Controls {
if len(fw.Controls[i].Rules) == 0 {
// getting the control object using GetOPAControlByID as it handles backward compatibility
tmpControl, err := gs.GetOPAControlByID(fw.Controls[i].ControlID)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 281c02f

Please sign in to comment.