From 998e8052c5211abf8b9ac4c41df79785ddaae751 Mon Sep 17 00:00:00 2001 From: Simon Aronsson Date: Sat, 22 Jun 2019 22:04:36 +0200 Subject: [PATCH] switch urfave to cobra --- app/app.go | 168 ------------------------ cmd/root.go | 178 +++++++++++++++++++++++++ go.mod | 17 ++- go.sum | 77 ++++++++++- internal/flags/flags.go | 269 ++++++++++++++++++++++++++++++++++++++ main.go | 196 +-------------------------- notifications/email.go | 28 ++-- notifications/msteams.go | 11 +- notifications/notifier.go | 12 +- notifications/slack.go | 23 ++-- 10 files changed, 581 insertions(+), 398 deletions(-) delete mode 100644 app/app.go create mode 100644 cmd/root.go create mode 100644 internal/flags/flags.go diff --git a/app/app.go b/app/app.go deleted file mode 100644 index 6a20e4f..0000000 --- a/app/app.go +++ /dev/null @@ -1,168 +0,0 @@ -package app - -import ( - "time" - - "github.com/urfave/cli" -) - -// SetupCliFlags registers flags on the supplied urfave app -func SetupCliFlags(app *cli.App) { - app.Flags = []cli.Flag{ - cli.StringFlag{ - Name: "host, H", - Usage: "daemon socket to connect to", - Value: "unix:///var/run/docker.sock", - EnvVar: "DOCKER_HOST", - }, - cli.IntFlag{ - Name: "interval, i", - Usage: "poll interval (in seconds)", - Value: 300, - EnvVar: "WATCHTOWER_POLL_INTERVAL", - }, - cli.StringFlag{ - Name: "schedule, s", - Usage: "the cron expression which defines when to update", - EnvVar: "WATCHTOWER_SCHEDULE", - }, - cli.BoolFlag{ - Name: "no-pull", - Usage: "do not pull new images", - EnvVar: "WATCHTOWER_NO_PULL", - }, - cli.BoolFlag{ - Name: "no-restart", - Usage: "do not restart containers", - EnvVar: "WATCHTOWER_NO_RESTART", - }, - cli.BoolFlag{ - Name: "cleanup", - Usage: "remove old images after updating", - EnvVar: "WATCHTOWER_CLEANUP", - }, - cli.BoolFlag{ - Name: "tlsverify", - Usage: "use TLS and verify the remote", - EnvVar: "DOCKER_TLS_VERIFY", - }, - cli.DurationFlag{ - Name: "stop-timeout", - Usage: "timeout before container is forcefully stopped", - Value: time.Second * 10, - EnvVar: "WATCHTOWER_TIMEOUT", - }, - cli.BoolFlag{ - Name: "label-enable", - Usage: "watch containers where the com.centurylinklabs.watchtower.enable label is true", - EnvVar: "WATCHTOWER_LABEL_ENABLE", - }, - cli.BoolFlag{ - Name: "debug", - Usage: "enable debug mode with verbose logging", - }, - cli.StringSliceFlag{ - Name: "notifications", - Value: &cli.StringSlice{}, - Usage: "notification types to send (valid: email, slack, msteams)", - EnvVar: "WATCHTOWER_NOTIFICATIONS", - }, - cli.StringFlag{ - Name: "notifications-level", - Usage: "The log level used for sending notifications. Possible values: \"panic\", \"fatal\", \"error\", \"warn\", \"info\" or \"debug\"", - EnvVar: "WATCHTOWER_NOTIFICATIONS_LEVEL", - Value: "info", - }, - cli.StringFlag{ - Name: "notification-email-from", - Usage: "Address to send notification e-mails from", - EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_FROM", - }, - cli.StringFlag{ - Name: "notification-email-to", - Usage: "Address to send notification e-mails to", - EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_TO", - }, - cli.StringFlag{ - Name: "notification-email-server", - Usage: "SMTP server to send notification e-mails through", - EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER", - }, - cli.IntFlag{ - Name: "notification-email-server-port", - Usage: "SMTP server port to send notification e-mails through", - Value: 25, - EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT", - }, - cli.BoolFlag{ - Name: "notification-email-server-tls-skip-verify", - Usage: "Controls whether watchtower verifies the SMTP server's certificate chain and host name. " + - "If set, TLS accepts any certificate " + - "presented by the server and any host name in that certificate. " + - "In this mode, TLS is susceptible to man-in-the-middle attacks. " + - "This should be used only for testing.", - EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_TLS_SKIP_VERIFY", - }, - cli.StringFlag{ - Name: "notification-email-server-user", - Usage: "SMTP server user for sending notifications", - EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER", - }, - cli.StringFlag{ - Name: "notification-email-server-password", - Usage: "SMTP server password for sending notifications", - EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD", - }, - cli.StringFlag{ - Name: "notification-slack-hook-url", - Usage: "The Slack Hook URL to send notifications to", - EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL", - }, - cli.StringFlag{ - Name: "notification-slack-identifier", - Usage: "A string which will be used to identify the messages coming from this watchtower instance. Default if omitted is \"watchtower\"", - EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER", - Value: "watchtower", - }, - cli.StringFlag{ - Name: "notification-slack-channel", - Usage: "A string which overrides the webhook's default channel. Example: #my-custom-channel", - EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_CHANNEL", - }, - cli.StringFlag{ - Name: "notification-slack-icon-emoji", - Usage: "An emoji code string to use in place of the default icon", - EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_ICON_EMOJI", - }, - cli.StringFlag{ - Name: "notification-slack-icon-url", - Usage: "An icon image URL string to use in place of the default icon", - EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_ICON_URL", - }, - cli.StringFlag{ - Name: "notification-msteams-hook", - Usage: "The MSTeams WebHook URL to send notifications to", - EnvVar: "WATCHTOWER_NOTIFICATION_MSTEAMS_HOOK_URL", - }, - cli.BoolFlag{ - Name: "notification-msteams-data", - Usage: "The MSTeams notifier will try to extract log entry fields as MSTeams message facts", - EnvVar: "WATCHTOWER_NOTIFICATION_MSTEAMS_USE_LOG_DATA", - }, - cli.BoolFlag{ - Name: "monitor-only", - Usage: "Will only monitor for new images, not update the containers", - EnvVar: "WATCHTOWER_MONITOR_ONLY", - }, - cli.BoolFlag{ - Name: "run-once", - Usage: "Run once now and exit", - EnvVar: "WATCHTOWER_RUN_ONCE", - }, - cli.BoolFlag{ - Name: "include-stopped", - Usage: "Will also include created and exited containers", - EnvVar: "WATCHTOWER_INCLUDE_STOPPED", - }, - } -} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..18e20ad --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,178 @@ +package cmd + +import ( + "fmt" + "github.com/containrrr/watchtower/actions" + "github.com/containrrr/watchtower/container" + "github.com/containrrr/watchtower/internal/flags" + "github.com/containrrr/watchtower/notifications" + "github.com/robfig/cron" + log "github.com/sirupsen/logrus" + "os" + "os/signal" + "strconv" + "syscall" + "time" + + "github.com/spf13/cobra" +) + +const DockerAPIMinVersion string = "1.24" + +var ( + client container.Client + scheduleSpec string + cleanup bool + noRestart bool + monitorOnly bool + enableLabel bool + notifier *notifications.Notifier + timeout time.Duration +) + +var rootCmd = &cobra.Command{ + Use: "watchtower", + Short: "Automatically updates running Docker containers", + Long: ` +Watchtower automatically updates running Docker containers whenever a new image is released. +More information available at https://github.com/containrrr/watchtower/. +`, + Run: Run, + PreRun: PreRun, +} + +func init() { + flags.SetDefaults() + flags.RegisterDockerFlags(rootCmd) + flags.RegisterSystemFlags(rootCmd) + flags.RegisterNotificationFlags(rootCmd) +} + +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func PreRun(cmd *cobra.Command, args []string) { + f := cmd.PersistentFlags() + + if enabled, _ := f.GetBool("debug"); enabled == true { + log.SetLevel(log.DebugLevel) + } + + pollingSet := f.Changed("interval") + cronSet := f.Changed("schedule") + schedule, _ := f.GetString("schedule") + cronLen := len(schedule) + + if pollingSet && cronSet && cronLen > 0 { + log.Fatal("Only schedule or interval can be defined, not both.") + } else if cronSet && cronLen > 0 { + scheduleSpec, _ = f.GetString("schedule") + } else { + interval, _ := f.GetInt("interval") + scheduleSpec = "@every " + strconv.Itoa(interval) + "s" + } + + cleanup, noRestart, monitorOnly, timeout = flags.ReadFlags(cmd) + + if timeout < 0 { + log.Fatal("Please specify a positive value for timeout value.") + } + enableLabel, _ = f.GetBool("label-enable") + + // configure environment vars for client + err := flags.EnvConfig(cmd, DockerAPIMinVersion) + if err != nil { + log.Fatal(err) + } + + noPull, _ := f.GetBool("no-pull") + includeStopped, _ := f.GetBool("include-stopped") + client = container.NewClient( + !noPull, + includeStopped, + ) + + notifier = notifications.NewNotifier(cmd) +} + +func Run(c *cobra.Command, names []string) { + filter := container.BuildFilter(names, enableLabel) + runOnce, _ := c.PersistentFlags().GetBool("run-once") + + if runOnce { + log.Info("Running a one time update.") + runUpdatesWithNotifications(filter) + os.Exit(1) + return + } + + if err := actions.CheckForMultipleWatchtowerInstances(client, cleanup); err != nil { + log.Fatal(err) + } + + runUpgradesOnSchedule(filter) + os.Exit(1) +} + +func runUpgradesOnSchedule(filter container.Filter) error { + tryLockSem := make(chan bool, 1) + tryLockSem <- true + + cron := cron.New() + err := cron.AddFunc( + scheduleSpec, + func() { + select { + case v := <-tryLockSem: + defer func() { tryLockSem <- v }() + runUpdatesWithNotifications(filter) + default: + log.Debug("Skipped another update already running.") + } + + nextRuns := cron.Entries() + if len(nextRuns) > 0 { + log.Debug("Scheduled next run: " + nextRuns[0].Next.String()) + } + }) + + if err != nil { + return err + } + + log.Debug("Starting Watchtower and scheduling first run: " + cron.Entries()[0].Schedule.Next(time.Now()).String()) + cron.Start() + + // Graceful shut-down on SIGINT/SIGTERM + interrupt := make(chan os.Signal, 1) + signal.Notify(interrupt, os.Interrupt) + signal.Notify(interrupt, syscall.SIGTERM) + + <-interrupt + cron.Stop() + log.Info("Waiting for running update to be finished...") + <-tryLockSem + return nil +} + +func runUpdatesWithNotifications(filter container.Filter) { + notifier.StartNotification() + updateParams := actions.UpdateParams{ + Filter: filter, + Cleanup: cleanup, + NoRestart: noRestart, + Timeout: timeout, + MonitorOnly: monitorOnly, + } + err := actions.Update(client, updateParams) + if err != nil { + log.Println(err) + } + notifier.SendNotification() +} + + diff --git a/go.mod b/go.mod index 0d7ae0e..1690237 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 github.com/Microsoft/go-winio v0.4.12 github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 - github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 + github.com/beorn7/perks v1.0.0 github.com/brysgo/gomock_ginkgo v0.0.0-20180512161304-be2c1b0e4111 github.com/containerd/containerd v1.2.6 // indirect github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 @@ -23,7 +23,6 @@ require ( github.com/gogo/protobuf v1.2.1 github.com/golang/mock v1.1.1 github.com/golang/protobuf v1.3.1 - github.com/google/go-cmp v0.2.0 // indirect github.com/gorilla/mux v1.7.0 github.com/hashicorp/go-memdb v1.0.0 // indirect github.com/hashicorp/go-version v1.1.0 @@ -44,24 +43,24 @@ require ( github.com/opencontainers/selinux v1.2.1 // indirect github.com/pkg/errors v0.8.1 github.com/pmezard/go-difflib v1.0.0 - github.com/prometheus/client_golang v0.9.2 + github.com/prometheus/client_golang v0.9.3 github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 - github.com/prometheus/common v0.2.0 - github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872 + github.com/prometheus/common v0.4.0 + github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084 github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 github.com/sirupsen/logrus v1.4.1 github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.3 + github.com/spf13/viper v1.4.0 github.com/stretchr/objx v0.1.1 github.com/stretchr/testify v1.3.0 github.com/theupdateframework/notary v0.6.1 - github.com/urfave/cli v1.20.0 github.com/vbatts/tar-split v0.11.1 // indirect golang.org/x/crypto v0.0.0-20190403202508-8e1b8d32e692 - golang.org/x/net v0.0.0-20190403144856-b630fd6fe46b + golang.org/x/net v0.0.0-20190522155817-f3200d17e092 golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e - golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect + google.golang.org/appengine v1.4.0 // indirect google.golang.org/genproto v0.0.0-20190401181712-f467c93bbac2 - google.golang.org/grpc v1.19.1 + google.golang.org/grpc v1.21.0 gotest.tools v2.2.0+incompatible // indirect ) diff --git a/go.sum b/go.sum index b0415fc..c9968f6 100644 --- a/go.sum +++ b/go.sum @@ -4,22 +4,34 @@ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Microsoft/go-winio v0.4.12 h1:xAfWHN1IrQ0NJ9TBC0KBZoqLjzDTr1ML+4MywiUOryc= github.com/Microsoft/go-winio v0.4.12/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/brysgo/gomock_ginkgo v0.0.0-20180512161304-be2c1b0e4111 h1:gRfsoKtF1tba+hVsNgo7OKG7a35hBK30ouOTHPgqFf8= github.com/brysgo/gomock_ginkgo v0.0.0-20180512161304-be2c1b0e4111/go.mod h1:H1ipqq0hhUWJgVeQ5dbUe/C8YptJrE/VGDQp9bI+qTo= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/containerd/containerd v1.2.6 h1:K38ZSAA9oKSrX3iFNY+4SddZ8hH1TCMCerc8NHfcKBQ= github.com/containerd/containerd v1.2.6/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 h1:4BX8f882bXEDKfWIf0wa8HRvpnBoPszJJXL+TVbBw4M= github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/docker/cli v0.0.0-20190327152802-57b27434ea29 h1:ciaXDHaWQda0nvevWqcjtXX/buQY3e0lga1vq8Batq0= github.com/docker/cli v0.0.0-20190327152802-57b27434ea29/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= @@ -40,21 +52,29 @@ github.com/docker/swarmkit v1.12.0 h1:vcbNXevt9xOod0miQxkp9WZ70IsOCe8geXkmFnXP2e github.com/docker/swarmkit v1.12.0/go.mod h1:n3Z4lIEl7g261ptkGDBcYi/3qBMDl9csaAhwi2MPejs= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U= github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-memdb v1.0.0 h1:K1O4N2VPndZiTrdH3lmmf5bemr9Xw81KjVwhReIUjTQ= github.com/hashicorp/go-memdb v1.0.0/go.mod h1:I6dKdmYhZqU0RJSheVEWgTNWdVQH5QvTgIUQ0t/t32M= @@ -62,6 +82,8 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= @@ -70,6 +92,7 @@ github.com/johntdyer/slack-go v0.0.0-20180213144715-95fac1160b22 h1:jKUP9TQ0c7X3 github.com/johntdyer/slack-go v0.0.0-20180213144715-95fac1160b22/go.mod h1:u0Jo4f2dNlTJeeOywkM6bLwxq6gC3pZ9rEFHn3AhTdk= github.com/johntdyer/slackrus v0.0.0-20180518184837-f7aae3243a07 h1:+kBG/8rjCa6vxJZbUjAiE4MQmBEBYc8nLEb51frnvBY= github.com/johntdyer/slackrus v0.0.0-20180518184837-f7aae3243a07/go.mod h1:j1kV/8f3jowErEq4XyeypkCdvg5EeHkf0YCKCcq5Ybo= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -77,13 +100,21 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-shellwords v1.0.5/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/pkcs11 v0.0.0-20190401114359-553cfdd26aaa/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -98,6 +129,8 @@ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59P github.com/opencontainers/runtime-spec v1.0.1/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/selinux v1.2.1 h1:Svlc+L67YcjN4K2bqD8Wlw9jtMlmZ+1FEGn6zsm8am0= github.com/opencontainers/selinux v1.2.1/go.mod h1:+BLncwf63G4dgOzykXAxcmnFlUaOlkDdmw/CqsW6pjs= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -106,25 +139,44 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740= github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= +github.com/prometheus/client_golang v0.9.3 h1:9iH4JKXLzFbOAdtqv/a+j8aewx2Y8lAjAydhbaScPF8= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.2.0 h1:kUZDBDTdBVBYBj5Tmh2NZLlF60mfjA27rM34b+cVwNU= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.0 h1:7etb9YClo3a6HjLzfl6rIQaU+FDfi0VSX39io3aQ+DM= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872 h1:0aNv3xC7DmQoy1/x1sMh18g+fihWW68LL13i8ao9kl4= github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084 h1:sofwID9zm4tzrgykg80hfFph1mryUeLRsUfoocVVmRY= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 h1:x7xEyJDP7Hv3LVgvWhzioQqbC/KtuUhTigKlH/8ehhE= github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -133,9 +185,15 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/theupdateframework/notary v0.6.1 h1:7wshjstgS9x9F5LuB1L5mBI2xNMObWqjz+cjWoom6l0= github.com/theupdateframework/notary v0.6.1/go.mod h1:MOfgIfmox8s7/7fduvB2xyPPMJCrjRLRizA8OFwpnKY= -github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/vbatts/tar-split v0.11.1/go.mod h1:LEuURwDEiWjRjwu46yU3KVGuUdVv/dcnpcEPSzR8z6g= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190403202508-8e1b8d32e692 h1:GRhHqDOgeDr6QDTtq9gn2O4iKvm5dsbfqD/TXb0KLX0= @@ -143,14 +201,19 @@ golang.org/x/crypto v0.0.0-20190403202508-8e1b8d32e692/go.mod h1:WFFai1msRO1wXaE golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190403144856-b630fd6fe46b h1:/zjbcJPEGAyu6Is/VBOALsgdi4z9+kz/Vtdm6S+beD0= golang.org/x/net v0.0.0-20190403144856-b630fd6fe46b/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -160,16 +223,19 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e h1:nFYrTHrdrAOpShe27kaFHjsqYSEQ0KWqdWLu3xuZJts= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -178,12 +244,19 @@ google.golang.org/genproto v0.0.0-20190401181712-f467c93bbac2/go.mod h1:VzzqZJRn google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.19.1 h1:TrBcJ1yqAl1G++wO39nD/qtgpsW9/1+QGrluyMGEYgM= google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0 h1:G+97AoqBnmZIT91cLG/EkCoK9NSelj64P8bOHHNmGn0= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/flags/flags.go b/internal/flags/flags.go new file mode 100644 index 0000000..236e4ba --- /dev/null +++ b/internal/flags/flags.go @@ -0,0 +1,269 @@ +package flags + +import ( + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "os" + "time" +) + +func RegisterDockerFlags(rootCmd *cobra.Command) { + flags := rootCmd.PersistentFlags() + flags.StringP("host", "H", viper.GetString("DOCKER_HOST"), "daemon socket to connect to") + flags.BoolP("tlsverify", "v", viper.GetBool("DOCKER_TLS_VERIFY"), "use TLS and verify the remote") +} + +func RegisterSystemFlags(rootCmd *cobra.Command) { + flags := rootCmd.PersistentFlags() + flags.IntP( + "interval", + "i", + viper.GetInt("WATCHTOWER_POLL_INTERVAL"), + "poll interval (in seconds)") + + flags.StringP("schedule", + "s", + viper.GetString("WATCHTOWER_SCHEDULE"), + "the cron expression which defines when to update") + + flags.DurationP("stop-timeout", + "t", + viper.GetDuration("WATCHTOWER_TIMEOUT"), + "timeout before a container is forcefully stopped") + + flags.BoolP( + "no-pull", + "", + viper.GetBool("WATCHTOWER_NO_PULL"), + "do not pull any new images") + + flags.BoolP( + "no-restart", + "", + viper.GetBool("WATCHTOWER_NO_RESTART"), + "do not restart any containers") + + flags.BoolP( + "cleanup", + "c", + viper.GetBool("WATCHTOWER_CLEANUP"), + "remove previously used images after updating") + + flags.BoolP( + "label-enable", + "e", + viper.GetBool("WATCHTOWER_LABEL_ENABLE"), + "watch containers where the com.centurylinklabs.watchtower.enable label is true") + + flags.BoolP( + "debug", + "d", + viper.GetBool("WATCHTOWER_DEBUG"), + "enable debug mode with verbose logging") + + + flags.BoolP( + "monitor-only", + "m", + viper.GetBool("WATCHTOWER_MONITOR_ONLY"), + "Will only monitor for new images, not update the containers") + + flags.BoolP( + "run-once", + "R", + viper.GetBool("WATCHTOWER_RUN_ONCE"), + "Run once now and exit") + + flags.BoolP( + "include-stopped", + "S", + viper.GetBool("WATCHTOWER_INCLUDE_STOPPED"), + "Will also include created and exited containers") +} + +func RegisterNotificationFlags(rootCmd *cobra.Command) { + flags := rootCmd.PersistentFlags() + + flags.StringSliceP( + "notifications", + "n", + viper.GetStringSlice("WATCHTOWER_NOTIFICATIONS"), + " notification types to send (valid: email, slack, msteams") + + flags.StringP( + "notifications-level", + "", + viper.GetString("WATCHTOWER_NOTIFICATIONS_LEVEL"), + "The log level used for sending notifications. Possible values: panic, fatal, error, warn, info or debug") + + flags.StringP( + "notification-email-from", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_FROM"), + "Address to send notification emails from") + + flags.StringP( + "notification-email-to", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_TO"), + "Address to send notification emails to") + + flags.StringP( + "notification-email-server", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_SERVER"), + "SMTP server to send notification emails through") + + flags.StringP( + "notification-email-server-port", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT"), + "SMTP server port to send notification emails through") + + flags.BoolP( + "notification-email-server-tls-skip-verify", + "", + viper.GetBool("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_TLS_SKIP_VERIFY"), + ` +Controls whether watchtower verifies the SMTP server's certificate chain and host name. +Should only be used for testing. +`) + + flags.StringP( + "notification-email-server-user", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER"), + "SMTP server user for sending notifications") + + flags.StringP( + "notification-email-server-password", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD"), + "SMTP server password for sending notifications") + + flags.StringP( + "notification-slack-hook-url", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL"), + "The Slack Hook URL to send notifications to") + + flags.StringP( + "notification-slack-identifier", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER"), + "A string which will be used to identify the messages coming from this watchtower instance") + + flags.StringP( + "notification-slack-channel", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_SLACK_CHANNEL"), + "A string which overrides the webhook's default channel. Example: #my-custom-channel") + + flags.StringP( + "notification-slack-icon-emoji", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_SLACK_ICON_EMOJI"), + "An emoji code string to use in place of the default icon") + + flags.StringP( + "notification-slack-icon-url", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_SLACK_ICON_URL"), + "An icon image URL string to use in place of the default icon") + + flags.StringP( + "notification-msteams-hook", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_MSTEAMS_HOOK_URL"), + "The MSTeams WebHook URL to send notifications to") + + flags.BoolP( + "notification-msteams-data", + "", + viper.GetBool("WATCHTOWER_NOTIFICATION_MSTEAMS_USE_LOG_DATA"), + "The MSTeams notifier will try to extract log entry fields as MSTeams message facts") +} + +func SetDefaults() { + viper.AutomaticEnv() + viper.SetDefault("DOCKER_HOST", "unix:///var/run/docker.sock") + viper.SetDefault("WATCHTOWER_POLL_INTERVAL", 300) + viper.SetDefault("WATCHTOWER_TIMEOUT", time.Second*10) + viper.SetDefault("WATCHTOWER_NOTIFICATIONS", []string{}) + viper.SetDefault("WATCHTOWER_NOTIFICATIONS_LEVEL", "info") + viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT", 25) + viper.SetDefault("WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER", "watchtower") +} + +// envConfig translates the command-line options into environment variables +// that will initialize the api client +func EnvConfig(cmd *cobra.Command, dockerAPIMinVersion string) error { + var err error + var host string + var tls bool + + flags := cmd.PersistentFlags() + + if host, err = flags.GetString("host"); err != nil { + return err + } + if tls, err = flags.GetBool("tlsverify"); err != nil { + return err + } + if err = setEnvOptStr("DOCKER_HOST", host); err != nil { + return err + } + if err = setEnvOptBool("DOCKER_TLS_VERIFY", tls); err != nil { + return err + } + if err = setEnvOptStr("DOCKER_API_VERSION", dockerAPIMinVersion); err != nil { + return err + } + return nil +} + +func ReadFlags(cmd *cobra.Command) (bool, bool, bool, time.Duration) { + flags := cmd.PersistentFlags() + + var err error + var cleanup bool + var noRestart bool + var monitorOnly bool + var timeout time.Duration + + if cleanup, err = flags.GetBool("cleanup"); err != nil { + log.Fatal(err) + } + if noRestart, err = flags.GetBool("no-restart"); err != nil { + log.Fatal(err) + } + if monitorOnly, err = flags.GetBool("monitor-only"); err != nil { + log.Fatal(err) + } + if timeout, err = flags.GetDuration("stop-timeout"); err != nil { + log.Fatal(err) + } + + return cleanup, noRestart, monitorOnly, timeout +} + + +func setEnvOptStr(env string, opt string) error { + if opt == "" || opt == os.Getenv(env) { + return nil + } + err := os.Setenv(env, opt) + if err != nil { + return err + } + return nil +} + +func setEnvOptBool(env string, opt bool) error { + if opt == true { + return setEnvOptStr(env, "1") + } + return nil +} + diff --git a/main.go b/main.go index faf35b6..c2ed833 100644 --- a/main.go +++ b/main.go @@ -1,213 +1,21 @@ package main // import "github.com/containrrr/watchtower" import ( - "os" - "os/signal" - "syscall" - "time" - - "strconv" - - "github.com/containrrr/watchtower/actions" - cliApp "github.com/containrrr/watchtower/app" - "github.com/containrrr/watchtower/container" - "github.com/containrrr/watchtower/notifications" - "github.com/robfig/cron" + "github.com/containrrr/watchtower/cmd" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" ) // DockerAPIMinVersion is the version of the docker API, which is minimally required by // watchtower. Currently we require at least API 1.24 and therefore Docker 1.12 or later. -const DockerAPIMinVersion string = "1.24" var version = "master" var commit = "unknown" var date = "unknown" -var ( - client container.Client - scheduleSpec string - cleanup bool - noRestart bool - monitorOnly bool - enableLabel bool - notifier *notifications.Notifier - timeout time.Duration -) - func init() { log.SetLevel(log.InfoLevel) } func main() { - app := cli.NewApp() - InitApp(app) - cliApp.SetupCliFlags(app) - - if err := app.Run(os.Args); err != nil { - log.Fatal(err) - } -} - -// InitApp initializes urfave app metadata and sets up entrypoints -func InitApp(app *cli.App) { - app.Name = "watchtower" - app.Version = version + " - " + commit + " - " + date - app.Usage = "Automatically update running Docker containers" - app.Before = before - app.Action = start -} - -func before(c *cli.Context) error { - if c.GlobalBool("debug") { - log.SetLevel(log.DebugLevel) - } - - pollingSet := c.IsSet("interval") - cronSet := c.IsSet("schedule") - cronLen := len(c.String("schedule")) - - if pollingSet && cronSet && cronLen > 0 { - log.Fatal("Only schedule or interval can be defined, not both.") - } else if cronSet && cronLen > 0 { - scheduleSpec = c.String("schedule") - } else { - scheduleSpec = "@every " + strconv.Itoa(c.Int("interval")) + "s" - } - - readFlags(c) - - if timeout < 0 { - log.Fatal("Please specify a positive value for timeout value.") - } - enableLabel = c.GlobalBool("label-enable") - - // configure environment vars for client - err := envConfig(c) - if err != nil { - return err - } - - client = container.NewClient( - !c.GlobalBool("no-pull"), - c.GlobalBool("include-stopped"), - ) - notifier = notifications.NewNotifier(c) - - return nil -} - -func start(c *cli.Context) error { - names := c.Args() - filter := container.BuildFilter(names, enableLabel) - - if c.GlobalBool("run-once") { - log.Info("Running a one time update.") - runUpdatesWithNotifications(filter) - os.Exit(1) - return nil - } - - if err := actions.CheckForMultipleWatchtowerInstances(client, cleanup); err != nil { - log.Fatal(err) - } - - runUpgradesOnSchedule(filter) - os.Exit(1) - return nil -} - -func runUpgradesOnSchedule(filter container.Filter) error { - tryLockSem := make(chan bool, 1) - tryLockSem <- true - - cron := cron.New() - err := cron.AddFunc( - scheduleSpec, - func() { - select { - case v := <-tryLockSem: - defer func() { tryLockSem <- v }() - runUpdatesWithNotifications(filter) - default: - log.Debug("Skipped another update already running.") - } - - nextRuns := cron.Entries() - if len(nextRuns) > 0 { - log.Debug("Scheduled next run: " + nextRuns[0].Next.String()) - } - }) - - if err != nil { - return err - } - - log.Debug("Starting Watchtower and scheduling first run: " + cron.Entries()[0].Schedule.Next(time.Now()).String()) - cron.Start() - - // Graceful shut-down on SIGINT/SIGTERM - interrupt := make(chan os.Signal, 1) - signal.Notify(interrupt, os.Interrupt) - signal.Notify(interrupt, syscall.SIGTERM) - - <-interrupt - cron.Stop() - log.Info("Waiting for running update to be finished...") - <-tryLockSem - return nil -} - -func runUpdatesWithNotifications(filter container.Filter) { - notifier.StartNotification() - updateParams := actions.UpdateParams{ - Filter: filter, - Cleanup: cleanup, - NoRestart: noRestart, - Timeout: timeout, - MonitorOnly: monitorOnly, - } - err := actions.Update(client, updateParams) - if err != nil { - log.Println(err) - } - notifier.SendNotification() -} - -func setEnvOptStr(env string, opt string) error { - if opt == "" || opt == os.Getenv(env) { - return nil - } - err := os.Setenv(env, opt) - if err != nil { - return err - } - return nil -} - -func setEnvOptBool(env string, opt bool) error { - if opt == true { - return setEnvOptStr(env, "1") - } - return nil -} - -// envConfig translates the command-line options into environment variables -// that will initialize the api client -func envConfig(c *cli.Context) error { - var err error - - err = setEnvOptStr("DOCKER_HOST", c.GlobalString("host")) - err = setEnvOptBool("DOCKER_TLS_VERIFY", c.GlobalBool("tlsverify")) - err = setEnvOptStr("DOCKER_API_VERSION", DockerAPIMinVersion) - - return err -} - -func readFlags(c *cli.Context) { - cleanup = c.GlobalBool("cleanup") - noRestart = c.GlobalBool("no-restart") - monitorOnly = c.GlobalBool("monitor-only") - timeout = c.GlobalDuration("stop-timeout") + cmd.Execute() } diff --git a/notifications/email.go b/notifications/email.go index 5f84ca5..fd3f4e8 100644 --- a/notifications/email.go +++ b/notifications/email.go @@ -3,6 +3,7 @@ package notifications import ( "encoding/base64" "fmt" + "github.com/spf13/cobra" "net/smtp" "os" "time" @@ -10,7 +11,6 @@ import ( "strconv" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" ) const ( @@ -31,15 +31,25 @@ type emailTypeNotifier struct { logLevels []log.Level } -func newEmailNotifier(c *cli.Context, acceptedLogLevels []log.Level) typeNotifier { +func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) typeNotifier { + flags := c.PersistentFlags() + + from, _ := flags.GetString("notification-email-from") + to, _ := flags.GetString("notification-email-to") + server, _ := flags.GetString("notification-email-server") + user, _ := flags.GetString("notification-email-server-user") + password, _ := flags.GetString("notification-email-server-password") + port, _ := flags.GetInt("notification-email-server-port") + tlsSkipVerify, _ := flags.GetBool("notification-email-server-tls-skip-verify") + n := &emailTypeNotifier{ - From: c.GlobalString("notification-email-from"), - To: c.GlobalString("notification-email-to"), - Server: c.GlobalString("notification-email-server"), - User: c.GlobalString("notification-email-server-user"), - Password: c.GlobalString("notification-email-server-password"), - Port: c.GlobalInt("notification-email-server-port"), - tlsSkipVerify: c.GlobalBool("notification-email-server-tls-skip-verify"), + From: from, + To: to, + Server: server, + User: user, + Password: password, + Port: port, + tlsSkipVerify: tlsSkipVerify, logLevels: acceptedLogLevels, } diff --git a/notifications/msteams.go b/notifications/msteams.go index 8bb9d7a..325c452 100644 --- a/notifications/msteams.go +++ b/notifications/msteams.go @@ -4,10 +4,10 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/spf13/cobra" "net/http" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" "io/ioutil" ) @@ -21,17 +21,20 @@ type msTeamsTypeNotifier struct { data bool } -func newMsTeamsNotifier(c *cli.Context, acceptedLogLevels []log.Level) typeNotifier { +func newMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) typeNotifier { - webHookURL := c.GlobalString("notification-msteams-hook") + flags := cmd.PersistentFlags() + + webHookURL, _ := flags.GetString("notification-msteams-hook") if len(webHookURL) <= 0 { log.Fatal("Required argument --notification-msteams-hook(cli) or WATCHTOWER_NOTIFICATION_MSTEAMS_HOOK_URL(env) is empty.") } + withData, _ := flags.GetBool("notification-msteams-data") n := &msTeamsTypeNotifier{ levels: acceptedLogLevels, webHookURL: webHookURL, - data: c.GlobalBool("notification-msteams-data"), + data: withData, } log.AddHook(n) diff --git a/notifications/notifier.go b/notifications/notifier.go index 62e8ebc..145eccd 100644 --- a/notifications/notifier.go +++ b/notifications/notifier.go @@ -3,7 +3,7 @@ package notifications import ( "github.com/johntdyer/slackrus" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) type typeNotifier interface { @@ -17,10 +17,13 @@ type Notifier struct { } // NewNotifier creates and returns a new Notifier, using global configuration. -func NewNotifier(c *cli.Context) *Notifier { +func NewNotifier(c *cobra.Command) *Notifier { n := &Notifier{} - logLevel, err := log.ParseLevel(c.GlobalString("notifications-level")) + f := c.PersistentFlags() + + level, _ := f.GetString("notifications-level") + logLevel, err := log.ParseLevel(level) if err != nil { log.Fatalf("Notifications invalid log level: %s", err.Error()) } @@ -28,7 +31,8 @@ func NewNotifier(c *cli.Context) *Notifier { acceptedLogLevels := slackrus.LevelThreshold(logLevel) // Parse types and create notifiers. - types := c.GlobalStringSlice("notifications") + types, _ := f.GetStringSlice("notifications") + for _, t := range types { var tn typeNotifier switch t { diff --git a/notifications/slack.go b/notifications/slack.go index 08f8d3b..99ad1dd 100644 --- a/notifications/slack.go +++ b/notifications/slack.go @@ -3,7 +3,7 @@ package notifications import ( "github.com/johntdyer/slackrus" log "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) const ( @@ -14,20 +14,27 @@ type slackTypeNotifier struct { slackrus.SlackrusHook } -func newSlackNotifier(c *cli.Context, acceptedLogLevels []log.Level) typeNotifier { +func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) typeNotifier { + flags := c.PersistentFlags() + + hookUrl, _ := flags.GetString("notification-slack-hook-url") + userName, _ := flags.GetString("notification-slack-identifier") + channel, _ := flags.GetString("notification-slack-channel") + emoji, _ := flags.GetString("notification-slack-icon-emoji") + iconUrl, _ := flags.GetString("notification-slack-icon-url") + n := &slackTypeNotifier{ SlackrusHook: slackrus.SlackrusHook{ - HookURL: c.GlobalString("notification-slack-hook-url"), - Username: c.GlobalString("notification-slack-identifier"), - Channel: c.GlobalString("notification-slack-channel"), - IconEmoji: c.GlobalString("notification-slack-icon-emoji"), - IconURL: c.GlobalString("notification-slack-icon-url"), + HookURL: hookUrl, + Username: userName, + Channel: channel, + IconEmoji: emoji, + IconURL: iconUrl, AcceptedLevels: acceptedLogLevels, }, } log.AddHook(n) - return n }