Skip to content

Commit

Permalink
configure use DATABRICKS_CONFIG_FILE environment variable if exists a…
Browse files Browse the repository at this point in the history
…s config file
  • Loading branch information
kai-zhu-sonatype committed Mar 28, 2024
1 parent cddc5f9 commit 1f2dcd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions cmd/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ The host must be specified with the --host flag or the DATABRICKS_HOST environme

// Save profile to config file.
return databrickscfg.SaveToProfile(ctx, &config.Config{
Profile: cfg.Profile,
Host: cfg.Host,
Token: cfg.Token,
ClusterID: cfg.ClusterID,
Profile: cfg.Profile,
Host: cfg.Host,
Token: cfg.Token,
ClusterID: cfg.ClusterID,
ConfigFile: cfg.ConfigFile,
})
}

Expand Down
10 changes: 9 additions & 1 deletion cmd/configure/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func TestConfigFileFromEnvNoInteractive(t *testing.T) {
//TODO: Replace with similar test code from go SDK, once we start using it directly
ctx := context.Background()
tempHomeDir := setup(t)
cfgPath := filepath.Join(tempHomeDir, ".databrickscfg")
defaultCfgPath := filepath.Join(tempHomeDir, ".databrickscfg")
cfgPath := filepath.Join(tempHomeDir, "overwrite-databricks-cfg")
t.Setenv("DATABRICKS_CONFIG_FILE", cfgPath)

inp := getTempFileWithContent(t, tempHomeDir, "token\n")
Expand All @@ -96,6 +97,13 @@ func TestConfigFileFromEnvNoInteractive(t *testing.T) {
_, err = os.Stat(cfgPath)
assert.NoError(t, err)

_, err = os.Stat(defaultCfgPath)
if runtime.GOOS == "windows" {
assert.ErrorContains(t, err, "cannot find the file specified")
} else {
assert.ErrorContains(t, err, "no such file or directory")
}

cfg, err := ini.Load(cfgPath)
assert.NoError(t, err)

Expand Down

0 comments on commit 1f2dcd8

Please sign in to comment.