Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not load host from bundle for CLI commands when profile flag is used #2335

Merged
merged 5 commits into from
Feb 26, 2025

Conversation

andrewnester
Copy link
Contributor

@andrewnester andrewnester commented Feb 11, 2025

Changes

Now when profile flag is used we won't pick up host from bundle anymore and use the one provided by -p flag

Previous behaviour in the context of bundle

databricks current-user me -p profile_name
Error: cannot resolve bundle auth configuration: config host mismatch: profile uses host https://non-existing-subdomain.databricks.com, but CLI configured to use https://foo.com

New behaviour (make an api call)

databricks current-user me -p profile_name
{
  email: "[email protected]"
  ...
}

We still load bundle configuration when -t flag provide because we want to load host information from the target.

Fixes #1358

Tests

Added acceptance test

@andrewnester andrewnester force-pushed the feature/use-profile-flag-in-bundle branch from 38e7d9c to f08770a Compare February 25, 2025 11:36
@@ -15,7 +15,7 @@ trace errcode $CLI current-user me -t dev | jq .userName
title "Inside the bundle, target and matching profile"
trace errcode $CLI current-user me -t dev -p DEFAULT | jq .userName

title "Inside the bundle, profile flag not matching bundle host. Badness: should use profile from flag instead and not fail"
title "Inside the bundle, profile flag not matching bundle host. Should use profile from the flag and not the bundle."
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd replace "Should use profile from the flag" with 'Prefers profile passed via "-p profile_name" over the one specified by bundle host'.

@@ -195,6 +195,12 @@ func MustWorkspaceClient(cmd *cobra.Command, args []string) error {
cfg.Profile = profile
}

_, isTargetFlagSet := targetFlagValue(cmd)
if !isTargetFlagSet && hasProfileFlag {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if both -p and -t are set? Should that result in an error? or is it a valid use case as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a valid use case, for example, you want to make a CLI call to -t dev but it requires some different profile so you need to provide -p flag. If the hosts mismatch in such cases it will correct fail

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's a valid case, should the condition be

if hasProfileFlag {?

so if -p is provided, then we always use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we use this condition we will skip bundle configuration always, even when -t is provided. But we don't want to skip it when -t is provided

return target
}

func targetFlagValue(cmd *cobra.Command) (string, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the motivation for ignoring env var but taking command line option into account?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean not having the same behaviour like with flag set?
The motivation that is the usage intention is different. You're likely to set DATABRICKS_CONFIG_PROFILE env for all the commands you use, like databricks bundle deploy and databricks clusters list equally.
While providing a flag to command is an explicit way to want it to be executed against different profile.

@andrewnester andrewnester requested a review from denik February 25, 2025 12:39
@@ -195,6 +195,12 @@ func MustWorkspaceClient(cmd *cobra.Command, args []string) error {
cfg.Profile = profile
}

_, isTargetFlagSet := targetFlagValue(cmd)
if !isTargetFlagSet && hasProfileFlag {
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's a valid case, should the condition be

if hasProfileFlag {?

so if -p is provided, then we always use that.

@andrewnester andrewnester added this pull request to the merge queue Feb 26, 2025
Merged via the queue into main with commit df001dc Feb 26, 2025
9 checks passed
@andrewnester andrewnester deleted the feature/use-profile-flag-in-bundle branch February 26, 2025 12:36
andrewnester added a commit that referenced this pull request Feb 27, 2025
Notable changes:
Starting this version CLI does not load bundle auth information when CLI command is executed inside the bundle directory with explicitly provided via `-p` flag profile.

CLI:
 * Do not load host from bundle for CLI commands when profile flag is used ([#2335](#2335)).
 * Fixed accessing required path parameters in CLI generation when --json flag ([#2373](#2373)).

Bundles:
 * Provide instructions for testing in the default-python template ([#2355](#2355)).
 * Remove `run_as` from the built-in templates ([#2044](#2044)).
 * Change warning about incomplete permissions section into a recommendation ([#2043](#2043)).
 * Refine `mode: production` diagnostic output ([#2236](#2236)).
 * Support serverless mode in default-python template (explicit prompt) ([#2377](#2377)).
 * Set default data_security_mode to "SINGLE_USER" in bundle templates ([#2372](#2372)).
 * Fixed spark version check for clusters defined in the same bundle ([#2374](#2374)).

API Changes:
 * Added `databricks genie get-message-query-result-by-attachment` command.

OpenAPI commit 99f644e72261ef5ecf8d74db20f4b7a1e09723cc (2025-02-11)
github-merge-queue bot pushed a commit that referenced this pull request Feb 27, 2025
Notable changes:
Starting this version CLI does not load bundle auth information when CLI
command is executed inside the bundle directory with explicitly provided
via `-p` flag profile. For more details see the related GitHub issue
#1358

CLI:
* Do not load host from bundle for CLI commands when profile flag is
used ([#2335](#2335)).
* Fixed accessing required path parameters in CLI generation when --json
flag ([#2373](#2373)).

Bundles:
* Provide instructions for testing in the default-python template
([#2355](#2355)).
* Remove `run_as` from the built-in templates
([#2044](#2044)).
* Change warning about incomplete permissions section into a
recommendation ([#2043](#2043)).
* Refine `mode: production` diagnostic output
([#2236](#2236)).
* Support serverless mode in default-python template (explicit prompt)
([#2377](#2377)).
* Set default data_security_mode to "SINGLE_USER" in bundle templates
([#2372](#2372)).
* Fixed spark version check for clusters defined in the same bundle
([#2374](#2374)).

API Changes:
* Added `databricks genie get-message-query-result-by-attachment`
command.

OpenAPI commit 99f644e72261ef5ecf8d74db20f4b7a1e09723cc (2025-02-11)
HariGS-DB pushed a commit to HariGS-DB/cli that referenced this pull request Feb 28, 2025
…ed (databricks#2335)

## Changes
Now when `profile` flag is used we won't pick up host from bundle
anymore and use the one provided by -p flag

Previous behaviour in the context of bundle
```
databricks current-user me -p profile_name
Error: cannot resolve bundle auth configuration: config host mismatch: profile uses host https://non-existing-subdomain.databricks.com, but CLI configured to use https://foo.com
```

New behaviour (make an api call)
```
databricks current-user me -p profile_name
{
  email: "[email protected]"
  ...
}
```

We still load bundle configuration when `-t` flag provide because we
want to load host information from the target.

Fixes databricks#1358 

## Tests
Added acceptance test
HariGS-DB pushed a commit to HariGS-DB/cli that referenced this pull request Feb 28, 2025
Notable changes:
Starting this version CLI does not load bundle auth information when CLI
command is executed inside the bundle directory with explicitly provided
via `-p` flag profile. For more details see the related GitHub issue
databricks#1358

CLI:
* Do not load host from bundle for CLI commands when profile flag is
used ([databricks#2335](databricks#2335)).
* Fixed accessing required path parameters in CLI generation when --json
flag ([databricks#2373](databricks#2373)).

Bundles:
* Provide instructions for testing in the default-python template
([databricks#2355](databricks#2355)).
* Remove `run_as` from the built-in templates
([databricks#2044](databricks#2044)).
* Change warning about incomplete permissions section into a
recommendation ([databricks#2043](databricks#2043)).
* Refine `mode: production` diagnostic output
([databricks#2236](databricks#2236)).
* Support serverless mode in default-python template (explicit prompt)
([databricks#2377](databricks#2377)).
* Set default data_security_mode to "SINGLE_USER" in bundle templates
([databricks#2372](databricks#2372)).
* Fixed spark version check for clusters defined in the same bundle
([databricks#2374](databricks#2374)).

API Changes:
* Added `databricks genie get-message-query-result-by-attachment`
command.

OpenAPI commit 99f644e72261ef5ecf8d74db20f4b7a1e09723cc (2025-02-11)
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.

cli commands unexpectedly inferring host from bundle
3 participants