From eb25fd90c03ecb139be4d62ceb40bd5b7457372a Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Mon, 15 Nov 2021 19:00:23 -0800 Subject: [PATCH] Fix missing --url-action & update main args * Fix error processing empty --url-action and --browser * No longer print URL when sending to browser or clipboard * Move defaults from DEFAULT_CONFIG to CLI struct Fixes: #133 --- CHANGELOG.md | 3 +++ cmd/console_cmd.go | 2 +- cmd/main.go | 20 +++++++++----------- sso/settings.go | 3 ++- utils/utils.go | 8 ++++---- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fa091c5..2f26b3c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] + * Fix missing --url-action and --browser #113 + * Don't print out URL when sending to browser/clipboard for security + ## [v1.3.0] - 2021-11-14 * Add report card and make improvements to code style #124 diff --git a/cmd/console_cmd.go b/cmd/console_cmd.go index 1fed6430..ca57b4ca 100644 --- a/cmd/console_cmd.go +++ b/cmd/console_cmd.go @@ -165,7 +165,7 @@ func openConsoleAccessKey(ctx *RunContext, creds *storage.RoleCredentials, durat } url := login.GetUrl() - return utils.HandleUrl(ctx.Cli.UrlAction, ctx.Cli.Browser, url, + return utils.HandleUrl(ctx.Settings.UrlAction, ctx.Settings.Browser, url, "Please open the following URL in your browser:\n\n", "\n\n") } diff --git a/cmd/main.go b/cmd/main.go index bc8a3344..a12ac675 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -23,7 +23,7 @@ import ( "os" "github.com/alecthomas/kong" - // "github.com/davecgh/go-spew/spew" + "github.com/davecgh/go-spew/spew" "github.com/posener/complete" log "github.com/sirupsen/logrus" "github.com/synfinatic/aws-sso-cli/sso" @@ -72,10 +72,7 @@ var DEFAULT_CONFIG map[string]interface{} = map[string]interface{}{ "PromptColors.SelectedSuggestionTextColor": "Black", "PromptColors.SuggestionBGColor": "Cyan", "PromptColors.SuggestionTextColor": "White", - "UrlAction": "open", "DefaultSSO": "Default", - "LogLevel": "info", - "LogLines": false, "DefaultRegion": "us-east-1", "HistoryLimit": 10, "ListFields": []string{"AccountId", "AccountAlias", "RoleName", "ExpiresStr"}, @@ -83,13 +80,13 @@ var DEFAULT_CONFIG map[string]interface{} = map[string]interface{}{ type CLI struct { // Common Arguments - Browser string `kong:"optional,short='b',help='Path to browser to open URLs with',env='AWS_SSO_BROWSER'"` - ConfigFile string `kong:"optional,name='config',default='${CONFIG_FILE}',help='Config file',env='AWS_SSO_CONFIG'"` - Lines bool `kong:"optional,help='Print line number in logs'"` - LogLevel string `kong:"optional,short='L',name='level',enum='error,warn,info,debug,trace,',help='Logging level [error|warn|info|debug|trace]'"` - UrlAction string `kong:"optional,short='u',enum='open,print,clip,',help='How to handle URLs [open|print|clip]'"` - SSO string `kong:"optional,short='S',help='AWS SSO Instance',env='AWS_SSO',predictor='sso'"` - STSRefresh bool `kong:"optional,help='Force refresh of STS Token Credentials'"` + Browser string `kong:"short='b',help='Path to browser to open URLs with',env='AWS_SSO_BROWSER'"` + ConfigFile string `kong:"name='config',default='${CONFIG_FILE}',help='Config file',env='AWS_SSO_CONFIG'"` + Lines bool `kong:"help='Print line number in logs'"` + LogLevel string `kong:"short='L',name='level',enum='error,warn,info,debug,trace',default='info',help='Logging level [error|warn|info|debug|trace]'"` + UrlAction string `kong:"short='u',enum='open,print,clip',default='open',help='How to handle URLs [open|print|clip]'"` + SSO string `kong:"short='S',help='AWS SSO Instance',env='AWS_SSO',predictor='sso'"` + STSRefresh bool `kong:"help='Force refresh of STS Token Credentials'"` // Commands Cache CacheCmd `kong:"cmd,help='Force reload of cached AWS SSO role info and config.yaml'"` @@ -121,6 +118,7 @@ func main() { if run_ctx.Settings, err = sso.LoadSettings(cli.ConfigFile, cacheFile, DEFAULT_CONFIG, override); err != nil { log.Fatalf("%s", err.Error()) } + log.Debugf("settings: %s", spew.Sdump(run_ctx.Settings)) // Load the secure store data switch run_ctx.Settings.SecureStore { diff --git a/sso/settings.go b/sso/settings.go index 66aef272..4b08065e 100644 --- a/sso/settings.go +++ b/sso/settings.go @@ -24,7 +24,7 @@ import ( "strconv" "strings" - // "github.com/davecgh/go-spew/spew" + // "github.com/davecgh/go-spew/spew" "github.com/knadh/koanf" "github.com/knadh/koanf/parsers/yaml" "github.com/knadh/koanf/providers/confmap" @@ -207,6 +207,7 @@ func (s *Settings) setOverrides(override OverrideSettings) { if override.DefaultSSO != "" { s.DefaultSSO = override.DefaultSSO } + if override.UrlAction != "" { s.UrlAction = override.UrlAction } diff --git a/utils/utils.go b/utils/utils.go index f0c11c08..645b02a2 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -59,7 +59,7 @@ func HandleUrl(action, browser, url, pre, post string) error { if err == nil { fmt.Printf("Please open URL copied to clipboard.\n") } else { - err = fmt.Errorf("Unable to copy %s to clipboard: %s", url, err.Error()) + err = fmt.Errorf("Unable to copy URL to clipboard: %s", err.Error()) } case "print": fmt.Printf("%s%s%s", pre, url, post) @@ -71,12 +71,12 @@ func HandleUrl(action, browser, url, pre, post string) error { err = open.RunWith(url, browser) } if err != nil { - err = fmt.Errorf("Unable to open %s with %s: %s", url, browser, err.Error()) + err = fmt.Errorf("Unable to open URL with %s: %s", browser, err.Error()) } else { - fmt.Printf("Opening %s in %s\n", url, browser) + fmt.Printf("Opening URL in %s\n", browser) } default: - err = fmt.Errorf("Unknown --url-action option: %s", action) + err = fmt.Errorf("Unknown --url-action option: '%s'", action) } return err