From fe2a98aca436fa4f26ef27de2b9d6c1ce05b2356 Mon Sep 17 00:00:00 2001 From: Philip Hayton Date: Wed, 11 Oct 2023 11:37:16 +0100 Subject: [PATCH] feat: send found languages when using bearer cloud (#1318) feat: send found languages to cloud --- internal/report/output/output.go | 14 +++++++++-- internal/report/output/saas/saas.go | 8 +++--- internal/report/output/saas/types/types.go | 29 +++++++++++----------- internal/report/output/types/types.go | 1 + 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/internal/report/output/output.go b/internal/report/output/output.go index 050631b08..6e9716ef5 100644 --- a/internal/report/output/output.go +++ b/internal/report/output/output.go @@ -3,16 +3,16 @@ package output import ( "errors" "fmt" + "sort" "time" "github.com/google/uuid" "github.com/hhatto/gocloc" + "golang.org/x/exp/maps" "github.com/bearer/bearer/internal/commands/process/settings" "github.com/bearer/bearer/internal/flag" "github.com/bearer/bearer/internal/report/basebranchfindings" - globaltypes "github.com/bearer/bearer/internal/types" - "github.com/bearer/bearer/internal/report/output/dataflow" "github.com/bearer/bearer/internal/report/output/detectors" "github.com/bearer/bearer/internal/report/output/privacy" @@ -20,6 +20,7 @@ import ( "github.com/bearer/bearer/internal/report/output/security" "github.com/bearer/bearer/internal/report/output/stats" "github.com/bearer/bearer/internal/report/output/types" + globaltypes "github.com/bearer/bearer/internal/types" ) var ErrUndefinedFormat = errors.New("undefined output format") @@ -30,6 +31,15 @@ func GetData( baseBranchFindings *basebranchfindings.Findings, ) (*types.ReportData, error) { data := &types.ReportData{} + + // add languages + languages := []string{} + if report.Inputgocloc != nil && report.Inputgocloc.Languages != nil { + languages = maps.Keys(report.Inputgocloc.Languages) + } + sort.Strings(languages) + data.FoundLanguages = languages + // add detectors err := detectors.AddReportData(data, report, config) if config.Report.Report == flag.ReportDetectors || err != nil { diff --git a/internal/report/output/saas/saas.go b/internal/report/output/saas/saas.go index 3489c9ddf..29cabd0b5 100644 --- a/internal/report/output/saas/saas.go +++ b/internal/report/output/saas/saas.go @@ -25,13 +25,14 @@ import ( func GetReport(reportData *types.ReportData, config settings.Config, ensureMeta bool) error { var meta *saas.Meta - meta, err := getMeta(config) + meta, err := getMeta(reportData, config) if err != nil { if ensureMeta { return err } else { meta = &saas.Meta{ - Target: config.Scan.Target, + Target: config.Scan.Target, + FoundLanguages: reportData.FoundLanguages, } } } @@ -166,7 +167,7 @@ func createBearerGzipFileReport( return &tempDir, &filename, nil } -func getMeta(config settings.Config) (*saas.Meta, error) { +func getMeta(reportData *types.ReportData, config settings.Config) (*saas.Meta, error) { sha, err := getSha(config.Scan.Target) if err != nil { return nil, err @@ -201,6 +202,7 @@ func getMeta(config settings.Config) (*saas.Meta, error) { DiffBaseBranch: config.Scan.DiffBaseBranch, BearerRulesVersion: config.BearerRulesVersion, BearerVersion: build.Version, + FoundLanguages: reportData.FoundLanguages, }, nil } diff --git a/internal/report/output/saas/types/types.go b/internal/report/output/saas/types/types.go index ffb725ae8..8a11e5c9e 100644 --- a/internal/report/output/saas/types/types.go +++ b/internal/report/output/saas/types/types.go @@ -7,20 +7,21 @@ import ( ) type Meta struct { - ID string `json:"id" yaml:"id"` - Host string `json:"host" yaml:"host"` - Username string `json:"username" yaml:"username"` - Name string `json:"name" yaml:"name"` - URL string `json:"url" yaml:"url"` - FullName string `json:"full_name" yaml:"full_name"` - Target string `json:"target" yaml:"target"` - SHA string `json:"sha" yaml:"sha"` - CurrentBranch string `json:"current_branch" yaml:"current_branch"` - DefaultBranch string `json:"default_branch" yaml:"default_branch"` - DiffBaseBranch string `json:"diff_base_branch,omitempty" yaml:"diff_base_branch,omitempty"` - SignedID string `json:"signed_id,omitempty" yaml:"signed_id,omitempty"` - BearerRulesVersion string `json:"bearer_rules_version,omitempty" yaml:"bearer_rules_version,omitempty"` - BearerVersion string `json:"bearer_version,omitempty" yaml:"bearer_version,omitempty"` + ID string `json:"id" yaml:"id"` + Host string `json:"host" yaml:"host"` + Username string `json:"username" yaml:"username"` + Name string `json:"name" yaml:"name"` + URL string `json:"url" yaml:"url"` + FullName string `json:"full_name" yaml:"full_name"` + Target string `json:"target" yaml:"target"` + SHA string `json:"sha" yaml:"sha"` + CurrentBranch string `json:"current_branch" yaml:"current_branch"` + DefaultBranch string `json:"default_branch" yaml:"default_branch"` + DiffBaseBranch string `json:"diff_base_branch,omitempty" yaml:"diff_base_branch,omitempty"` + SignedID string `json:"signed_id,omitempty" yaml:"signed_id,omitempty"` + BearerRulesVersion string `json:"bearer_rules_version,omitempty" yaml:"bearer_rules_version,omitempty"` + BearerVersion string `json:"bearer_version,omitempty" yaml:"bearer_version,omitempty"` + FoundLanguages []string `json:"found_languages" yaml:"found_languages"` } type BearerReport struct { diff --git a/internal/report/output/types/types.go b/internal/report/output/types/types.go index f07aa829f..67c84763c 100644 --- a/internal/report/output/types/types.go +++ b/internal/report/output/types/types.go @@ -12,6 +12,7 @@ type ReportData struct { ReportFailed bool SendToCloud bool Files []string + FoundLanguages []string Detectors []any Dataflow *DataFlow FindingsBySeverity map[string][]securitytypes.Finding