Skip to content

Commit

Permalink
Merge pull request #89 from underdog-tech/jose/issues-50
Browse files Browse the repository at this point in the history
feat: Add a -r/--reporters configuration flag
  • Loading branch information
tarkatronic authored Oct 26, 2023
2 parents 43cade8 + 9037176 commit d3223ee
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ func Execute() {

func init() {
persistent := rootCmd.PersistentFlags()
persistent.BoolP("disable_slack", "d", false, "Disable Slack alerts.")

persistent.StringP("config", "c", "config.toml", "Config file path.")

persistent.StringSliceP("reporters", "r", []string{"slack", "console"}, "Specify a list of reporters for reporting vulnerabilities.")
persistent.BoolP("quiet", "q", false, "Suppress all console output. (Mutually exclusive with 'verbose'.)")
persistent.CountP("verbose", "v", "More verbose output. Specifying multiple times increases verbosity. (Mutually exclusive with 'quiet'.)")

Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type TeamConfig struct {

type Config struct {
Default_slack_channel string
Disable_slack bool
Github_org string
Slack_auth_token string
Github_token string
Expand All @@ -28,6 +27,7 @@ type Config struct {
Severity []SeverityConfig
Ecosystem []EcosystemConfig
Team []TeamConfig
Reporters []string
}

func fileExists(fname string) bool {
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestGetUserConfigFromFile(t *testing.T) {
}

func TestGetUserConfigFromEnv(t *testing.T) {
t.Setenv("VULNBOT_DISABLE_SLACK", "1")
t.Setenv("VULNBOT_REPORTERS", "slack")
t.Setenv("VULNBOT_GITHUB_ORG", "hitchhikers")
// This should override the config file
t.Setenv("VULNBOT_DEFAULT_SLACK_CHANNEL", "other_slack_channel")
Expand All @@ -91,7 +91,7 @@ func TestGetUserConfigFromEnv(t *testing.T) {
cfg, err := config.GetUserConfig(testDataPath)
assert.Nil(t, err)

assert.True(t, cfg.Disable_slack)
assert.Equal(t, []string{"slack"}, cfg.Reporters)
assert.Equal(t, "hitchhikers", cfg.Github_org)
assert.Equal(t, "other_slack_channel", cfg.Default_slack_channel)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.3
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/oauth2 v0.8.0
golang.org/x/text v0.13.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand Down
8 changes: 6 additions & 2 deletions internal/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/underdog-tech/vulnbot/reporting"

"github.com/spf13/cobra"
"golang.org/x/exp/slices"
)

func Scan(cmd *cobra.Command, args []string) {
Expand All @@ -35,7 +36,7 @@ func Scan(cmd *cobra.Command, args []string) {
// Load and report out to all configured reporters
reporters := []reporting.Reporter{}

if !cfg.Disable_slack {
if slices.Contains(cfg.Reporters, "slack") {
slackReporter, err := reporting.NewSlackReporter(&cfg)
if err != nil {
log.Error().Err(err).Msg("Failed to create Slack reporter.")
Expand All @@ -44,7 +45,10 @@ func Scan(cmd *cobra.Command, args []string) {
}
}

reporters = append(reporters, &reporting.ConsoleReporter{Config: &cfg})
if slices.Contains(cfg.Reporters, "console") {
reporters = append(reporters, &reporting.ConsoleReporter{Config: &cfg})
}

reportTime := time.Now().UTC()
wg := new(sync.WaitGroup)

Expand Down

0 comments on commit d3223ee

Please sign in to comment.