Commit f26ecce
authored
Pass --force-refresh to CLI auth token command (databricks#752)
## 🥞 Stacked PR
Use this
[link](https://github.com/databricks/databricks-sdk-java/pull/752/files)
to review incremental changes.
-
[stack/cli-force-refresh](databricks#751)
[[Files
changed](https://github.com/databricks/databricks-sdk-java/pull/751/files)]
-
[**stack/cli-attempt-chain**](databricks#752)
[[Files
changed](https://github.com/databricks/databricks-sdk-java/pull/752/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)
and
[databricks/databricks-sdk-py#1378](databricks/databricks-sdk-py#1378).
Requires the version-detection infrastructure from the parent PR
[databricks#751](databricks#751).
## Why
The SDK already manages its own token caching via `CachedTokenSource`.
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."`
`AzureCliCredentialsProvider` is unaffected — it does not pass through
`DatabricksCliCredentialsProvider` and does not opt into version-gated
flag selection.
### Internal changes
- New constant
`DatabricksCliCredentialsProvider.CLI_VERSION_FOR_FORCE_REFRESH = new
DatabricksCliVersion(0, 296, 0)`.
- `buildCliCommand` is split into two helpers, matching the shape the Go
and Python SDKs settled on after the same PR there:
- **`buildCoreCliCommand(cliPath, config, version)`** — holds the
existing profile-vs-host decision (moved out of `buildCliCommand`).
- **`buildCliCommand(cliPath, config, version)`** — now a thin wrapper
that calls `buildCoreCliCommand`, appends `--force-refresh` when
`version.atLeast(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.atLeast(...)` block
in `buildCliCommand`.
## How is this tested?
Additional `testBuildCliCommand` parameterized cases in
`DatabricksCliCredentialsProviderTest` cover 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`).
- `--host` + v0.295.0 → `--host` only (too old for `--force-refresh`).
- unknown version (detection failure) → `--host` only, no
`--force-refresh`.
- dev build → `--host` only, no `--force-refresh`.
All parent-PR tests continue to pass unchanged.1 parent 20d0239 commit f26ecce
3 files changed
Lines changed: 82 additions & 25 deletions
File tree
- databricks-sdk-java/src
- main/java/com/databricks/sdk/core
- test/java/com/databricks/sdk/core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
Lines changed: 48 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| |||
161 | 165 | | |
162 | 166 | | |
163 | 167 | | |
164 | | - | |
| 168 | + | |
165 | 169 | | |
166 | | - | |
167 | | - | |
| 170 | + | |
| 171 | + | |
168 | 172 | | |
169 | 173 | | |
170 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
171 | 203 | | |
172 | 204 | | |
173 | 205 | | |
| |||
176 | 208 | | |
177 | 209 | | |
178 | 210 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 211 | + | |
187 | 212 | | |
188 | 213 | | |
189 | 214 | | |
| |||
254 | 279 | | |
255 | 280 | | |
256 | 281 | | |
257 | | - | |
258 | | - | |
| 282 | + | |
| 283 | + | |
259 | 284 | | |
260 | 285 | | |
261 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
262 | 297 | | |
263 | 298 | | |
264 | 299 | | |
| |||
Lines changed: 33 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
115 | | - | |
| 114 | + | |
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
120 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
125 | 129 | | |
126 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
127 | 144 | | |
128 | 145 | | |
129 | 146 | | |
130 | 147 | | |
131 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
132 | 154 | | |
133 | 155 | | |
134 | 156 | | |
135 | 157 | | |
136 | | - | |
| 158 | + | |
137 | 159 | | |
138 | 160 | | |
139 | 161 | | |
140 | 162 | | |
141 | | - | |
| 163 | + | |
142 | 164 | | |
143 | 165 | | |
144 | 166 | | |
| |||
366 | 388 | | |
367 | 389 | | |
368 | 390 | | |
369 | | - | |
370 | 391 | | |
371 | 392 | | |
372 | 393 | | |
| |||
398 | 419 | | |
399 | 420 | | |
400 | 421 | | |
401 | | - | |
| 422 | + | |
402 | 423 | | |
403 | 424 | | |
404 | 425 | | |
| |||
427 | 448 | | |
428 | 449 | | |
429 | 450 | | |
430 | | - | |
| 451 | + | |
431 | 452 | | |
432 | 453 | | |
433 | 454 | | |
| |||
451 | 472 | | |
452 | 473 | | |
453 | 474 | | |
454 | | - | |
| 475 | + | |
455 | 476 | | |
456 | 477 | | |
457 | 478 | | |
| |||
0 commit comments