Skip to content

Commit

Permalink
change nodeType in report params to string array
Browse files Browse the repository at this point in the history
  • Loading branch information
gnmahanth committed Nov 11, 2024
1 parent 2086e9c commit 7b1f11d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deepfence_utils/utils/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type ReportOptions struct {
type ReportFilters struct {
ScanID string `json:"scan_id"`
ScanType string `json:"scan_type" validate:"required" required:"true" enum:"vulnerability,secret,malware,compliance,cloud_compliance"`
NodeType string `json:"node_type" validate:"required" required:"true" enum:"host,container,container_image,linux,cluster,aws,gcp,azure"`
NodeType []string `json:"node_type" validate:"required" required:"true" enum:"host,container,container_image,linux,cluster,aws,gcp,azure"`
SeverityOrCheckType []string `json:"severity_or_check_type" enum:"critical,high,medium,low,cis,gdpr,nist,hipaa,pci,soc_2,aws_foundational_security"`
IncludeDeadNode bool `json:"include_dead_nodes"`
MostExploitableReport bool `json:"most_exploitable_report"`
Expand Down
2 changes: 1 addition & 1 deletion deepfence_worker/tasks/reports/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func searchScansFilter(params sdkUtils.ReportParams) rptSearch.SearchScanReq {
Filters: reporters.FieldsFilters{
ContainsFilter: reporters.ContainsFilter{
FieldsValues: map[string][]interface{}{
"node_type": {params.Filters.NodeType},
"node_type": sdkUtils.StringArrayToInterfaceArray(params.Filters.NodeType),
},
},
},
Expand Down
6 changes: 4 additions & 2 deletions deepfence_worker/tasks/reports/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/deepfence/ThreatMapper/deepfence_utils/log"
Expand Down Expand Up @@ -74,7 +75,8 @@ func getMarato() core.Maroto {
return m
}

func getFiltersPage(title, scanType, nodeType, timeRange, severity, advFilters string) core.Page {
func getFiltersPage(title string, scanType string, nodeType []string,
timeRange string, severity string, advFilters string) core.Page {

cellStyle := &props.Cell{
BackgroundColor: &props.Color{Red: 255, Green: 255, Blue: 255},
Expand Down Expand Up @@ -104,7 +106,7 @@ func getFiltersPage(title, scanType, nodeType, timeRange, severity, advFilters s
),
row.New(6).Add(
text.NewCol(6, "Node Type", filtersTextProps).WithStyle(cellStyle),
text.NewCol(6, nodeType, filtersTextProps).WithStyle(cellStyle),
text.NewCol(6, strings.Join(nodeType, ","), filtersTextProps).WithStyle(cellStyle),
),
row.New(6).Add(
text.NewCol(6, "Time Range", filtersTextProps).WithStyle(cellStyle),
Expand Down
12 changes: 6 additions & 6 deletions deepfence_worker/tasks/reports/pdf_compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func createCompSingleReport(data *Info[model.Compliance], params sdkUtils.Report

// summary table
var summaryPage core.Page
if data.AppliedFilters.NodeType != "cluster" {
if data.AppliedFilters.NodeType[0] != "cluster" {
summaryPage = getComplianceSummaryPage(data.NodeWiseData.SeverityCount)
} else {
summaryPage = getCloudComplianceSummaryPage(data.NodeWiseData.SeverityCount)
Expand Down Expand Up @@ -202,7 +202,7 @@ func createCompZippedReport(data *Info[model.Compliance], params sdkUtils.Report
i: data.NodeWiseData.SeverityCount[i],
}
var summaryPage core.Page
if data.AppliedFilters.NodeType != "cluster" {
if data.AppliedFilters.NodeType[0] != "cluster" {
summaryPage = getComplianceSummaryPage(singleSummary)
} else {
summaryPage = getCloudComplianceSummaryPage(singleSummary)
Expand Down Expand Up @@ -249,9 +249,9 @@ func createCompZippedReport(data *Info[model.Compliance], params sdkUtils.Report
return outputZip, nil
}

func addCompResultHeaders(p core.Page, nodeName string, nodeType string) {
func addCompResultHeaders(p core.Page, nodeName string, nodeType []string) {
p.Add(text.NewRow(10, fmt.Sprintf("%s - Scan Details", nodeName), compResultHeaderProps))
if nodeType != "cluster" {
if nodeType[0] != "cluster" {
p.Add(row.New(10).Add(
text.NewCol(1, "No.", compResultHeaderProps).WithStyle(compResultCellStyle),
text.NewCol(1, "Status", compResultHeaderProps).WithStyle(compResultCellStyle),
Expand All @@ -273,10 +273,10 @@ func addCompResultHeaders(p core.Page, nodeName string, nodeType string) {
}
}

func getCompResultRows(d ScanData[model.Compliance], nodeType string) []core.Row {
func getCompResultRows(d ScanData[model.Compliance], nodeType []string) []core.Row {
resultRows := []core.Row{}
for k, v := range d.ScanResults {
if nodeType != "cluster" {
if nodeType[0] != "cluster" {
resultRows = append(
resultRows,
row.New(15).Add(
Expand Down
4 changes: 3 additions & 1 deletion deepfence_worker/tasks/reports/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func reportFileName(params sdkUtils.ReportParams) string {
return fmt.Sprintf("sbom_%s%s", params.ReportID, fileExt(sdkUtils.ReportSBOM))
}

list := []string{params.Filters.ScanType, params.Filters.NodeType, params.ReportID}
list := []string{params.Filters.ScanType}
list = append(list, params.Filters.NodeType...)
list = append(list, params.ReportID)

if params.ZippedReport {
return strings.Join(list, "_") + ".zip"
Expand Down

0 comments on commit 7b1f11d

Please sign in to comment.