Repository navigation
Commit e1ef265
authored
Pass --force-refresh to CLI auth token command (databricks#1378)
## 🥞 Stacked PR
Use this
[link](https://github.com/databricks/databricks-sdk-py/pull/1378/files)
to review incremental changes.
-
[stack/cli-force-refresh](databricks#1377)
[[Files
changed](https://github.com/databricks/databricks-sdk-py/pull/1377/files)]
[MERGED]
-
[**stack/cli-progressive-token-commands**](databricks#1378)
[[Files
changed](https://github.com/databricks/databricks-sdk-py/pull/1378/files)]
---------
## Summary
Append `--force-refresh` to the `databricks auth token` command when the
installed CLI is >= v0.296.0, so the CLI bypasses its internal token
cache and hands the SDK a freshly minted token every time.
Mirrors
[databricks/databricks-sdk-go#1628](databricks/databricks-sdk-go#1628).
Requires the version-detection infrastructure from the parent PR
[databricks#1377](databricks#1377).
## Why
The SDK already manages its own token caching via `oauth.Refreshable`.
When the SDK decides it needs a new token and shells out to `databricks
auth token`, the CLI may return a token from *its* own cache that is
about to expire (or that has already expired from the SDK's
perspective). That produces unnecessary refresh failures and retry loops
on top of a value that the SDK was confident was fresh.
The CLI added `--force-refresh` in
[databricks/cli#4767](databricks/cli#4767)
(motivated by
[databricks/cli#4564](databricks/cli#4564))
specifically to let callers bypass the CLI's cache. With the
version-detection infrastructure from the parent PR already in place,
opting in is a one-constant, one-branch change.
## What changed
### Interface changes
None. `CliTokenSource` is not part of the public API surface.
### Behavioral changes
- `databricks auth token` invocations now end with `--force-refresh`
whenever the detected CLI is >= v0.296.0. Callers on older CLIs see no
change.
- On older CLIs, a `WARNING` is logged: `"Databricks CLI <ver> does not
support --force-refresh (requires >= v0.296.0). The CLI's token cache
may provide stale tokens."`
`AzureCliTokenSource` is unaffected — it does not pass through
`DatabricksCliTokenSource` and does not opt into version-gated flag
selection.
### Internal changes
- New constant `DatabricksCliTokenSource._CLI_VERSION_FOR_FORCE_REFRESH
= CliVersion(0, 296, 0)`.
- `_build_cli_command` is split into two helpers, matching the shape the
Go SDK settled on after the same PR there:
- **`_build_core_cli_command(cli_path, cfg, version)`** — holds the
existing profile-vs-host decision (moved out of `_build_cli_command`).
- **`_build_cli_command(cli_path, cfg, version)`** — now a thin wrapper
that calls `_build_core_cli_command`, appends `--force-refresh` when
`version >= _CLI_VERSION_FOR_FORCE_REFRESH`, and otherwise logs the
unsupported-version `WARNING`.
Future version-gated flags slot into the same pattern: add a
`_CLI_VERSION_FOR_<flag>` constant and an `if version >= ...` block in
`_build_cli_command`.
## How is this tested?
Unit tests in `tests/test_credentials_provider.py`:
- Additional `test_build_cli_command` cases covering the full matrix:
- `--host` + v0.296.0 → appends `--force-refresh`.
- account `--host` + v0.296.0 → appends `--force-refresh`.
- `--profile` + v0.296.0 → `--profile` + `--force-refresh`.
- `--profile` + v0.207.1 → `--profile` only (too old for
`--force-refresh`).
- `--profile`-only + v0.296.0 → `--profile` + `--force-refresh` even
without a host.
- zero version (detection failure) → `--host` only, no
`--force-refresh`.
- `test_build_cli_command_force_refresh_unsupported_logs_warning` —
asserts the `WARNING` log is emitted when `version <
_CLI_VERSION_FOR_FORCE_REFRESH`.
All parent-PR tests continue to pass unchanged.1 parent 650b178 commit e1ef265
3 files changed
Lines changed: 136 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1012 | 1012 | | |
1013 | 1013 | | |
1014 | 1014 | | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
1015 | 1018 | | |
1016 | 1019 | | |
1017 | 1020 | | |
| |||
1101 | 1104 | | |
1102 | 1105 | | |
1103 | 1106 | | |
1104 | | - | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
1105 | 1135 | | |
1106 | 1136 | | |
1107 | 1137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
454 | 496 | | |
455 | 497 | | |
456 | 498 | | |
| |||
592 | 634 | | |
593 | 635 | | |
594 | 636 | | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
595 | 699 | | |
596 | 700 | | |
597 | 701 | | |
| |||
0 commit comments