Skip to content

Commit bdd24cf

Browse files
maksim-zuev-dbIsaac
andauthored
Apply the timeout to the auth token inline login (#7267)
## Changes `runInlineLogin` in `databricks auth token` now creates its timeout context before `NewPersistentAuth`, as `databricks auth login` does. ## Why Follow-up to [this review](#7196 (review)) on #7196. `PersistentAuth.Challenge` uses the context passed to `NewPersistentAuth`, but the timeout context was created after it, so the one hour timeout never applied. Closing the browser tab left `auth token` waiting until Ctrl+C. ## Tests - `cmd/auth` unit tests pass. - No new test: covering it would need the one hour `defaultTimeout` to be injectable. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
1 parent a7e6114 commit bdd24cf

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎cmd/auth/token.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,15 +452,18 @@ func runInlineLogin(ctx context.Context, profiler profile.Profiler, tokenStore s
452452
u2m.WithOAuthArgument(oauthArgument),
453453
u2m.WithBrowser(func(url string) error { return browser.Open(ctx, url) }),
454454
}
455+
456+
// Challenge uses the context passed to NewPersistentAuth, so the timeout
457+
// must be set before it.
458+
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
459+
defer cancel()
460+
455461
persistentAuth, err := u2m.NewPersistentAuth(ctx, persistentAuthOpts...)
456462
if err != nil {
457463
return "", nil, err
458464
}
459465
defer persistentAuth.Close()
460466

461-
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
462-
defer cancel()
463-
464467
token, err := persistentAuth.Challenge()
465468
if err != nil {
466469
return "", nil, err

0 commit comments

Comments
 (0)