From ddec9c0e356c54e4a745fd4b398f7cd2f9eeb3ea Mon Sep 17 00:00:00 2001 From: Tom Prince Date: Tue, 24 Mar 2020 18:46:07 -0600 Subject: [PATCH] Add skeleton support for listening to pulse. --- go.mod | 2 ++ main.go | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/go.mod b/go.mod index 990f77f..f2d1061 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,9 @@ go 1.14 require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71 github.com/stretchr/testify v1.1.4-0.20160524234229-8d64eb7173c7 + github.com/taskcluster/pulse-go v1.0.0 github.com/urfave/cli v1.17.1-0.20160608151511-fa949b48f384 go.mozilla.org/mozlog v0.0.0-20160610165107-cd74695caf44 ) diff --git a/main.go b/main.go index f639bcd..75ef248 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,8 @@ import ( "go.mozilla.org/mozlog" "github.com/urfave/cli" + + "github.com/taskcluster/pulse-go/pulse" ) func init() { @@ -47,6 +49,22 @@ func main() { Usage: "Password for authing against jenkins", EnvVar: "JENKINS_PASSWORD", }, + cli.StringFlag{ + Name: "pulse-username", + Usage: "Username for authing against pulse", + EnvVar: "PULSE_USERNAME", + }, + cli.StringFlag{ + Name: "pulse-password", + Usage: "Password for authing against pulse", + EnvVar: "PULSE_PASSWORD", + }, + cli.StringFlag{ + Name: "pulse-host", + Usage: "Pulse host to connect to", + Value: "", + EnvVar: "PULSE_HOST", + }, } app.Action = func(c *cli.Context) error { @@ -74,6 +92,14 @@ func main() { w.Write([]byte("OK")) }) + if c.String("pulse-host") != "" { + pulse := pulse.NewConnection( + c.String("pulse-username"), + c.String("pulse-password"), + c.String("pulse-host"), + ) + } + server := &http.Server{ Addr: c.String("addr"), Handler: mux, @@ -94,6 +120,20 @@ func validateCliContext(c *cli.Context) error { } } + pulseSpecified := false + pulseMissing := false + pulseOptions := []string{"pulse-username", "pulse-password", "pulse-host"} + for _, s := range pulseOptions { + if c.String(s) == "" { + pulseMissing = true + } else { + pulseSpecified = true + } + } + if pulseMissing && pulseSpecified { + cErrors = append(cErrors, fmt.Errorf("All or none of %s must be set", pulseOptions)) + } + if len(cErrors) > 0 { return cli.NewMultiError(cErrors...) }