Skip to content

Commit

Permalink
fix: following refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
elsapet committed Aug 25, 2023
1 parent f433b5d commit 173e0e4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
32 changes: 20 additions & 12 deletions pkg/report/output/saas/saas.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/bearer/bearer/cmd/bearer/build"
"github.com/bearer/bearer/pkg/commands/process/settings"
saas "github.com/bearer/bearer/pkg/report/output/saas/types"
securitytypes "github.com/bearer/bearer/pkg/report/output/security/types"
"github.com/bearer/bearer/pkg/report/output/types"
"github.com/bearer/bearer/pkg/util/file"
util "github.com/bearer/bearer/pkg/util/output"
Expand All @@ -35,20 +36,17 @@ func GetReport(reportData *types.ReportData, config settings.Config, ensureMeta
}
}

saasFindingsBySeverity := make(map[string][]saas.SaasFinding)
for _, severity := range maps.Keys(reportData.FindingsBySeverity) {
for _, finding := range reportData.FindingsBySeverity[severity] {
saasFindingsBySeverity[severity] = append(saasFindingsBySeverity[severity], saas.SaasFinding{Finding: &finding})
}
}
saasFindingsBySeverity := translateFindingsBySeverity(reportData.FindingsBySeverity)
saasIgnoredFindingsBySeverity := translateFindingsBySeverity(reportData.IgnoredFindingsBySeverity)

reportData.SaasReport = &saas.BearerReport{
Meta: *meta,
Findings: saasFindingsBySeverity,
DataTypes: reportData.Dataflow.Datatypes,
Components: reportData.Dataflow.Components,
Errors: reportData.Dataflow.Errors,
Files: getDiscoveredFiles(config, reportData.Files),
Meta: *meta,
Findings: saasFindingsBySeverity,
IgnoredFindings: saasIgnoredFindingsBySeverity,
DataTypes: reportData.Dataflow.Datatypes,
Components: reportData.Dataflow.Components,
Errors: reportData.Dataflow.Errors,
Files: getDiscoveredFiles(config, reportData.Files),
}

return nil
Expand Down Expand Up @@ -94,6 +92,16 @@ func SendReport(config settings.Config, reportData *types.ReportData) {
}
}

func translateFindingsBySeverity(findingBySeverity map[string][]securitytypes.Finding) map[string][]saas.SaasFinding {
saasFindingsBySeverity := make(map[string][]saas.SaasFinding)
for _, severity := range maps.Keys(findingBySeverity) {
for _, finding := range findingBySeverity[severity] {
saasFindingsBySeverity[severity] = append(saasFindingsBySeverity[severity], saas.SaasFinding{Finding: &finding})
}
}
return saasFindingsBySeverity
}

func sendReportToBearer(client *api.API, meta *saas.Meta, filename *string) error {
fileUploadOffer, err := s3.UploadS3(&s3.UploadRequestS3{
Api: client,
Expand Down
13 changes: 7 additions & 6 deletions pkg/report/output/saas/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ type Meta struct {
}

type BearerReport struct {
Meta Meta `json:"meta" yaml:"meta"`
Findings map[string][]SaasFinding `json:"findings" yaml:"findings"`
DataTypes []dataflowtypes.Datatype `json:"data_types" yaml:"data_types"`
Components []dataflowtypes.Component `json:"components" yaml:"components"`
Errors []dataflowtypes.Error `json:"errors" yaml:"errors"`
Files []string `json:"files" yaml:"files"`
Meta Meta `json:"meta" yaml:"meta"`
Findings map[string][]SaasFinding `json:"findings" yaml:"findings"`
IgnoredFindings map[string][]SaasFinding `json:"ignored_findings" yaml:"ignored_findings"`
DataTypes []dataflowtypes.Datatype `json:"data_types" yaml:"data_types"`
Components []dataflowtypes.Component `json:"components" yaml:"components"`
Errors []dataflowtypes.Error `json:"errors" yaml:"errors"`
Files []string `json:"files" yaml:"files"`
// Dependencies []dataflowtypes.Dependency `json:"dependencies" yaml:"dependencies"`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/report/output/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func AddReportData(
}

reportData.FindingsBySeverity = summaryFindings
reportData.IgnoredFindingsBySeverity = ignoredSummaryFindings
reportData.ReportFailed = reportFailed
return nil
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/report/output/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
)

type ReportData struct {
ReportFailed bool
Files []string
Detectors []any
Dataflow *DataFlow
FindingsBySeverity map[string][]securitytypes.Finding
PrivacyReport *privacytypes.Report
Stats *statstypes.Stats
SaasReport *saastypes.BearerReport
ReportFailed bool
Files []string
Detectors []any
Dataflow *DataFlow
FindingsBySeverity map[string][]securitytypes.Finding
IgnoredFindingsBySeverity map[string][]securitytypes.Finding
PrivacyReport *privacytypes.Report
Stats *statstypes.Stats
SaasReport *saastypes.BearerReport
}

type DataFlow struct {
Expand Down

0 comments on commit 173e0e4

Please sign in to comment.