Skip to content

Commit

Permalink
Use flagx.File for authtoken-file flag (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-soltesz authored Jun 25, 2020
1 parent 700e59c commit 4cc7884
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 9 deletions.
10 changes: 5 additions & 5 deletions cmd/github_receiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

var (
authtoken = flag.String("authtoken", "", "Oauth2 token for access to github API.")
authtokenFile = flagx.FileBytes{}
authtokenFile = flagx.File{}
githubOrg = flag.String("org", "", "The github user or organization name where all repos are found.")
githubRepo = flag.String("repo", "", "The default repository for creating issues when alerts do not include a repo label.")
githubBaseURL = flag.String("enterprise.base-url", "", "The URL of your GitHub Enterprise with API suffix (for example '/api/v3/').")
Expand Down Expand Up @@ -87,7 +87,7 @@ EXAMPLE

func init() {
flag.Var(&extraLabels, "label", "Extra labels to add to issues at creation time.")
flag.Var(&authtokenFile, "authtokenFile", "Oauth2 token file for access to github API. When provided it takes precedence over authtoken.")
flag.Var(&authtokenFile, "authtoken-file", "Oauth2 token file for access to github API. When provided it takes precedence over authtoken.")
flag.Var(&titleTmplFile, "title-template-file", "File containing a template to generate issue titles.")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), usage)
Expand All @@ -110,15 +110,15 @@ func mustServeWebhookReceiver(receiver *alerts.ReceiverHandler) *http.Server {
func main() {
flag.Parse()
rtx.Must(flagx.ArgsFromEnv(flag.CommandLine), "Failed to read ArgsFromEnv")
if (*authtoken == "" && len(authtokenFile) == 0) || *githubOrg == "" || *githubRepo == "" {
if (*authtoken == "" && len(authtokenFile.Bytes) == 0) || *githubOrg == "" || *githubRepo == "" {
flag.Usage()
osExit(1)
return
}

var token string
if len(authtokenFile) != 0 {
token = string(authtokenFile)
if len(authtokenFile.Bytes) != 0 {
token = authtokenFile.Content()
} else {
token = *authtoken
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/github_receiver/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Test_main(t *testing.T) {
}
}
*authtoken = tt.authtoken
authtokenFile = []byte(tt.authfile)
authtokenFile.Bytes = []byte(tt.authfile)
*githubOrg = "fake-org"
*githubRepo = tt.repo
*githubBaseURL = tt.baseURL
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.14
require (
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/m-lab/go v0.1.40
github.com/m-lab/go v0.1.42
github.com/prometheus/alertmanager v0.20.0
github.com/prometheus/client_golang v1.5.0
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
github.com/prometheus/client_golang v1.7.1
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
)
Loading

0 comments on commit 4cc7884

Please sign in to comment.