mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
refactored load policy getter for Frameworks
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This commit is contained in:
@@ -71,8 +71,11 @@ func (lp *LoadPolicy) GetControl(controlID string) (*reporthandling.Control, err
|
||||
return control, nil
|
||||
}
|
||||
|
||||
// GetFramework retrieves a framework configuration from the policy.
|
||||
func (lp *LoadPolicy) GetFramework(frameworkName string) (*reporthandling.Framework, error) {
|
||||
var framework *reporthandling.Framework
|
||||
if frameworkName == "" {
|
||||
return &reporthandling.Framework{}, nil
|
||||
}
|
||||
|
||||
for _, filePath := range lp.filePaths {
|
||||
f, err := os.ReadFile(filePath)
|
||||
@@ -86,17 +89,11 @@ func (lp *LoadPolicy) GetFramework(frameworkName string) (*reporthandling.Framew
|
||||
}
|
||||
|
||||
if strings.EqualFold(frameworkName, fw.Name) {
|
||||
framework = &fw
|
||||
|
||||
break
|
||||
return &fw, nil
|
||||
}
|
||||
}
|
||||
|
||||
if frameworkName != "" && !strings.EqualFold(frameworkName, framework.Name) {
|
||||
return nil, fmt.Errorf("framework from file not matching")
|
||||
}
|
||||
|
||||
return framework, nil
|
||||
return nil, fmt.Errorf("framework from file not matching")
|
||||
}
|
||||
|
||||
func (lp *LoadPolicy) GetFrameworks() ([]reporthandling.Framework, error) {
|
||||
@@ -108,6 +105,7 @@ func (lp *LoadPolicy) GetFrameworks() ([]reporthandling.Framework, error) {
|
||||
func (lp *LoadPolicy) ListFrameworks() ([]string, error) {
|
||||
fwNames := []string{}
|
||||
framework := &reporthandling.Framework{}
|
||||
|
||||
for _, f := range lp.filePaths {
|
||||
file, err := os.ReadFile(f)
|
||||
if err == nil {
|
||||
@@ -118,6 +116,7 @@ func (lp *LoadPolicy) ListFrameworks() ([]string, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fwNames, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user