Commit 20d0239
authored
Fix CLI token source --profile fallback with version detection (#751)
## 🥞 Stacked PR
Use this
[link](https://github.com/databricks/databricks-sdk-java/pull/751/files)
to review incremental changes.
-
[**stack/cli-force-refresh**](#751)
[[Files
changed](https://github.com/databricks/databricks-sdk-java/pull/751/files)]
-
[stack/cli-attempt-chain](#752)
[[Files
changed](https://github.com/databricks/databricks-sdk-java/pull/752/files/c4e12c18..5ee21871)]
---------
## Summary
Replace the broken error-based `--profile` fallback in `CliTokenSource`
with version-based CLI detection at init time. Mirrors
[databricks/databricks-sdk-go#1605](databricks/databricks-sdk-go#1605)
and
[databricks/databricks-sdk-py#1377](databricks/databricks-sdk-py#1377).
## Why
`--profile` on `databricks auth token` is a global flag, so old CLIs (<
v0.207.1) **silently accept it** and then fail with `"cannot fetch
credentials"` instead of `"unknown flag: --profile"`. The existing retry
check was matching on the latter and never fired — the `--host` fallback
it gated was effectively dead code. Switching to `databricks version` +
a minimum-version constant makes the fallback reliable and sets up
future capability-gated flags (e.g. `--force-refresh` in
[#752](#752))
without additional subprocess calls.
## What changed
### Interface changes
None. `CliTokenSource` is not part of the public API surface.
### Behavioral changes
- `cfg.profile` + CLI < v0.207.1 now correctly falls back to `--host`
(previously broken).
- `databricks version` failures log a `WARNING` and fall back to the
most conservative command. Successful detections are cached per CLI
path; failures are not cached and will be retried on the next call.
- A default dev build (`v0.0.0-dev`) logs an `INFO` explaining why
feature gates are conservative.
`AzureCliCredentialsProvider` is untouched.
### Internal changes
- New `DatabricksCliVersion` class with a `(major, minor, patch)`
triple, an `UNKNOWN` sentinel, an `atLeast()` comparator, and an
`isDefaultDevBuild()` helper.
- `CliTokenSource` simplified to a single `cmd`; the `fallbackCmd`
parameter and its retry logic are removed.
- `DatabricksCliCredentialsProvider` gains `getCliVersion`,
`probeCliVersion`, `parseCliVersion`, `resolveCliCommand`, and
`buildCliCommand` helpers.
## How is this tested?
Unit tests in `DatabricksCliVersionTest` cover version comparison
(across patch/minor/major), the `UNKNOWN` sentinel, dev-build detection,
and `toString` formatting.
Unit tests in `DatabricksCliCredentialsProviderTest` cover JSON parsing
of `databricks version --output json` (standard, dev build, missing
fields, malformed JSON, empty string) and command assembly for every
profile/host/version combination (host-only, account host, profile + new
CLI, profile + old CLI, unknown version, dev build).
`CliTokenSourceTest` retains its parsing and timezone tests; the
obsolete fallback tests are dropped.1 parent 0a68591 commit 20d0239
7 files changed
Lines changed: 913 additions & 225 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 | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
Lines changed: 0 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 33 | | |
39 | 34 | | |
40 | 35 | | |
| |||
58 | 53 | | |
59 | 54 | | |
60 | 55 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | 56 | | |
73 | 57 | | |
74 | 58 | | |
75 | 59 | | |
76 | 60 | | |
77 | | - | |
78 | | - | |
79 | 61 | | |
80 | 62 | | |
81 | 63 | | |
| |||
158 | 140 | | |
159 | 141 | | |
160 | 142 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | 143 | | |
178 | 144 | | |
179 | 145 | | |
| |||
0 commit comments