Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send found languages when using bearer cloud #1318

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/report/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ 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"
"github.com/bearer/bearer/internal/report/output/saas"
"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")
Expand All @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions internal/report/output/saas/saas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
29 changes: 15 additions & 14 deletions internal/report/output/saas/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions internal/report/output/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ReportData struct {
ReportFailed bool
SendToCloud bool
Files []string
FoundLanguages []string
Detectors []any
Dataflow *DataFlow
FindingsBySeverity map[string][]securitytypes.Finding
Expand Down
Loading