Add --force-refresh support for Databricks CLI token fetching#751
Open
mihaimitrea-db wants to merge 1 commit intomainfrom
Open
Add --force-refresh support for Databricks CLI token fetching#751mihaimitrea-db wants to merge 1 commit intomainfrom
mihaimitrea-db wants to merge 1 commit intomainfrom
Conversation
048a903 to
5e8f476
Compare
Contributor
Author
Range-diff: main (048a903 -> 5e8f476)
Reproduce locally: |
5e8f476 to
6b8a57f
Compare
Contributor
Author
Range-diff: main (5e8f476 -> 6b8a57f)
Reproduce locally: |
6b8a57f to
61686da
Compare
Contributor
Author
Range-diff: main (6b8a57f -> 61686da)
Reproduce locally: |
Try `--force-refresh` before the regular CLI command so the SDK can bypass the CLI's own token cache when the SDK considers its token stale. If the CLI is too old to recognise `--force-refresh` (or `--profile`), gracefully fall back to the next command in the chain. Chain order: - with profile: forceCmd (--profile --force-refresh) -> profileCmd (--profile) -> fallbackCmd (--host) - without profile: forceCmd (--host --force-refresh) -> profileCmd (--host) Azure CLI callers are unchanged; they use constructors that leave forceCmd null, preserving existing behavior. Signed-off-by: Mihai Mitrea <mihai.mitrea@databricks.com>
61686da to
1c68e85
Compare
Contributor
Author
Range-diff: main (61686da -> 1c68e85)
Reproduce locally: |
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🥞 Stacked PR
Use this link to review incremental changes.
Summary
Pass
--force-refreshto the Databricks CLIauth tokencommand so the SDK always receives a fresh token instead of a potentially stale one from the CLI's internal cache.Why
The SDK manages its own token caching via
CachedTokenSource. When the SDK decides it needs a new token and shells out todatabricks auth token, the CLI may return a cached token that is about to expire (or has already expired from the SDK's perspective). This creates unnecessary refresh failures and retry loops.The CLI recently added a
--force-refreshflag (databricks/cli#4767) that bypasses its internal cache. By using this flag, the SDK is guaranteed a freshly minted token every time it asks for one, eliminating the stale-token problem.What changed
Interface changes
None.
CliTokenSourceis not part of the public API surface.Behavioral changes
--force-refreshwhen invokingdatabricks auth token. If the CLI is too old to support this flag, the SDK falls back to the plain--profilecommand (and then to--hostif--profileis also unsupported)."Databricks CLI does not support --force-refresh flag. Falling back to regular token fetch. Please upgrade your CLI to the latest version."--profilefallback warning is unchanged.Internal changes
CliTokenSourcenow holds three command variants:forceCmd(--profile+--force-refresh),profileCmd(--profile), andfallbackCmd(--host). Any of these can be null depending on the config.getDatabricksCliTokenSourceinDatabricksCliCredentialsProviderbuilds all three commands.forceCmdis always built asprofileCmd + --force-refresh.getToken()tries commands in order (forceCmd->profileCmd->fallbackCmd), falling through on"unknown flag:"errors and logging the appropriate warning at each step.isUnknownFlagErrortakes a bare flag name (e.g."--profile") and prepends"unknown flag: "internally for matching.forceCmdnull.How is this tested?
Unit tests in
CliTokenSourceTest:testForceCmdSucceedsAndProfileCmdNotRun--forceCmdsucceeds, no further commands are tried.testForceCmdFailsWithUnknownForceRefreshFallsBackToProfileCmd--forceCmdfails with"unknown flag: --force-refresh", verifies fallback toprofileCmd.testForceCmdFailsWithUnknownProfileFallsThroughToFallbackCmd--forceCmdfails with"unknown flag: --profile"(very old CLI), verifies fallback cascades throughprofileCmdtofallbackCmd.testForceCmdRealAuthErrorDoesNotFallBack-- non-flag error fromforceCmdis returned immediately without fallback.testNullForceCmdPreservesExistingBehavior--forceCmdis null, existingprofileCmd->fallbackCmdchain is preserved.Unit tests in
DatabricksCliCredentialsProviderTest:testBuildProfileArgs-- verifies profile command construction.