Add text output mode for auth token and auth env#4725
Add text output mode for auth token and auth env#4725simonfaltum wants to merge 8 commits intomainfrom
Conversation
Both commands now respect --output text when explicitly set: - auth token --output text: outputs just the access token string - auth env --output text: outputs KEY=VALUE lines JSON remains the default for backward compatibility. Co-authored-by: Isaac
|
Commit: 23d833e
16 interesting tests: 7 SKIP, 6 RECOVERED, 3 flaky
Top 21 slowest tests (at least 2 minutes):
|
Co-authored-by: Isaac
shreyas-goenka
left a comment
There was a problem hiding this comment.
Note: This review was posted by Claude (AI assistant). Shreyas will do a separate, more thorough review pass.
Priority: MEDIUM — Env var inconsistency needs a decision
HIGH: DATABRICKS_OUTPUT_FORMAT env var silently ignored
Both auth token and auth env commands use cmd.Flag("output").Changed to detect text mode, which means the DATABRICKS_OUTPUT_FORMAT=text env var is ignored. This is inconsistent with the rest of the CLI where the env var is a first-class way to set output format. The guard exists because these commands have an inverted default (JSON by default, unlike other commands), so without it the default behavior would break. A decision is needed on whether the env var should be honored here.
MEDIUM: Shell quoting not fully .env-file compatible
The quoteEnvValue function uses POSIX shell single-quote escaping ('\''), but the PR description claims ".env loader" compatibility. Most .env parsers (Docker, python-dotenv) use different quoting rules. Only eval usage is truly compatible.
LOW: Doc comment typo
quoteEnvValue doc references '\" but code does '\''.
What looks good
- Backward compatibility preserved (JSON remains default)
collectEnvVarsextraction reduces duplication- Clean text output formatting
The comment referenced the '\" escape sequence, but the code actually uses the POSIX '\'' sequence (end-quote, backslash-escaped literal single quote, re-open quote).
…al characters Values containing \n or \r were emitted unquoted, producing raw multi-line shell output instead of a single safe KEY=VALUE pair. Add both characters to shellQuotedSpecialChars so they trigger single-quoting.
|
|
||
| // collectEnvVars returns the environment variables for the given config | ||
| // as a map from env var name to value. | ||
| func collectEnvVars(cfg *config.Config) map[string]string { |
There was a problem hiding this comment.
We have the auth.Env and auth.ProcessEnv functions. Worth looking into using those.
This command in general is pretty old and is also useless. It only returns the env corresponding to a profile. We should be able to make it more general i.e. return the env vars I need to set, to authenticate the same as the current CLI context.
I think a breaking change is pretty justified here (after double checking once with the usage numbers)
Why
databricks auth tokenanddatabricks auth envalways output JSON, ignoring the--outputflag. Users who want to pipe the token string or source env vars have to parse JSON first.Changes
Before: Both commands always output JSON regardless of the
--outputflag.Now: Both commands respect
--output textwhen explicitly set:auth token --output text: outputs just the access token string, suitable for pipingauth env --output text: outputs KEY=VALUE lines, compatible with .env loaders and evalJSON remains the default (backward compatible). Text mode activates only when the user explicitly passes
--output text.Test plan
make checkspasses