From a9187950c991fd2523d9dfcc53a65d43d42e56af Mon Sep 17 00:00:00 2001 From: Tim Heurich Date: Thu, 7 Sep 2023 12:36:10 +0200 Subject: [PATCH] feat: respect BROWSER env var fixes #130 Signed-off-by: Tim Heurich --- README.md | 3 +++ pkg/sso/aws.go | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 463d413..ba49630 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Make working with AWS SSO on local machines an ease. * Choose your desired account and role interactively * Choose your account and role via flags from command line * Utilize AWSs `credential_process` to avoid storing credentials locally + * Locks concurrent calls to `credential_process` to no DDoS your Browser (this behaviour occurs from time to time when using e.g. the k8s plugin for IntelliJ) * Refresh credentials based on your previously chosen account and role (if you've chosen to persist your credentials) * Store your Start-URL and region * Set different profiles for your different accounts @@ -108,6 +109,8 @@ OPTIONS: ### Configuration +* If you want to point to a specific non-default Browser, do so via the `BROWSER` environment variable +
Basics ``` diff --git a/pkg/sso/aws.go b/pkg/sso/aws.go index 02fcd06..602e21b 100644 --- a/pkg/sso/aws.go +++ b/pkg/sso/aws.go @@ -175,8 +175,17 @@ func startDeviceAuthorization(oidc ssooidciface.SSOOIDCAPI, rco *ssooidc.Registe func openUrlInBrowser(url string) { var err error - osName := determineOsName() + if env, ok := os.LookupEnv("BROWSER"); ok { + zap.S().Debugf("using BROWSER environment variable: %s", env) + err = exec.Command(env, url).Start() + if err != nil { + zap.S().Fatalf("error while opening browser: %s", err) + } + return + } + + osName := determineOsName() switch osName { case "linux": err = exec.Command("xdg-open", url).Start() @@ -187,7 +196,7 @@ func openUrlInBrowser(url string) { case "wsl": err = exec.Command("wslview", url).Start() default: - err = fmt.Errorf("could not open %s - unsupported platform. Please open the URL manually", url) + err = fmt.Errorf("could not open %s - unsupported platform. Please open the URL manually or use the BROWSER environemnt variable to point to your browser", url) } if err != nil { zap.S().Error(err)