Skip to content

Commit

Permalink
treat webhook url as sensitive, default to getting it from envvar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jef Spaleta committed Jan 4, 2019
1 parent d935695 commit 6c65c14
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ func configureRootCommand() *cobra.Command {
RunE: run,
}

/*
Sensitive flags
default to using envvar value
do not mark as required
manually test for empty value
*/
cmd.Flags().StringVarP(&webhookURL,
"webhook-url",
"w",
"",
"The webhook url to send messages to")
os.Getenv("SLACK_WEBHOOK_URL"),
"The webhook url to send messages to, defaults to value of SLACK_WEBHOOK_URL env variable")

cmd.Flags().StringVarP(&channel,
"channel",
Expand Down Expand Up @@ -75,6 +81,11 @@ func run(cmd *cobra.Command, args []string) error {
_ = cmd.Help()
return errors.New("invalid argument(s) received")
}
if webhookURL == "" {
_ = cmd.Help()
return fmt.Errorf("webhook url is empty")

}
if stdin == nil {
stdin = os.Stdin
}
Expand Down

0 comments on commit 6c65c14

Please sign in to comment.