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: config/cli_token_source.go
+64-49Lines changed: 64 additions & 49 deletions
Original file line number
Diff line number
Diff line change
@@ -31,50 +31,78 @@ type cliTokenResponse struct {
31
31
Expirystring`json:"expiry"`
32
32
}
33
33
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
34
+
// cliFeatureFlag defines a CLI feature flag and the warning to log when
35
+
// falling back because the CLI does not support it. Ordered newest-first:
36
+
// commands are built by progressively stripping these flags for older CLIs.
37
+
typecliFeatureFlagstruct {
38
+
flagstring
39
+
warningMessagestring
40
+
}
41
+
42
+
varcliFeatureFlags= []cliFeatureFlag{
43
+
{"--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."},
44
+
}
41
45
42
-
// profileCmd uses --profile for token lookup. Nil when cfg.Profile is empty.
43
-
profileCmd []string
46
+
constprofileFlagWarning="Databricks CLI does not support --profile flag. Falling back to --host. Please upgrade your CLI to the latest version."
44
47
45
-
// hostCmd uses --host as a fallback for CLIs that predate --profile support.
46
-
// Nil when cfg.Host is empty.
47
-
hostCmd []string
48
+
// cliCommand is a single CLI invocation with an associated warning message
49
+
// that is logged when this command fails and we fall back to the next one.
50
+
typecliCommandstruct {
51
+
args []string
52
+
warningMessagestring
53
+
}
54
+
55
+
// CliTokenSource fetches OAuth tokens by shelling out to the Databricks CLI.
56
+
// It holds a list of commands ordered from most feature-rich to simplest,
57
+
// 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.")
130
+
logger.Warnf(ctx, cmd.warningMessage)
100
131
}
101
-
102
-
ifc.profileCmd!=nil {
103
-
tok, err:=c.execCliCommand(ctx, c.profileCmd)
104
-
iferr==nil {
105
-
returntok, nil
106
-
}
107
-
if!isUnknownFlagError(err, "--profile") {
108
-
returnnil, err
109
-
}
110
-
logger.Warnf(ctx, "Databricks CLI does not support --profile flag. Falling back to --host. Please upgrade your CLI to the latest version.")
0 commit comments