Skip to content

Commit

Permalink
Merge pull request #131 from kubescape/new-cli-output
Browse files Browse the repository at this point in the history
New cli output
  • Loading branch information
Daniel-GrunbergerCA authored Aug 1, 2023
2 parents d480b6b + 3617cbf commit ea3c970
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
11 changes: 6 additions & 5 deletions reporthandling/apis/severity.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
12 changes: 12 additions & 0 deletions reporthandling/datastructures.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion reporthandling/datastructuresv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions reporthandling/results/v1/reportsummary/controlsummarymethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)))
Expand Down
43 changes: 23 additions & 20 deletions reporthandling/results/v1/reportsummary/datastructures.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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
Expand All @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions reporthandling/results/v1/reportsummary/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ea3c970

Please sign in to comment.