diff --git a/cmd/root.go b/cmd/root.go index f3e31ce..2d5e42c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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'.)") diff --git a/config/config.go b/config/config.go index 0e3a622..1c55b5e 100644 --- a/config/config.go +++ b/config/config.go @@ -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 @@ -28,6 +27,7 @@ type Config struct { Severity []SeverityConfig Ecosystem []EcosystemConfig Team []TeamConfig + Reporters []string } func fileExists(fname string) bool { diff --git a/config/config_test.go b/config/config_test.go index 5a86a12..774a57d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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") @@ -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) } diff --git a/go.mod b/go.mod index 6d8ee07..c26a665 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index e2bea29..9e332a7 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/scan.go b/internal/scan.go index 4bd981b..ed7390a 100644 --- a/internal/scan.go +++ b/internal/scan.go @@ -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) { @@ -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.") @@ -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)