Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions libs/databrickscfg/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ func GetConfiguredDefaultProfile(ctx context.Context, configFilePath string) (st
}

// GetConfiguredDefaultProfileFrom returns the explicit default profile from
// [__settings__].default_profile, or "" when it is not set.
// [__settings__].default_profile, or "" when it is not set or when the value
// is the reserved __settings__ section name itself.
func GetConfiguredDefaultProfileFrom(configFile *config.File) string {
return configFile.Section(databricksSettingsSection).Key(defaultProfileKey).String()
v := configFile.Section(databricksSettingsSection).Key(defaultProfileKey).String()
if v == databricksSettingsSection {
return ""
}
return v
}

// GetDefaultProfile returns the name of the default profile by loading the
Expand Down
10 changes: 10 additions & 0 deletions libs/databrickscfg/ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ func TestGetDefaultProfile(t *testing.T) {
content: "[no-host]\naccount_id = abc\n\n[profile1]\nhost = https://abc\n",
want: "profile1",
},
{
name: "self-referencing __settings__ falls through to single profile",
content: "[__settings__]\ndefault_profile = __settings__\n\n[profile1]\nhost = https://abc\n",
want: "profile1",
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -280,6 +285,11 @@ func TestGetConfiguredDefaultProfile(t *testing.T) {
content: "[__settings__]\n\n[profile1]\nhost = https://abc\n",
want: "",
},
{
name: "self-referencing __settings__ is ignored",
content: "[__settings__]\ndefault_profile = __settings__\n\n[profile1]\nhost = https://abc\n",
want: "",
},
}

for _, tc := range testCases {
Expand Down
Loading