mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 09:59:54 +00:00
control scan by id
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user