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 ( diff --git a/reporthandling/datastructures.go b/reporthandling/datastructures.go index 0b12c486..f44a060d 100644 --- a/reporthandling/datastructures.go +++ b/reporthandling/datastructures.go @@ -82,6 +82,18 @@ type Control struct { 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,omitempty" bson:"subCategory,omitempty"` +} + +type SubCategory struct { + Name string `json:"name" bson:"name"` + ID string `json:"id" bson:"id"` } type UpdatedControl struct { diff --git a/reporthandling/datastructuresv1.go b/reporthandling/datastructuresv1.go index 31bbd3d3..abca7548 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"` // 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 cca6a3ff..464fd1b8 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,17 @@ func (controlSummary *ControlSummary) GetDescription() string { } +func (controlSummary *ControlSummary) GetCategory() *reporthandling.Category { + return controlSummary.Category +} + +func (controlSummary *ControlSummary) GetSubCategory() *reporthandling.SubCategory { + if controlSummary.GetCategory() == nil { + return nil + } + 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..7543ec49 100644 --- a/reporthandling/results/v1/reportsummary/datastructures.go +++ b/reporthandling/results/v1/reportsummary/datastructures.go @@ -1,6 +1,7 @@ package reportsummary import ( + "github.com/kubescape/opa-utils/reporthandling" "github.com/kubescape/opa-utils/reporthandling/apis" helpersv1 "github.com/kubescape/opa-utils/reporthandling/helpers/v1" ) @@ -14,14 +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"` + 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:"topWorkloadsByScore,omitempty"` } // FrameworkSummary summary of scanning from a single framework perspective @@ -37,18 +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"` + 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 { diff --git a/reporthandling/results/v1/reportsummary/interface.go b/reporthandling/results/v1/reportsummary/interface.go index 22df0959..935e624b 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