From 3a404f29fa6973d5a3a5dd92a8749a670dada6a7 Mon Sep 17 00:00:00 2001 From: kooomix Date: Wed, 14 Dec 2022 13:42:52 +0200 Subject: [PATCH] control scan by id --- core/cautils/scaninfo.go | 11 +++++++++-- core/pkg/policyhandler/handlepullpolicies.go | 6 +++--- smoke_testing/test_scan.py | 6 +++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/cautils/scaninfo.go b/core/cautils/scaninfo.go index 2c5631e2..067e6469 100644 --- a/core/cautils/scaninfo.go +++ b/core/cautils/scaninfo.go @@ -94,7 +94,8 @@ const ( ) type PolicyIdentifier struct { - Name string // policy name e.g. nsa,mitre,c-0012 + ID string // policy ID e.g. c-0012 - relevant only to kind=control + Name string // policy name e.g. nsa,mitre Kind apisv1.NotificationPolicyKind // policy kind e.g. Framework,Control,Rule Designators armotypes.PortalDesignator } @@ -214,7 +215,13 @@ func (scanInfo *ScanInfo) SetPolicyIdentifiers(policies []string, kind apisv1.No if !scanInfo.contains(policy) { newPolicy := PolicyIdentifier{} newPolicy.Kind = kind - newPolicy.Name = policy + // control can be identified only by it's id. + if kind == apisv1.KindControl { + newPolicy.ID = policy + } else { + newPolicy.Name = policy + } + scanInfo.PolicyIdentifier = append(scanInfo.PolicyIdentifier, newPolicy) } } diff --git a/core/pkg/policyhandler/handlepullpolicies.go b/core/pkg/policyhandler/handlepullpolicies.go index 9915e05f..63b57926 100644 --- a/core/pkg/policyhandler/handlepullpolicies.go +++ b/core/pkg/policyhandler/handlepullpolicies.go @@ -73,15 +73,15 @@ func (policyHandler *PolicyHandler) getScanPolicies(policyIdentifier []cautils.P f := reporthandling.Framework{} var receivedControl *reporthandling.Control var err error - for _, rule := range policyIdentifier { - receivedControl, err = policyHandler.getters.PolicyGetter.GetControl(rule.Name) + for _, policy := range policyIdentifier { + receivedControl, err = policyHandler.getters.PolicyGetter.GetControl(policy.ID) if err != nil { return frameworks, policyDownloadError(err) } if receivedControl != nil { f.Controls = append(f.Controls, *receivedControl) - cache := getter.GetDefaultPath(rule.Name + ".json") + cache := getter.GetDefaultPath(policy.ID + ".json") if err := getter.SaveInFile(receivedControl, cache); err != nil { logger.L().Warning("failed to cache file", helpers.String("file", cache), helpers.Error(err)) } diff --git a/smoke_testing/test_scan.py b/smoke_testing/test_scan.py index f890d8f8..f6b9774c 100644 --- a/smoke_testing/test_scan.py +++ b/smoke_testing/test_scan.py @@ -48,9 +48,9 @@ def run(kubescape_exec: str): # msg = scan_all(kubescape_exec=kubescape_exec) # smoke_utils.assertion(msg) - print("Testing scan control name") - msg = scan_control_name(kubescape_exec=kubescape_exec) - smoke_utils.assertion(msg) + # print("Testing scan control name") + # msg = scan_control_name(kubescape_exec=kubescape_exec) + # smoke_utils.assertion(msg) print("Testing scan control id") msg = scan_control_id(kubescape_exec=kubescape_exec)