-
Notifications
You must be signed in to change notification settings - Fork 36
Add support for default_profile in [__settings__] section #698
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
Open
simonfaltum
wants to merge
12
commits into
main
Choose a base branch
from
default-profile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
39ecf38
Add support for default_profile in [__settings__] section
simonfaltum be0e584
Reject __settings__ as a reserved profile target
simonfaltum 5c59dec
Fix spotless formatting and add NEXT_CHANGELOG entry
simonfaltum c417dc7
Extract resolveProfile to simplify loadFromConfig
simonfaltum d029dd2
Fix spotless formatting for resolveProfile signature
simonfaltum 6f4d13c
Merge branch 'main' into default-profile
simonfaltum a55e191
Replace String[] with ResolvedProfile inner class
simonfaltum 3595fae
Merge remote-tracking branch 'origin/main' into default-profile
simonfaltum 694b7c4
Merge remote-tracking branch 'origin/main' into default-profile
simonfaltum 5be1ea0
Regenerate maven lockfile after merge from main
simonfaltum c200b12
Route CI Maven resolution through Databricks proxy
simonfaltum c7a88dc
Revert "Route CI Maven resolution through Databricks proxy"
simonfaltum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
databricks-sdk-java/src/test/java/com/databricks/sdk/DefaultProfileTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| package com.databricks.sdk; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import com.databricks.sdk.core.ConfigResolving; | ||
| import com.databricks.sdk.core.DatabricksConfig; | ||
| import com.databricks.sdk.core.DatabricksException; | ||
| import com.databricks.sdk.core.http.HttpClient; | ||
| import com.databricks.sdk.core.utils.TestOSUtils; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class DefaultProfileTest implements ConfigResolving { | ||
|
|
||
| private DatabricksConfig createConfigWithMockClient() { | ||
| HttpClient mockClient = mock(HttpClient.class); | ||
| return new DatabricksConfig().setHttpClient(mockClient); | ||
| } | ||
|
|
||
| /** Test 1: default_profile resolves correctly and is written back to config */ | ||
| @Test | ||
| public void testDefaultProfileResolvesCorrectly() { | ||
| StaticEnv env = new StaticEnv().with("HOME", TestOSUtils.resource("/testdata/default_profile")); | ||
| DatabricksConfig config = createConfigWithMockClient(); | ||
| resolveConfig(config, env); | ||
| config.authenticate(); | ||
|
|
||
| assertEquals("pat", config.getAuthType()); | ||
| assertEquals("https://my-workspace.cloud.databricks.com", config.getHost()); | ||
| assertEquals("my-workspace", config.getProfile()); | ||
| } | ||
|
|
||
| /** Test 2: default_profile takes precedence over [DEFAULT] */ | ||
| @Test | ||
| public void testDefaultProfileTakesPrecedenceOverDefault() { | ||
| StaticEnv env = | ||
| new StaticEnv().with("HOME", TestOSUtils.resource("/testdata/default_profile_precedence")); | ||
| DatabricksConfig config = createConfigWithMockClient(); | ||
| resolveConfig(config, env); | ||
| config.authenticate(); | ||
|
|
||
| assertEquals("pat", config.getAuthType()); | ||
| assertEquals("https://my-workspace.cloud.databricks.com", config.getHost()); | ||
| } | ||
|
|
||
| /** Test 3: Legacy fallback when no [__settings__] */ | ||
| @Test | ||
| public void testLegacyFallbackWhenNoSettings() { | ||
| StaticEnv env = new StaticEnv().with("HOME", TestOSUtils.resource("/testdata")); | ||
| DatabricksConfig config = createConfigWithMockClient(); | ||
| resolveConfig(config, env); | ||
| config.authenticate(); | ||
|
|
||
| assertEquals("pat", config.getAuthType()); | ||
| assertEquals("https://dbc-XXXXXXXX-YYYY.cloud.databricks.com", config.getHost()); | ||
| } | ||
|
|
||
| /** Test 4: Legacy fallback when default_profile is empty */ | ||
| @Test | ||
| public void testLegacyFallbackWhenDefaultProfileEmpty() { | ||
| StaticEnv env = | ||
| new StaticEnv() | ||
| .with("HOME", TestOSUtils.resource("/testdata/default_profile_empty_settings")); | ||
| DatabricksConfig config = createConfigWithMockClient(); | ||
| resolveConfig(config, env); | ||
| config.authenticate(); | ||
|
|
||
| assertEquals("pat", config.getAuthType()); | ||
| assertEquals("https://default.cloud.databricks.com", config.getHost()); | ||
| } | ||
|
|
||
| /** Test 5: default_profile = __settings__ is rejected */ | ||
| @Test | ||
| public void testSettingsSelfReferenceIsRejected() { | ||
| StaticEnv env = | ||
| new StaticEnv() | ||
| .with("HOME", TestOSUtils.resource("/testdata/default_profile_settings_self_ref")); | ||
| DatabricksConfig config = createConfigWithMockClient(); | ||
|
|
||
| DatabricksException ex = | ||
| assertThrows( | ||
| DatabricksException.class, | ||
| () -> { | ||
| resolveConfig(config, env); | ||
| config.authenticate(); | ||
| }); | ||
| assertTrue( | ||
| ex.getMessage().contains("reserved section name"), | ||
| "Error should reject __settings__ as a profile target: " + ex.getMessage()); | ||
| } | ||
|
|
||
| /** Test 6: Explicit --profile overrides default_profile */ | ||
| @Test | ||
| public void testExplicitProfileOverridesDefaultProfile() { | ||
| StaticEnv env = | ||
| new StaticEnv() | ||
| .with("DATABRICKS_CONFIG_PROFILE", "other") | ||
| .with("HOME", TestOSUtils.resource("/testdata/default_profile_explicit_override")); | ||
| DatabricksConfig config = createConfigWithMockClient(); | ||
| resolveConfig(config, env); | ||
| config.authenticate(); | ||
|
|
||
| assertEquals("pat", config.getAuthType()); | ||
| assertEquals("https://other.cloud.databricks.com", config.getHost()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExplicitSettingsSectionProfileIsRejected() { | ||
| StaticEnv env = | ||
| new StaticEnv() | ||
| .with("DATABRICKS_CONFIG_PROFILE", "__settings__") | ||
| .with("HOME", TestOSUtils.resource("/testdata/default_profile")); | ||
| DatabricksConfig config = createConfigWithMockClient(); | ||
|
|
||
| DatabricksException ex = | ||
| assertThrows( | ||
| DatabricksException.class, | ||
| () -> { | ||
| resolveConfig(config, env); | ||
| config.authenticate(); | ||
| }); | ||
| assertTrue( | ||
| ex.getMessage().contains("reserved section name"), | ||
| "Error should reject __settings__ as a profile target: " + ex.getMessage()); | ||
| } | ||
|
|
||
| /** Test 7: default_profile pointing to nonexistent section */ | ||
| @Test | ||
| public void testDefaultProfileNonexistentSection() { | ||
| StaticEnv env = | ||
| new StaticEnv().with("HOME", TestOSUtils.resource("/testdata/default_profile_nonexistent")); | ||
| DatabricksConfig config = createConfigWithMockClient(); | ||
|
|
||
| DatabricksException ex = | ||
| assertThrows( | ||
| DatabricksException.class, | ||
| () -> { | ||
| resolveConfig(config, env); | ||
| config.authenticate(); | ||
| }); | ||
| assertTrue( | ||
| ex.getMessage().contains("deleted-profile"), | ||
| "Error should mention the missing profile name: " + ex.getMessage()); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
databricks-sdk-java/src/test/resources/testdata/default_profile/.databrickscfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [__settings__] | ||
| default_profile = my-workspace | ||
|
|
||
| [my-workspace] | ||
| host = https://my-workspace.cloud.databricks.com | ||
| token = dapiXYZ |
5 changes: 5 additions & 0 deletions
5
...bricks-sdk-java/src/test/resources/testdata/default_profile_empty_settings/.databrickscfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [__settings__] | ||
|
|
||
| [DEFAULT] | ||
| host = https://default.cloud.databricks.com | ||
| token = dapiXYZ |
10 changes: 10 additions & 0 deletions
10
...cks-sdk-java/src/test/resources/testdata/default_profile_explicit_override/.databrickscfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [__settings__] | ||
| default_profile = my-workspace | ||
|
|
||
| [my-workspace] | ||
| host = https://my-workspace.cloud.databricks.com | ||
| token = dapiXYZ | ||
|
|
||
| [other] | ||
| host = https://other.cloud.databricks.com | ||
| token = dapiOTHER |
6 changes: 6 additions & 0 deletions
6
databricks-sdk-java/src/test/resources/testdata/default_profile_nonexistent/.databrickscfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [__settings__] | ||
| default_profile = deleted-profile | ||
|
|
||
| [my-workspace] | ||
| host = https://my-workspace.cloud.databricks.com | ||
| token = dapiXYZ |
10 changes: 10 additions & 0 deletions
10
databricks-sdk-java/src/test/resources/testdata/default_profile_precedence/.databrickscfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [__settings__] | ||
| default_profile = my-workspace | ||
|
|
||
| [DEFAULT] | ||
| host = https://default.cloud.databricks.com | ||
| token = dapiOLD | ||
|
|
||
| [my-workspace] | ||
| host = https://my-workspace.cloud.databricks.com | ||
| token = dapiXYZ |
6 changes: 6 additions & 0 deletions
6
...cks-sdk-java/src/test/resources/testdata/default_profile_settings_self_ref/.databrickscfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [__settings__] | ||
| default_profile = __settings__ | ||
|
|
||
| [DEFAULT] | ||
| host = https://default.cloud.databricks.com | ||
| token = dapiXYZ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.