-
Notifications
You must be signed in to change notification settings - Fork 147
Add databricks auth switch command for setting the default profile
#4651
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
base: main
Are you sure you want to change the base?
Changes from all commits
f30ebe8
e75348f
a7f5031
b2c5315
71b7c7d
1614826
ea4a9e0
3f72a7f
51c780a
b72f644
f78d6a4
bbb07d3
4129a82
95ae4c3
8e88cc2
4876b8b
75aa2dc
389921a
3d0ee11
55d8373
193ffc0
64a6473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| === Describe without --profile (should use default) | ||
|
|
||
| >>> [CLI] auth describe | ||
| Host: [DATABRICKS_URL] | ||
| User: [USERNAME] | ||
| Authenticated with: pat | ||
| ----- | ||
| Current configuration: | ||
| ✓ host: [DATABRICKS_URL] (from DATABRICKS_HOST environment variable) | ||
| ✓ token: ******** (from DATABRICKS_TOKEN environment variable) | ||
| ✓ profile: my-workspace | ||
| ✓ databricks_cli_path: [CLI] | ||
| ✓ auth_type: pat | ||
| ✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| sethome "./home" | ||
|
|
||
| # Create a config with two profiles and an explicit default. | ||
| cat > "./home/.databrickscfg" <<EOF | ||
| [DEFAULT] | ||
simonfaltum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [my-workspace] | ||
| host = $DATABRICKS_HOST | ||
| token = $DATABRICKS_TOKEN | ||
|
|
||
| [other-workspace] | ||
| host = https://other.cloud.databricks.com | ||
| token = other-token | ||
|
|
||
| [__settings__] | ||
| default_profile = my-workspace | ||
| EOF | ||
|
|
||
| title "Describe without --profile (should use default)\n" | ||
| trace $CLI auth describe | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Ignore = [ | ||
| "home" | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,6 @@ | |
| [test] | ||
| host = [DATABRICKS_URL] | ||
| auth_type = databricks-cli | ||
|
|
||
| [__settings__] | ||
| default_profile = test | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| ; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified. | ||
| [DEFAULT] | ||
|
|
||
| [profile-a] | ||
| host = https://profile-a.cloud.databricks.com | ||
| token = token-a | ||
| auth_type = pat | ||
|
|
||
| [profile-b] | ||
| host = https://profile-b.cloud.databricks.com | ||
| token = token-b | ||
| auth_type = pat | ||
|
|
||
| [__settings__] | ||
| default_profile = profile-b |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
|
|
||
| === Initial config | ||
| ; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified. | ||
| [DEFAULT] | ||
|
|
||
| [profile-a] | ||
| host = https://profile-a.cloud.databricks.com | ||
| token = token-a | ||
| auth_type = pat | ||
|
|
||
| [profile-b] | ||
| host = https://profile-b.cloud.databricks.com | ||
| token = token-b | ||
| auth_type = pat | ||
|
|
||
| === Switch to profile-a | ||
|
|
||
| >>> [CLI] auth switch --profile profile-a | ||
| Default profile set to "profile-a". | ||
|
|
||
| === Settings after first switch | ||
| [__settings__] | ||
| default_profile = profile-a | ||
|
|
||
| === Profiles after first switch | ||
|
|
||
| >>> [CLI] auth profiles --skip-validate | ||
| Name Host Valid | ||
| profile-a (Default) https://profile-a.cloud.databricks.com NO | ||
| profile-b https://profile-b.cloud.databricks.com NO | ||
|
|
||
| === Switch to profile-b | ||
|
|
||
| >>> [CLI] auth switch --profile profile-b | ||
| Default profile set to "profile-b". | ||
|
|
||
| === Settings after second switch | ||
| [__settings__] | ||
| default_profile = profile-b | ||
|
|
||
| === Profiles after second switch | ||
|
|
||
| >>> [CLI] auth profiles --skip-validate | ||
| Name Host Valid | ||
| profile-a https://profile-a.cloud.databricks.com NO | ||
| profile-b (Default) https://profile-b.cloud.databricks.com NO |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| sethome "./home" | ||
|
|
||
| # Create two profiles without a [__settings__] section. | ||
| cat > "./home/.databrickscfg" <<'EOF' | ||
| ; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified. | ||
| [DEFAULT] | ||
|
|
||
| [profile-a] | ||
| host = https://profile-a.cloud.databricks.com | ||
| token = token-a | ||
| auth_type = pat | ||
|
|
||
| [profile-b] | ||
| host = https://profile-b.cloud.databricks.com | ||
| token = token-b | ||
| auth_type = pat | ||
| EOF | ||
|
|
||
| title "Initial config\n" | ||
| cat "./home/.databrickscfg" | ||
simonfaltum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| title "Switch to profile-a\n" | ||
| trace $CLI auth switch --profile profile-a | ||
|
|
||
| title "Settings after first switch\n" | ||
| cat "./home/.databrickscfg" | grep -A1 __settings__ | ||
|
|
||
| title "Profiles after first switch\n" | ||
| trace $CLI auth profiles --skip-validate | ||
|
|
||
| title "Switch to profile-b\n" | ||
| trace $CLI auth switch --profile profile-b | ||
|
|
||
| title "Settings after second switch\n" | ||
| cat "./home/.databrickscfg" | grep -A1 __settings__ | ||
|
|
||
| title "Profiles after second switch\n" | ||
| trace $CLI auth profiles --skip-validate | ||
|
|
||
| # Track the final .databrickscfg to surface changes. | ||
| cp "./home/.databrickscfg" "./out.databrickscfg" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Ignore = [ | ||
| "home" | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,13 +177,15 @@ func getAuthDetails(cmd *cobra.Command, cfg *config.Config, showSensitive bool) | |
| } | ||
| } | ||
|
|
||
| // If profile is not set explicitly, default to "default" | ||
| // If profile is not set explicitly, show which profile is being used. | ||
| // When a default_profile is configured, MustWorkspaceClient/MustAccountClient | ||
| // resolves it before we get here, so cfg.Profile is already set. | ||
| if _, ok := details.Configuration["profile"]; !ok { | ||
| profile := cfg.Profile | ||
| if profile == "" { | ||
| profile = "default" | ||
| displayProfile := cfg.Profile | ||
| if displayProfile == "" { | ||
| displayProfile = "default" | ||
| } | ||
| details.Configuration["profile"] = &config.AttrConfig{Value: profile, Source: config.Source{Type: config.SourceDynamicConfig}} | ||
| details.Configuration["profile"] = &config.AttrConfig{Value: displayProfile, Source: config.Source{Type: config.SourceDynamicConfig}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this code path in use at all? If the default profile is resolved earlier in the chain,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this diff no longer changes anything. |
||
| } | ||
|
|
||
| // Unset source for databricks_cli_path because it can't be overridden anyway | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,9 @@ depends on the existing profiles you have set in your configuration file | |
| } | ||
|
|
||
| if profileName != "" { | ||
| configFile := env.Get(ctx, "DATABRICKS_CONFIG_FILE") | ||
| isFirst := databrickscfg.IsFirstProfile(ctx, configFile) | ||
|
|
||
| err := databrickscfg.SaveToProfile(ctx, &config.Config{ | ||
| Profile: profileName, | ||
| Host: authArguments.Host, | ||
|
|
@@ -248,14 +251,17 @@ depends on the existing profiles you have set in your configuration file | |
| WorkspaceID: authArguments.WorkspaceID, | ||
| Experimental_IsUnifiedHost: authArguments.IsUnifiedHost, | ||
| ClusterID: clusterID, | ||
| ConfigFile: env.Get(ctx, "DATABRICKS_CONFIG_FILE"), | ||
| ConfigFile: configFile, | ||
| ServerlessComputeID: serverlessComputeID, | ||
| Scopes: scopesList, | ||
| }, clearKeys...) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if isFirst { | ||
| databrickscfg.SetDefaultProfileQuietly(ctx, profileName, configFile) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: could this be implicit in SaveToProfile now? Moving this to these helpers made this more apparent. |
||
| cmdio.LogString(ctx, fmt.Sprintf("Profile %s was successfully saved", profileName)) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.