Skip to content

Commit

Permalink
feat: respect BROWSER env var
Browse files Browse the repository at this point in the history
fixes #130

Signed-off-by: Tim Heurich <[email protected]>
  • Loading branch information
theurichde committed Sep 7, 2023
1 parent 07602db commit a918795
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,6 +109,8 @@ OPTIONS:

### Configuration

* If you want to point to a specific non-default Browser, do so via the `BROWSER` environment variable

<details><summary>Basics</summary>

```
Expand Down
13 changes: 11 additions & 2 deletions pkg/sso/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit a918795

Please sign in to comment.