From b84bab720db2ca008581367945f1eb2b057fc96d Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Thu, 20 Jul 2023 09:47:23 +0300 Subject: [PATCH 01/12] support new fields Signed-off-by: Daniel Grunberger --- reporthandling/datastructures.go | 12 +++++++ .../v1/reportsummary/controlsummarymethods.go | 9 +++++ .../v1/reportsummary/datastructures.go | 33 ++++++++++++------- .../results/v1/reportsummary/interface.go | 7 ++++ 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/reporthandling/datastructures.go b/reporthandling/datastructures.go index 85ac930d..848892ef 100644 --- a/reporthandling/datastructures.go +++ b/reporthandling/datastructures.go @@ -65,6 +65,18 @@ type Control struct { FrameworkNames []string `json:"frameworkNames,omitempty" bson:"frameworkNames,omitempty"` BaseScore float32 `json:"baseScore,omitempty" bson:"baseScore,omitempty"` ARMOImprovementFactor float32 `json:"ARMOImprovementFactor,omitempty" bson:"ARMOImprovementFactor,omitempty"` + Category Category `json:"category,omitempty" bson:"categories,omitempty"` +} + +type Category struct { + Name string `json:"name" bson:"name"` + ID string `json:"id" bson:"id"` + SubCategory SubCategory `json:"subCategory" bson:"subCategory"` +} + +type SubCategory struct { + Name string `json:"name" bson:"name"` + ID string `json:"id" bson:"id"` } type UpdatedControl struct { diff --git a/reporthandling/results/v1/reportsummary/controlsummarymethods.go b/reporthandling/results/v1/reportsummary/controlsummarymethods.go index cca6a3ff..788724dd 100644 --- a/reporthandling/results/v1/reportsummary/controlsummarymethods.go +++ b/reporthandling/results/v1/reportsummary/controlsummarymethods.go @@ -3,6 +3,7 @@ package reportsummary import ( "strings" + "github.com/kubescape/opa-utils/reporthandling" "github.com/kubescape/opa-utils/reporthandling/apis" helpersv1 "github.com/kubescape/opa-utils/reporthandling/helpers/v1" ) @@ -151,6 +152,14 @@ func (controlSummary *ControlSummary) GetDescription() string { } +func (controlSummary *ControlSummary) GetCategory() reporthandling.Category { + return controlSummary.Category +} + +func (controlSummary *ControlSummary) GetSubCategory() reporthandling.SubCategory { + return controlSummary.GetCategory().SubCategory +} + // =============== ControlSummaries func (controlSummaries *ControlSummaries) GetIDs() []string { keys := make([]string, 0, len((*controlSummaries))) diff --git a/reporthandling/results/v1/reportsummary/datastructures.go b/reporthandling/results/v1/reportsummary/datastructures.go index 292d3e3a..e0a2f6d9 100644 --- a/reporthandling/results/v1/reportsummary/datastructures.go +++ b/reporthandling/results/v1/reportsummary/datastructures.go @@ -1,6 +1,8 @@ package reportsummary import ( + "github.com/kubescape/k8s-interface/workloadinterface" + "github.com/kubescape/opa-utils/reporthandling" "github.com/kubescape/opa-utils/reporthandling/apis" helpersv1 "github.com/kubescape/opa-utils/reporthandling/helpers/v1" ) @@ -22,6 +24,12 @@ type SummaryDetails struct { StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility Score float32 `json:"score"` ComplianceScore float32 `json:"complianceScore"` + TopWorkloadsByScore []TopWorkload `json:"topWorkloads,omitempty"` +} + +type TopWorkload struct { + Workload workloadinterface.IMetadata + ResourceSource reporthandling.Source } // FrameworkSummary summary of scanning from a single framework perspective @@ -37,18 +45,19 @@ type FrameworkSummary struct { // ControlSummary summary of scanning from a single control perspective type ControlSummary struct { - StatusInfo apis.StatusInfo `json:"statusInfo,omitempty"` - ControlID string `json:"controlID"` - Name string `json:"name"` - Status apis.ScanningStatus `json:"status"` // backward compatibility - Description string `json:"-"` - Remediation string `json:"-"` - ResourceIDs helpersv1.AllLists `json:"resourceIDs"` - StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility - SubStatusCounters SubStatusCounters `json:"subStatusCounters"` - Score float32 `json:"score"` - ComplianceScore *float32 `json:"complianceScore,omitempty"` - ScoreFactor float32 `json:"scoreFactor"` + StatusInfo apis.StatusInfo `json:"statusInfo,omitempty"` + ControlID string `json:"controlID"` + Name string `json:"name"` + Status apis.ScanningStatus `json:"status"` // backward compatibility + Description string `json:"-"` + Remediation string `json:"-"` + ResourceIDs helpersv1.AllLists `json:"resourceIDs"` + StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility + SubStatusCounters SubStatusCounters `json:"subStatusCounters"` + Score float32 `json:"score"` + ComplianceScore *float32 `json:"complianceScore,omitempty"` + ScoreFactor float32 `json:"scoreFactor"` + Category reporthandling.Category `json:"categories"` } type StatusCounters struct { diff --git a/reporthandling/results/v1/reportsummary/interface.go b/reporthandling/results/v1/reportsummary/interface.go index 22df0959..74ebdee2 100644 --- a/reporthandling/results/v1/reportsummary/interface.go +++ b/reporthandling/results/v1/reportsummary/interface.go @@ -3,6 +3,7 @@ package reportsummary import ( "time" + "github.com/kubescape/opa-utils/reporthandling" "github.com/kubescape/opa-utils/reporthandling/apis" helpersv1 "github.com/kubescape/opa-utils/reporthandling/helpers/v1" ) @@ -41,6 +42,12 @@ type IControlSummary interface { // GetRemediation get control remediation GetRemediation() string + // GetCategory get control category + GetCategory() reporthandling.Category + + // GetSubCategory get control sub category + GetSubCategory() reporthandling.SubCategory + // GetDescription get control description GetDescription() string From 9200b17aa47d59ff394f534b785d3d3b82e7bc22 Mon Sep 17 00:00:00 2001 From: Amir Malka Date: Mon, 10 Jul 2023 15:17:23 +0300 Subject: [PATCH 02/12] added fields selected to RuleMatchObjects Signed-off-by: Amir Malka --- reporthandling/datastructures.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/reporthandling/datastructures.go b/reporthandling/datastructures.go index 85ac930d..a6a012e1 100644 --- a/reporthandling/datastructures.go +++ b/reporthandling/datastructures.go @@ -18,9 +18,10 @@ const ( // RuleMatchObjects defines which objects this rule applied on type RuleMatchObjects struct { - APIGroups []string `json:"apiGroups" bson:"apiGroups"` // apps - APIVersions []string `json:"apiVersions" bson:"apiVersions"` // v1/ v1beta1 / * - Resources []string `json:"resources" bson:"resources"` // dep.., pods, + APIGroups []string `json:"apiGroups" bson:"apiGroups"` // apps + APIVersions []string `json:"apiVersions" bson:"apiVersions"` // v1/ v1beta1 / * + Resources []string `json:"resources" bson:"resources"` // dep.., pods, + FieldSelector []string `json:"fieldSelector" bson:"fieldSelector"` // fields selector for example metadata.name==nginx,metadata.namespace==ns1 } type RuleDependency struct { From 28c28203662cd84cdd877cfae3049c47db3ecd8b Mon Sep 17 00:00:00 2001 From: Amir Malka Date: Thu, 13 Jul 2023 12:17:44 +0300 Subject: [PATCH 03/12] omitempty fieldselector Signed-off-by: Amir Malka --- reporthandling/datastructures.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reporthandling/datastructures.go b/reporthandling/datastructures.go index a6a012e1..8185c582 100644 --- a/reporthandling/datastructures.go +++ b/reporthandling/datastructures.go @@ -18,10 +18,10 @@ const ( // RuleMatchObjects defines which objects this rule applied on type RuleMatchObjects struct { - APIGroups []string `json:"apiGroups" bson:"apiGroups"` // apps - APIVersions []string `json:"apiVersions" bson:"apiVersions"` // v1/ v1beta1 / * - Resources []string `json:"resources" bson:"resources"` // dep.., pods, - FieldSelector []string `json:"fieldSelector" bson:"fieldSelector"` // fields selector for example metadata.name==nginx,metadata.namespace==ns1 + APIGroups []string `json:"apiGroups" bson:"apiGroups"` // apps + APIVersions []string `json:"apiVersions" bson:"apiVersions"` // v1/ v1beta1 / * + Resources []string `json:"resources" bson:"resources"` // dep.., pods, + FieldSelector []string `json:"fieldSelector,omitempty" bson:"fieldSelector,omitempty"` // fields selector for example metadata.name==nginx,metadata.namespace==ns1 } type RuleDependency struct { From 796d89cc623cb5aaa97c035054a03be92ee01f37 Mon Sep 17 00:00:00 2001 From: Amir Malka Date: Thu, 20 Jul 2023 16:12:57 +0300 Subject: [PATCH 04/12] scan workload support in httpserver api Signed-off-by: Amir Malka --- httpserver/apis/v1/apis.go | 12 ++++++++++++ httpserver/meta/v1/datastructure.go | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/httpserver/apis/v1/apis.go b/httpserver/apis/v1/apis.go index 925fc34f..6997f6d1 100644 --- a/httpserver/apis/v1/apis.go +++ b/httpserver/apis/v1/apis.go @@ -31,3 +31,15 @@ const ( // ReadyScanResponseType indicates that a server has successfully completed a request ReadyScanResponseType ScanResponseType = "ready" ) + +// A WorkloadScan contains the identifiers of a workload to be scanned +type WorkloadScan struct { + // The ApiVersion of the workload + ApiVersion string `json:"apiVersion"` + // The kind of the workload + Kind string `json:"kind"` + // The name of the workload + Name string `json:"name"` + // The namespace of the workload + Namespace string `json:"namespace"` +} diff --git a/httpserver/meta/v1/datastructure.go b/httpserver/meta/v1/datastructure.go index 1d6ec06a..f33d9a4d 100644 --- a/httpserver/meta/v1/datastructure.go +++ b/httpserver/meta/v1/datastructure.go @@ -70,9 +70,12 @@ type PostScanRequest struct { // // Example: false UseCachedArtifacts *bool `json:"useCachedArtifacts,omitempty"` - // UseExceptions string // Load file with exceptions configuration - // ControlsInputs string // Load file with inputs for controls - // VerboseMode bool // Display all of the input resources and not only failed resources + // Scan a specific workload + // + // Same as `kubescape scan workload ` + // + // Example: {"apiVersion": "apps/v1", "kind": "Deployment", "name": "nginx", "namespace": "my-namespace"} + Workload *v1.WorkloadScan `json:"workload,omitempty"` } // A Scan Response object From ffc4ddd2c0c83b0311080690a14b44ed65719fdf Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Mon, 31 Jul 2023 08:36:31 +0300 Subject: [PATCH 05/12] undeprecate path --- reporthandling/datastructuresv1.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reporthandling/datastructuresv1.go b/reporthandling/datastructuresv1.go index 31bbd3d3..f7f93e95 100644 --- a/reporthandling/datastructuresv1.go +++ b/reporthandling/datastructuresv1.go @@ -111,8 +111,9 @@ const ( // Source - File source metadata type Source struct { - Path string `json:"path,omitempty"` // deprecated + Path string `json:"path,omitempty"` RelativePath string `json:"relativePath,omitempty"` // relative path from the repo base + HelmPath string `json:"helmPath,omitempty"` // full path to helm chart FileType string `json:"fileType,omitempty"` // file type HelmChartName string `json:"helmChartName,omitempty"` // helm chart name (if FileType is "Helm Chart") KustomizeDirectoryName string `json:"kustomizeDirectoryName,omitempty"` //Kustomize Directory name if File is from Kustomize Directory From 6eda7244282019726f6764c12be91f9c7e794e46 Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Tue, 1 Aug 2023 13:12:50 +0300 Subject: [PATCH 06/12] add negligible --- reporthandling/apis/severity.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/reporthandling/apis/severity.go b/reporthandling/apis/severity.go index e7f430ee..0e244276 100644 --- a/reporthandling/apis/severity.go +++ b/reporthandling/apis/severity.go @@ -1,11 +1,12 @@ package apis const ( - SeverityCriticalString = "Critical" - SeverityHighString = "High" - SeverityMediumString = "Medium" - SeverityLowString = "Low" - SeverityUnknownString = "Unknown" + SeverityCriticalString = "Critical" + SeverityHighString = "High" + SeverityMediumString = "Medium" + SeverityLowString = "Low" + SeverityNegligibleString = "Negligible" + SeverityUnknownString = "Unknown" ) const ( From af0eb6d35ab676f51e574d92292edeff6b9ca6b6 Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Tue, 1 Aug 2023 17:52:04 +0300 Subject: [PATCH 07/12] omit empty --- reporthandling/results/v1/reportsummary/datastructures.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporthandling/results/v1/reportsummary/datastructures.go b/reporthandling/results/v1/reportsummary/datastructures.go index e0a2f6d9..c45d584a 100644 --- a/reporthandling/results/v1/reportsummary/datastructures.go +++ b/reporthandling/results/v1/reportsummary/datastructures.go @@ -57,7 +57,7 @@ type ControlSummary struct { Score float32 `json:"score"` ComplianceScore *float32 `json:"complianceScore,omitempty"` ScoreFactor float32 `json:"scoreFactor"` - Category reporthandling.Category `json:"categories"` + Category reporthandling.Category `json:"categories,omitempty"` } type StatusCounters struct { From 83a6856d97d60ffbd67840450448aed924ad2dec Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Tue, 1 Aug 2023 17:54:37 +0300 Subject: [PATCH 08/12] comment --- reporthandling/results/v1/reportsummary/datastructures.go | 1 + 1 file changed, 1 insertion(+) diff --git a/reporthandling/results/v1/reportsummary/datastructures.go b/reporthandling/results/v1/reportsummary/datastructures.go index c45d584a..0ee49bab 100644 --- a/reporthandling/results/v1/reportsummary/datastructures.go +++ b/reporthandling/results/v1/reportsummary/datastructures.go @@ -27,6 +27,7 @@ type SummaryDetails struct { TopWorkloadsByScore []TopWorkload `json:"topWorkloads,omitempty"` } +// TopWorkload represents one of the top workloads of a scan type TopWorkload struct { Workload workloadinterface.IMetadata ResourceSource reporthandling.Source From d602d8ac1ad1149ea9e67f54026d4034b97c453f Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Tue, 1 Aug 2023 17:55:42 +0300 Subject: [PATCH 09/12] rm unused struct --- httpserver/apis/v1/apis.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/httpserver/apis/v1/apis.go b/httpserver/apis/v1/apis.go index 6997f6d1..925fc34f 100644 --- a/httpserver/apis/v1/apis.go +++ b/httpserver/apis/v1/apis.go @@ -31,15 +31,3 @@ const ( // ReadyScanResponseType indicates that a server has successfully completed a request ReadyScanResponseType ScanResponseType = "ready" ) - -// A WorkloadScan contains the identifiers of a workload to be scanned -type WorkloadScan struct { - // The ApiVersion of the workload - ApiVersion string `json:"apiVersion"` - // The kind of the workload - Kind string `json:"kind"` - // The name of the workload - Name string `json:"name"` - // The namespace of the workload - Namespace string `json:"namespace"` -} From 47efe91e15c7484c8ae3424bcb832d8ab1fefd52 Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Tue, 1 Aug 2023 18:19:45 +0300 Subject: [PATCH 10/12] fixes --- reporthandling/datastructures.go | 28 +++++----- reporthandling/datastructuresv1.go | 2 +- .../v1/reportsummary/controlsummarymethods.go | 7 ++- .../v1/reportsummary/datastructures.go | 51 ++++++++----------- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/reporthandling/datastructures.go b/reporthandling/datastructures.go index 3e2a9daa..a7dfacfa 100644 --- a/reporthandling/datastructures.go +++ b/reporthandling/datastructures.go @@ -72,23 +72,23 @@ type Control struct { FixedInput map[string][]string `json:"fixedInput,omitempty"` RulesIDs *[]string `json:"rulesIDs,omitempty" bson:"rulesIDs,omitempty"` armotypes.PortalBase `json:",inline" bson:"inline"` - Control_ID string `json:"id,omitempty" bson:"id,omitempty" ` - ControlID string `json:"controlID" bson:"controlID"` - CreationTime string `json:"creationTime" bson:"creationTime"` - Description string `json:"description" bson:"description"` - Remediation string `json:"remediation" bson:"remediation"` - Rules []PolicyRule `json:"rules" bson:"rules,omitempty"` - FrameworkNames []string `json:"frameworkNames,omitempty" bson:"frameworkNames,omitempty"` - BaseScore float32 `json:"baseScore,omitempty" bson:"baseScore,omitempty"` - ARMOImprovementFactor float32 `json:"ARMOImprovementFactor,omitempty" bson:"ARMOImprovementFactor,omitempty"` - Category Category `json:"category,omitempty" bson:"categories,omitempty"` - ScanningScope ScanningScope `json:"scanningScope" bson:"scanningScope"` + Control_ID string `json:"id,omitempty" bson:"id,omitempty" ` + ControlID string `json:"controlID" bson:"controlID"` + CreationTime string `json:"creationTime" bson:"creationTime"` + Description string `json:"description" bson:"description"` + Remediation string `json:"remediation" bson:"remediation"` + Rules []PolicyRule `json:"rules" bson:"rules,omitempty"` + FrameworkNames []string `json:"frameworkNames,omitempty" bson:"frameworkNames,omitempty"` + BaseScore float32 `json:"baseScore,omitempty" bson:"baseScore,omitempty"` + ARMOImprovementFactor float32 `json:"ARMOImprovementFactor,omitempty" bson:"ARMOImprovementFactor,omitempty"` + ScanningScope *ScanningScope `json:"scanningScope,omitempty" bson:"scanningScope,omitempty"` + Category *Category `json:"category,omitempty" bson:"category,omitempty"` } type Category struct { - Name string `json:"name" bson:"name"` - ID string `json:"id" bson:"id"` - SubCategory SubCategory `json:"subCategory" bson:"subCategory"` + Name string `json:"name" bson:"name"` + ID string `json:"id" bson:"id"` + SubCategory *SubCategory `json:"subCategory,omitempty" bson:"subCategory,omitempty"` } type SubCategory struct { diff --git a/reporthandling/datastructuresv1.go b/reporthandling/datastructuresv1.go index f7f93e95..abca7548 100644 --- a/reporthandling/datastructuresv1.go +++ b/reporthandling/datastructuresv1.go @@ -113,7 +113,7 @@ const ( type Source struct { Path string `json:"path,omitempty"` RelativePath string `json:"relativePath,omitempty"` // relative path from the repo base - HelmPath string `json:"helmPath,omitempty"` // full path to helm chart + HelmPath string `json:"helmPath,omitempty"` // relative path to helm chart FileType string `json:"fileType,omitempty"` // file type HelmChartName string `json:"helmChartName,omitempty"` // helm chart name (if FileType is "Helm Chart") KustomizeDirectoryName string `json:"kustomizeDirectoryName,omitempty"` //Kustomize Directory name if File is from Kustomize Directory diff --git a/reporthandling/results/v1/reportsummary/controlsummarymethods.go b/reporthandling/results/v1/reportsummary/controlsummarymethods.go index 788724dd..81589992 100644 --- a/reporthandling/results/v1/reportsummary/controlsummarymethods.go +++ b/reporthandling/results/v1/reportsummary/controlsummarymethods.go @@ -153,11 +153,14 @@ func (controlSummary *ControlSummary) GetDescription() string { } func (controlSummary *ControlSummary) GetCategory() reporthandling.Category { - return controlSummary.Category + return *controlSummary.Category } func (controlSummary *ControlSummary) GetSubCategory() reporthandling.SubCategory { - return controlSummary.GetCategory().SubCategory + if controlSummary.Category == nil { + return reporthandling.SubCategory{} + } + return *controlSummary.GetCategory().SubCategory } // =============== ControlSummaries diff --git a/reporthandling/results/v1/reportsummary/datastructures.go b/reporthandling/results/v1/reportsummary/datastructures.go index 0ee49bab..d89c0ad2 100644 --- a/reporthandling/results/v1/reportsummary/datastructures.go +++ b/reporthandling/results/v1/reportsummary/datastructures.go @@ -1,7 +1,6 @@ package reportsummary import ( - "github.com/kubescape/k8s-interface/workloadinterface" "github.com/kubescape/opa-utils/reporthandling" "github.com/kubescape/opa-utils/reporthandling/apis" helpersv1 "github.com/kubescape/opa-utils/reporthandling/helpers/v1" @@ -16,21 +15,15 @@ type ControlSummaries map[string]ControlSummary // SummaryDetails detailed summary of the scanning. will contain versions, counters, etc. type SummaryDetails struct { - Controls ControlSummaries `json:"controls,omitempty"` - Status apis.ScanningStatus `json:"status"` - Frameworks []FrameworkSummary `json:"frameworks"` - ResourcesSeverityCounters SeverityCounters `json:"resourcesSeverityCounters,omitempty"` - ControlsSeverityCounters SeverityCounters `json:"controlsSeverityCounters,omitempty"` - StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility - Score float32 `json:"score"` - ComplianceScore float32 `json:"complianceScore"` - TopWorkloadsByScore []TopWorkload `json:"topWorkloads,omitempty"` -} - -// TopWorkload represents one of the top workloads of a scan -type TopWorkload struct { - Workload workloadinterface.IMetadata - ResourceSource reporthandling.Source + Controls ControlSummaries `json:"controls,omitempty"` + Status apis.ScanningStatus `json:"status"` + Frameworks []FrameworkSummary `json:"frameworks"` + ResourcesSeverityCounters SeverityCounters `json:"resourcesSeverityCounters,omitempty"` + ControlsSeverityCounters SeverityCounters `json:"controlsSeverityCounters,omitempty"` + StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility + Score float32 `json:"score"` + ComplianceScore float32 `json:"complianceScore"` + TopWorkloadsByScore []reporthandling.IResource `json:"topWorkloads,omitempty"` } // FrameworkSummary summary of scanning from a single framework perspective @@ -46,19 +39,19 @@ type FrameworkSummary struct { // ControlSummary summary of scanning from a single control perspective type ControlSummary struct { - StatusInfo apis.StatusInfo `json:"statusInfo,omitempty"` - ControlID string `json:"controlID"` - Name string `json:"name"` - Status apis.ScanningStatus `json:"status"` // backward compatibility - Description string `json:"-"` - Remediation string `json:"-"` - ResourceIDs helpersv1.AllLists `json:"resourceIDs"` - StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility - SubStatusCounters SubStatusCounters `json:"subStatusCounters"` - Score float32 `json:"score"` - ComplianceScore *float32 `json:"complianceScore,omitempty"` - ScoreFactor float32 `json:"scoreFactor"` - Category reporthandling.Category `json:"categories,omitempty"` + StatusInfo apis.StatusInfo `json:"statusInfo,omitempty"` + ControlID string `json:"controlID"` + Name string `json:"name"` + Status apis.ScanningStatus `json:"status"` // backward compatibility + Description string `json:"-"` + Remediation string `json:"-"` + ResourceIDs helpersv1.AllLists `json:"resourceIDs"` + StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility + SubStatusCounters SubStatusCounters `json:"subStatusCounters"` + Score float32 `json:"score"` + ComplianceScore *float32 `json:"complianceScore,omitempty"` + ScoreFactor float32 `json:"scoreFactor"` + Category *reporthandling.Category `json:"category,omitempty"` } type StatusCounters struct { From 064da0e5e23c97d6582d3d38cc6fd8f81acedbc0 Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Tue, 1 Aug 2023 18:20:50 +0300 Subject: [PATCH 11/12] fix json path --- reporthandling/results/v1/reportsummary/datastructures.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporthandling/results/v1/reportsummary/datastructures.go b/reporthandling/results/v1/reportsummary/datastructures.go index d89c0ad2..7543ec49 100644 --- a/reporthandling/results/v1/reportsummary/datastructures.go +++ b/reporthandling/results/v1/reportsummary/datastructures.go @@ -23,7 +23,7 @@ type SummaryDetails struct { StatusCounters StatusCounters `json:"ResourceCounters"` // Backward compatibility Score float32 `json:"score"` ComplianceScore float32 `json:"complianceScore"` - TopWorkloadsByScore []reporthandling.IResource `json:"topWorkloads,omitempty"` + TopWorkloadsByScore []reporthandling.IResource `json:"topWorkloadsByScore,omitempty"` } // FrameworkSummary summary of scanning from a single framework perspective From 3617cbf164d6fb62681dd766fe62af3be43ca8b6 Mon Sep 17 00:00:00 2001 From: Daniel Grunberger Date: Tue, 1 Aug 2023 18:32:03 +0300 Subject: [PATCH 12/12] fix --- .../v1/reportsummary/controlsummarymethods.go | 12 ++++++------ reporthandling/results/v1/reportsummary/interface.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/reporthandling/results/v1/reportsummary/controlsummarymethods.go b/reporthandling/results/v1/reportsummary/controlsummarymethods.go index 81589992..464fd1b8 100644 --- a/reporthandling/results/v1/reportsummary/controlsummarymethods.go +++ b/reporthandling/results/v1/reportsummary/controlsummarymethods.go @@ -152,15 +152,15 @@ func (controlSummary *ControlSummary) GetDescription() string { } -func (controlSummary *ControlSummary) GetCategory() reporthandling.Category { - return *controlSummary.Category +func (controlSummary *ControlSummary) GetCategory() *reporthandling.Category { + return controlSummary.Category } -func (controlSummary *ControlSummary) GetSubCategory() reporthandling.SubCategory { - if controlSummary.Category == nil { - return reporthandling.SubCategory{} +func (controlSummary *ControlSummary) GetSubCategory() *reporthandling.SubCategory { + if controlSummary.GetCategory() == nil { + return nil } - return *controlSummary.GetCategory().SubCategory + return controlSummary.GetCategory().SubCategory } // =============== ControlSummaries diff --git a/reporthandling/results/v1/reportsummary/interface.go b/reporthandling/results/v1/reportsummary/interface.go index 74ebdee2..935e624b 100644 --- a/reporthandling/results/v1/reportsummary/interface.go +++ b/reporthandling/results/v1/reportsummary/interface.go @@ -43,10 +43,10 @@ type IControlSummary interface { GetRemediation() string // GetCategory get control category - GetCategory() reporthandling.Category + GetCategory() *reporthandling.Category // GetSubCategory get control sub category - GetSubCategory() reporthandling.SubCategory + GetSubCategory() *reporthandling.SubCategory // GetDescription get control description GetDescription() string