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: Add a -r/--reporters configuration flag #89

Merged
merged 9 commits into from
Oct 26, 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
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 @@
"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 @@
// Load and report out to all configured reporters
reporters := []reporting.Reporter{}

if !cfg.Disable_slack {
if slices.Contains(cfg.Reporters, "slack") {

Check warning on line 39 in internal/scan.go

View check run for this annotation

Codecov / codecov/patch

internal/scan.go#L39

Added line #L39 was not covered by tests
JoseAngel1196 marked this conversation as resolved.
Show resolved Hide resolved
slackReporter, err := reporting.NewSlackReporter(&cfg)
if err != nil {
log.Error().Err(err).Msg("Failed to create Slack reporter.")
Expand All @@ -44,7 +45,10 @@
}
}

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

Check warning on line 50 in internal/scan.go

View check run for this annotation

Codecov / codecov/patch

internal/scan.go#L48-L50

Added lines #L48 - L50 were not covered by tests

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

Expand Down