You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generalize CLI token source into progressive command list
Replace the three explicit command fields (forceCmd, profileCmd, hostCmd)
with a []cliCommand list and an activeCommandIndex. Feature flags are
defined statically in cliFeatureFlags and stripped progressively to
build commands for older CLI versions.
Token() now iterates from activeCommandIndex, falling back on unknown
flag errors and caching the working command index for subsequent calls.
Adding future flags (e.g. --scopes) requires only a one-line addition
to the cliFeatureFlags slice.
Signed-off-by: Mihai Mitrea <mihai.mitrea@databricks.com>
Copy file name to clipboardExpand all lines: NEXT_CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@
22
22
23
23
### Internal Changes
24
24
25
+
* Generalize CLI token source into a progressive command list for forward-compatible flag support.
25
26
* Normalize internal token sources on `auth.TokenSource` for proper context propagation ([#1577](https://github.com/databricks/databricks-sdk-go/pull/1577)).
26
27
* Fix `TestAzureGithubOIDCCredentials` hang caused by missing `HTTPTransport` stub: `EnsureResolved` now calls `resolveHostMetadata`, which makes a real network request when no transport is set ([#1550](https://github.com/databricks/databricks-sdk-go/pull/1550)).
27
28
* Bump golang.org/x/crypto from 0.21.0 to 0.45.0 in /examples/slog ([#1566](https://github.com/databricks/databricks-sdk-go/pull/1566)).
Copy file name to clipboardExpand all lines: config/cli_token_source.go
+66-49Lines changed: 66 additions & 49 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ import (
10
10
"path/filepath"
11
11
"runtime"
12
12
"strings"
13
+
"sync/atomic"
13
14
"time"
14
15
15
16
"github.com/databricks/databricks-sdk-go/logger"
@@ -31,50 +32,78 @@ type cliTokenResponse struct {
31
32
Expirystring`json:"expiry"`
32
33
}
33
34
34
-
// CliTokenSource fetches OAuth tokens by shelling out to the Databricks CLI.
35
-
// Commands are tried in order: forceCmd -> profileCmd -> hostCmd, progressively
36
-
// falling back to simpler invocations for older CLI versions.
37
-
typeCliTokenSourcestruct {
38
-
// forceCmd uses --profile with --force-refresh to bypass the CLI's token cache.
39
-
// Nil when cfg.Profile is empty (--force-refresh requires --profile support).
40
-
forceCmd []string
35
+
// cliFeatureFlag defines a CLI feature flag and the warning to log when
36
+
// falling back because the CLI does not support it. Ordered newest-first:
37
+
// commands are built by progressively stripping these flags for older CLIs.
38
+
typecliFeatureFlagstruct {
39
+
flagstring
40
+
warningMessagestring
41
+
}
42
+
43
+
varcliFeatureFlags= []cliFeatureFlag{
44
+
{"--force-refresh", "Databricks CLI does not support --force-refresh flag. The CLI's token cache may provide stale tokens. Please upgrade your CLI to the latest version."},
45
+
}
41
46
42
-
// profileCmd uses --profile for token lookup. Nil when cfg.Profile is empty.
43
-
profileCmd []string
47
+
constprofileFlagWarning="Databricks CLI does not support --profile flag. Falling back to --host. Please upgrade your CLI to the latest version."
44
48
45
-
// hostCmd uses --host as a fallback for CLIs that predate --profile support.
46
-
// Nil when cfg.Host is empty.
47
-
hostCmd []string
49
+
// cliCommand is a single CLI invocation with an associated warning message
50
+
// that is logged when this command fails and we fall back to the next one.
51
+
typecliCommandstruct {
52
+
args []string
53
+
warningMessagestring
54
+
}
55
+
56
+
// CliTokenSource fetches OAuth tokens by shelling out to the Databricks CLI.
57
+
// It holds a list of commands ordered from most feature-rich to simplest,
58
+
// falling back progressively for older CLI versions that lack newer flags.
logger.Warnf(ctx, "Databricks CLI does not support --force-refresh flag. The CLI's token cache may provide stale tokens. Please upgrade your CLI to the latest version.")
0 commit comments