Skip to content

Pass --profile to CLI token source#682

Open
hectorcast-db wants to merge 5 commits intomainfrom
hectorcast-db/profile-in-token
Open

Pass --profile to CLI token source#682
hectorcast-db wants to merge 5 commits intomainfrom
hectorcast-db/profile-in-token

Conversation

@hectorcast-db
Copy link
Contributor

@hectorcast-db hectorcast-db commented Feb 26, 2026

Why

Today `databricks auth token --profile ` fails to find a valid token even when one exists — because the token was stored under the host URL key (via `--host`), not the profile name key. The SDK's `DatabricksCliCredentialsProvider` always passed `--host` regardless of whether a profile was configured, so the CLI never had a chance to do profile-based lookup.

This is a port of databricks-sdk-py#1297 / databricks-sdk-go#1497.

Changes

`CliTokenSource`

  • Added `fallbackCmd` optional field: a fallback command for CLIs too old to support `--profile`.
  • Added inner `CliCommandException extends IOException`: its `getMessage()` returns the clean stderr-based message (what users see), while `getFullOutput()` exposes the combined stdout+stderr for flag detection — avoiding verbose combined output in user-facing errors.
  • Extracted `execCliCommand()` helper to run a single CLI invocation.
  • Updated `getToken()` to try the primary command first; if it fails with `"unknown flag: --profile"` (checked in full output across both streams), retries with `fallbackCmd` and emits a warning to upgrade the CLI.

`DatabricksCliCredentialsProvider`

  • Renamed `buildCliCommand` → `buildHostArgs` (reflects its role as the `--host` legacy path).
  • When `cfg.profile` is set: uses `--profile ` as the primary command. If `cfg.host` is also present, builds a `--host` fallback via `buildHostArgs()` for compatibility with older CLIs.
  • When `cfg.profile` is empty: unchanged — existing `--host` path is used.

Test plan

  • `--profile` fails with `"unknown flag: --profile"` in stderr → retries with `--host`, succeeds
  • `--profile` fails with `"unknown flag: --profile"` in stdout → fallback still triggered
  • `--profile` fails with real auth error → no retry, error propagated
  • `fallbackCmd` is `null` and `--profile` fails → original error raised
  • All existing `buildHostArgs` tests (workspace, account, unified host variants) pass

🤖 Generated with Claude Code

…CLIs

Port of databricks-sdk-py#1297 / databricks-sdk-go#1497.

- CliTokenSource: add optional fallbackCmd; extract execCliCommand(); on IOError
  check full stdout+stderr for "unknown flag: --profile" via CliCommandException
  (clean stderr message exposed to users, full output used only for detection);
  if matched, warn and retry with fallbackCmd.
- DatabricksCliCredentialsProvider: rename buildCliCommand -> buildHostArgs;
  when cfg.profile is set use --profile as primary command, build --host fallback
  if cfg.host is also present; when profile is absent keep existing --host path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@hectorcast-db hectorcast-db changed the title wip Pass --profile to CLI token source Feb 26, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Trimming stderr changed the exception message format, breaking an existing
test that expected the raw stderr (including trailing newline) to be
propagated through the error chain.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-java

Inputs:

  • PR number: 682
  • Commit SHA: a56fa6cab7bb064921e91701c94eca7982231186

Checks will be approved automatically on success.

Copy link
Member

@simonfaltum simonfaltum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks solid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants