Repository navigation
Commit 52e36a3
authored
Pass --force-refresh to CLI auth token command (databricks#1628)
## Summary
Pass `--force-refresh` to the Databricks CLI `auth token` command when
the CLI supports it (>= v0.296.0), bypassing the CLI's internal token
cache.
## Why
The SDK 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 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 added a `--force-refresh` flag
([databricks/cli#4767](databricks/cli#4767),
motivated by
[databricks/cli#4564](databricks/cli#4564))
that bypasses its internal cache. By using this flag, the SDK is
guaranteed a freshly minted token every time it asks for one.
With the version detection infrastructure from the parent PR (databricks#1605),
adding `--force-refresh` is a one-constant, one-`if` change.
## What changed
### Interface changes
None. `CliTokenSource` is not part of the public API surface.
### Behavioral changes
- The SDK now appends `--force-refresh` when invoking `databricks auth
token` if the CLI version is >= v0.296.0.
- A warning is logged when the CLI is too old for `--force-refresh`:
`"Databricks CLI v%s does not support --force-refresh (requires >= v%s).
The CLI's token cache may provide stale tokens."`
### Internal changes
- **`cliVersionForForceRefresh`**: new version constant `{0, 296, 0}`.
- **`buildCliCommand`**: adds a nil guard and appends `--force-refresh`
after the base command is resolved.
## How is this tested?
Additional test cases in `TestBuildCliCommand`:
- host + v0.296.0 → appends `--force-refresh`
- host + v0.200.0 → no `--force-refresh`
- account host + v0.296.0 → appends `--force-refresh`
- profile + v0.296.0 → `--profile` + `--force-refresh`
- profile + v0.207.1 → `--profile` only (no `--force-refresh`)
- profile-only + v0.296.0 → `--profile` + `--force-refresh`
- zero version → `--host` only, no `--force-refresh`
Signed-off-by: Mihai Mitrea <[email protected]>1 parent 1d7243d commit 52e36a3
3 files changed
Lines changed: 59 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
| |||
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
119 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
120 | 142 | | |
121 | 143 | | |
122 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
220 | 232 | | |
221 | 233 | | |
222 | 234 | | |
| |||
232 | 244 | | |
233 | 245 | | |
234 | 246 | | |
235 | | - | |
| 247 | + | |
236 | 248 | | |
237 | 249 | | |
238 | 250 | | |
239 | 251 | | |
240 | 252 | | |
241 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
242 | 260 | | |
243 | 261 | | |
244 | 262 | | |
| |||
256 | 274 | | |
257 | 275 | | |
258 | 276 | | |
259 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
260 | 284 | | |
261 | 285 | | |
262 | 286 | | |
263 | 287 | | |
264 | 288 | | |
265 | 289 | | |
266 | 290 | | |
267 | | - | |
| 291 | + | |
268 | 292 | | |
269 | 293 | | |
270 | 294 | | |
| |||
0 commit comments