Skip to content

Commit

Permalink
Macaroon update fixes (#4059)
Browse files Browse the repository at this point in the history
* don't try opening browser in ci/noninteractive setting

* don't fetch missing org tokens when tokens came from env var
  • Loading branch information
btoews authored Nov 12, 2024
1 parent d522500 commit 3ab4f26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 7 additions & 4 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,14 @@ func RequireSession(ctx context.Context) (context.Context, error) {
}

func tryOpenUserURL(ctx context.Context, url string) error {
io := iostreams.FromContext(ctx)

if !io.IsInteractive() || env.IsCI() {
return errors.New("failed opening browser")
}

if err := open.Run(url); err != nil {
fmt.Fprintf(iostreams.FromContext(ctx).ErrOut,
"failed opening browser. Copy the url (%s) into a browser and continue\n",
url,
)
fmt.Fprintf(io.ErrOut, "failed opening browser. Copy the url (%s) into a browser and continue\n", url)
}

return nil
Expand Down
7 changes: 6 additions & 1 deletion internal/config/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func MonitorTokens(monitorCtx context.Context, t *tokens.Tokens, uucb UserURLCal
log.Debugf("failed to update discharge tokens: %s", err)
}

if file != "" && updated1 || updated2 {
if file != "" && (updated1 || updated2) {
if err := SetAccessToken(file, t.All()); err != nil {
log.Debugf("failed to persist updated tokens: %s", err)
}
Expand Down Expand Up @@ -198,6 +198,11 @@ func refreshDischargeTokens(ctx context.Context, t *tokens.Tokens, uucb UserURLC
//
// Don't call this when other goroutines might also be accessing t.
func fetchOrgTokens(ctx context.Context, t *tokens.Tokens) (bool, error) {
// don't fetch missing org tokens if tokens came from environment var
if t.FromFile() == "" {
return false, nil
}

return doFetchOrgTokens(ctx, t, defaultOrgFetcher, defaultTokenMinter)
}

Expand Down

0 comments on commit 3ab4f26

Please sign in to comment.