Skip to content

Commit

Permalink
Add skeleton support for listening to pulse.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomprince committed Mar 25, 2020
1 parent 6e2c7a9 commit ddec9c0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
40 changes: 40 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"go.mozilla.org/mozlog"

"github.com/urfave/cli"

"github.com/taskcluster/pulse-go/pulse"
)

func init() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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...)
}
Expand Down

0 comments on commit ddec9c0

Please sign in to comment.