From 1c02224902eec47e61d40215b0bf4816eab2153e Mon Sep 17 00:00:00 2001 From: Kartik Gupta <88345179+kartikgupta-db@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:18:13 +0200 Subject: [PATCH] Pass `DATABRICKS_CONFIG_FILE` env var to sdk config during `auth profiles` (#1394) ## Changes * Currently, we use `auth profiles` command with `DATABRICKS_CONFIG_FILE` env var set, the file pointed to by the env var is ONLY used for loading the profile names (ini file sections). It is not passed to go sdk config object. We also don't use env variable loader in the go sdk config object, so this env var is ignored by the config and only default file is read. * This PR explicitly sets the config file path in the go sdk config object. ## Tests * integration tests in vscode --- cmd/auth/profiles.go | 9 +++++---- cmd/auth/profiles_test.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/auth/profiles.go b/cmd/auth/profiles.go index 5ebea444..797eb3b5 100644 --- a/cmd/auth/profiles.go +++ b/cmd/auth/profiles.go @@ -29,10 +29,11 @@ func (c *profileMetadata) IsEmpty() bool { return c.Host == "" && c.AccountID == "" } -func (c *profileMetadata) Load(ctx context.Context, skipValidate bool) { +func (c *profileMetadata) Load(ctx context.Context, configFilePath string, skipValidate bool) { cfg := &config.Config{ - Loaders: []config.Loader{config.ConfigFile}, - Profile: c.Name, + Loaders: []config.Loader{config.ConfigFile}, + ConfigFile: configFilePath, + Profile: c.Name, } _ = cfg.EnsureResolved() if cfg.IsAws() { @@ -117,7 +118,7 @@ func newProfilesCommand() *cobra.Command { go func() { ctx := cmd.Context() t := time.Now() - profile.Load(ctx, skipValidate) + profile.Load(ctx, iniFile.Path(), skipValidate) log.Debugf(ctx, "Profile %q took %s to load", profile.Name, time.Since(t)) wg.Done() }() diff --git a/cmd/auth/profiles_test.go b/cmd/auth/profiles_test.go index 8a667a6d..91ff4d04 100644 --- a/cmd/auth/profiles_test.go +++ b/cmd/auth/profiles_test.go @@ -36,7 +36,7 @@ func TestProfiles(t *testing.T) { // Load the profile profile := &profileMetadata{Name: "profile1"} - profile.Load(ctx, true) + profile.Load(ctx, configFile, true) // Check the profile assert.Equal(t, "profile1", profile.Name)