refactored load policy getter for Frameworks

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This commit is contained in:
Frederic BIDON
2023-01-06 09:32:18 +01:00
parent 2e5ad85fe0
commit 69846bb4c0
+8 -9
View File
@@ -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
}