Skip to content

Commit c968abd

Browse files
Detect Databricks CLI version to gate --profile support
`--profile` on `databricks auth token` is a global Cobra flag, so old CLIs (< v0.207.1) silently accept it and fail later with `cannot fetch credentials` instead of `unknown flag: --profile`. The previous error-based fallback never matched, leaving the `--host` fallback as dead code. This commit replaces the runtime fallback chain with version-based capability detection: * `CliVersion` carries a (major, minor, patch) triple plus an `UNKNOWN` sentinel and a default-dev-build (0,0,0) check. * `DatabricksCliCredentialsProvider` runs `databricks version --output json` once per CLI path (cached on success only, with a 5s timeout) and gates `--profile` on >= v0.207.1; everything else falls back to `--host` with a precise warning. * `CliTokenSource` is simplified to a single `cmd`; the `fallbackCmd` parameter and the runtime "unknown flag" retry loop are removed. Mirrors the equivalent refactors in the Go and Python SDKs: * databricks/databricks-sdk-go#1605 * databricks/databricks-sdk-py#1377 Co-authored-by: Isaac
1 parent f850f56 commit c968abd

7 files changed

Lines changed: 893 additions & 225 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
### Breaking Changes
88

99
### Bug Fixes
10+
* Fixed Databricks CLI `--profile` fallback by detecting the CLI version at init time. The previous error-based detection was broken because `--profile` is a global Cobra flag silently accepted by old CLIs.
1011

1112
### Security Vulnerabilities
1213

1314
### Documentation
1415

1516
### Internal Changes
17+
* Detect Databricks CLI version at init time via `databricks version --output json`, enabling version-gated flag support. Successful detections are cached per CLI path; subprocess failures fall back to the most conservative command and are retried on the next call.
1618

1719
### API Changes

databricks-sdk-java/src/main/java/com/databricks/sdk/core/CliTokenSource.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public class CliTokenSource implements TokenSource {
3030
private String accessTokenField;
3131
private String expiryField;
3232
private Environment env;
33-
// fallbackCmd is tried when the primary command fails with "unknown flag: --profile",
34-
// indicating the CLI is too old to support --profile. Can be removed once support
35-
// for CLI versions predating --profile is dropped.
36-
// See: https://github.com/databricks/databricks-sdk-go/pull/1497
37-
private List<String> fallbackCmd;
3833

3934
/**
4035
* Internal exception that carries the clean stderr message but exposes full output for checks.
@@ -58,24 +53,11 @@ public CliTokenSource(
5853
String accessTokenField,
5954
String expiryField,
6055
Environment env) {
61-
this(cmd, tokenTypeField, accessTokenField, expiryField, env, null);
62-
}
63-
64-
public CliTokenSource(
65-
List<String> cmd,
66-
String tokenTypeField,
67-
String accessTokenField,
68-
String expiryField,
69-
Environment env,
70-
List<String> fallbackCmd) {
71-
super();
7256
this.cmd = OSUtils.get(env).getCliExecutableCommand(cmd);
7357
this.tokenTypeField = tokenTypeField;
7458
this.accessTokenField = accessTokenField;
7559
this.expiryField = expiryField;
7660
this.env = env;
77-
this.fallbackCmd =
78-
fallbackCmd != null ? OSUtils.get(env).getCliExecutableCommand(fallbackCmd) : null;
7961
}
8062

8163
/**
@@ -158,22 +140,6 @@ public Token getToken() {
158140
try {
159141
return execCliCommand(this.cmd);
160142
} catch (IOException e) {
161-
String textToCheck =
162-
e instanceof CliCommandException
163-
? ((CliCommandException) e).getFullOutput()
164-
: e.getMessage();
165-
if (fallbackCmd != null
166-
&& textToCheck != null
167-
&& textToCheck.contains("unknown flag: --profile")) {
168-
LOG.warn(
169-
"Databricks CLI does not support --profile flag. Falling back to --host. "
170-
+ "Please upgrade your CLI to the latest version.");
171-
try {
172-
return execCliCommand(this.fallbackCmd);
173-
} catch (IOException fallbackException) {
174-
throw new DatabricksException(fallbackException.getMessage(), fallbackException);
175-
}
176-
}
177143
throw new DatabricksException(e.getMessage(), e);
178144
}
179145
}

0 commit comments

Comments
 (0)