Skip to content

Commit

Permalink
fix: show warning when unsupported languages are detected
Browse files Browse the repository at this point in the history
  • Loading branch information
elsapet committed Sep 15, 2023
1 parent bf59e80 commit 486e457
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
48 changes: 48 additions & 0 deletions internal/detectors/dependencies/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,54 @@ func (detector *detector) AcceptDir(dir *file.Path) (bool, error) {
return true, nil
}

func DetectorsForLanguage(language string) []string {
switch language {
case "C#":
return []string{
"nuget",
"packageconfig",
"paketdependencies",
}
case "Go":
return []string{
"gosum",
}
case "Java":
return []string{
"buildgradle",
"ivy",
"mvnplugin",
"pomxml",
}
case "Javascript":
return []string{
"npm",
"packagejson",
"projectjson",
"yarnlock",
}
case "PHP":
return []string{
"composerlock",
"composerjson",
}
case "Python":
return []string{
"pipdeptree",
"piplock",
"poetry",
"pyproject",
"requirements",
}
case "Ruby":
return []string{
"gemfile",
}
}

return []string{}
}

func (detector *detector) ProcessFile(file *file.FileInfo, dir *file.Path, report report.Report) (bool, error) {
switch file.Base {
case "Gemfile.lock":
Expand Down
27 changes: 27 additions & 0 deletions internal/report/output/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/bearer/bearer/internal/classification/db"
"github.com/bearer/bearer/internal/commands/process/settings"
"github.com/bearer/bearer/internal/detectors/dependencies"
"github.com/bearer/bearer/internal/report/basebranchfindings"
globaltypes "github.com/bearer/bearer/internal/types"
"github.com/bearer/bearer/internal/util/file"
Expand All @@ -27,6 +28,7 @@ import (
"github.com/bearer/bearer/internal/util/rego"
"github.com/bearer/bearer/internal/util/set"

dataflowtypes "github.com/bearer/bearer/internal/report/output/dataflow/types"
types "github.com/bearer/bearer/internal/report/output/security/types"
stats "github.com/bearer/bearer/internal/report/output/stats"
outputtypes "github.com/bearer/bearer/internal/report/output/types"
Expand Down Expand Up @@ -382,6 +384,7 @@ func BuildReportString(reportData *outputtypes.ReportData, config settings.Confi
reportStr,
config.Rules,
config.BuiltInRules,
reportData.Dataflow.Dependencies,
lineOfCodeOutput.Languages,
config,
)
Expand Down Expand Up @@ -510,6 +513,7 @@ func writeRuleListToString(
reportStr *strings.Builder,
rules map[string]*settings.Rule,
builtInRules map[string]*settings.Rule,
reportedDependencies []dataflowtypes.Dependency,
languages map[string]*gocloc.Language,
config settings.Config,
) int {
Expand Down Expand Up @@ -544,13 +548,36 @@ func writeRuleListToString(
sort.Slice(languageSlice, func(i, j int) bool {
return len(languageSlice[i].Files) > len(languageSlice[j].Files)
})
unsupportedLanguages := make(map[string]int)
for _, lang := range languageSlice {
if ruleCount, ok := ruleCountPerLang[lang.Name]; ok {
tbl.AddRow(lang.Name, ruleCount.DefaultRuleCount, ruleCount.CustomRuleCount, len(languages[lang.Name].Files))
} else {
for _, detector := range dependencies.DetectorsForLanguage(lang.Name) {
if _, ok := unsupportedLanguages[lang.Name]; ok {
break
}
for _, reportedDependency := range reportedDependencies {
if reportedDependency.Detector == detector {
unsupportedLanguages[lang.Name] = len(languages[lang.Name].Files)
break
}
}
}
}
}

for language, filesCount := range unsupportedLanguages {
tbl.AddRow(language, 0, 0, filesCount)
}

tbl.Print()

if len(unsupportedLanguages) > 0 {
reportStr.WriteString(
fmt.Sprintf("\nWarning: Only partial support is offered for %s. For more information, see https://docs.bearer.com/reference/supported-languages/\n\n", strings.Join(maps.Keys(unsupportedLanguages), ", ")))
}

return totalRuleCount
}

Expand Down

0 comments on commit 486e457

Please sign in to comment.