From e7349740cba76ed2912e07178f1c6820803f575e Mon Sep 17 00:00:00 2001 From: Patrick Sanders Date: Fri, 26 Mar 2021 16:27:59 -0700 Subject: [PATCH] Add separate config for service flags (#58) --- cmd/service.go | 10 +++++++++- config/config.go | 1 + example-config.yaml | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index 4a75431..e21256a 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -57,14 +57,22 @@ func (p *program) Start(s service.Service) error { } func (p *program) run() { + var err error log.Info("starting weep service!") exitCode := 0 + + flags := viper.GetStringSlice("service.args") + err = rootCmd.ParseFlags(flags) + if err != nil { + log.Errorf("could not parse flags: %v", err) + } + args := viper.GetStringSlice("service.args") switch command := viper.GetString("service.command"); command { case "ecs_credential_provider": fallthrough case "serve": - err := runWeepServer(nil, args) + err = runWeepServer(nil, args) if err != nil { log.Error(err) exitCode = 1 diff --git a/config/config.go b/config/config.go index 189785d..4ca6853 100644 --- a/config/config.go +++ b/config/config.go @@ -44,6 +44,7 @@ func init() { viper.SetDefault("server.port", 9091) viper.SetDefault("service.command", "ecs_credential_provider") viper.SetDefault("service.args", []string{}) + viper.SetDefault("service.flags", []string{}) // Set aliases for backward-compatibility viper.RegisterAlias("server.ecs_credential_provider_port", "server.port") diff --git a/example-config.yaml b/example-config.yaml index cdb39a9..954fcaf 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -9,10 +9,12 @@ server: address: 127.0.0.1 port: 9091 service: - command: ecs_credential_provider - args: + command: serve + flags: # Flags are CLI options - --log-level - debug + args: # Args are command arguments. This configuration will start the metadata service with credentials for roleName + - roleName #challenge_settings: # (Optional) Username can be provided. If it is not provided, user will be prompted on first authentication attempt # user: you@example.com mtls_settings: # only needed if authentication_method is mtls