diff --git a/cmd/auth/login.go b/cmd/auth/login.go index c905d6cf..13db6147 100644 --- a/cmd/auth/login.go +++ b/cmd/auth/login.go @@ -49,11 +49,12 @@ var loginCmd = &cobra.Command{ return err } + // We need the config without the profile before it's used to initialise new workspace client below. + // Otherwise it will complain about non existing profile because it was not yet saved. cfg := config.Config{ Host: perisistentAuth.Host, AccountID: perisistentAuth.AccountID, AuthType: "databricks-cli", - Profile: profileName, } if configureCluster { @@ -77,6 +78,7 @@ var loginCmd = &cobra.Command{ cfg.ClusterID = clusterId } + cfg.Profile = profileName err = databrickscfg.SaveToProfile(ctx, &cfg) if err != nil { return err diff --git a/libs/databrickscfg/loader.go b/libs/databrickscfg/loader.go index 8179703a..e0507961 100644 --- a/libs/databrickscfg/loader.go +++ b/libs/databrickscfg/loader.go @@ -76,6 +76,9 @@ func (l profileFromHostLoader) Configure(cfg *config.Config) error { // Normalized version of the configured host. host := normalizeHost(cfg.Host) match, err := findMatchingProfile(configFile, func(s *ini.Section) bool { + if cfg.Profile != "" { + return cfg.Profile == s.Name() + } key, err := s.GetKey("host") if err != nil { log.Tracef(ctx, "section %s: %s", s.Name(), err) diff --git a/libs/databrickscfg/ops.go b/libs/databrickscfg/ops.go index 4a4a27b0..9f3b8db4 100644 --- a/libs/databrickscfg/ops.go +++ b/libs/databrickscfg/ops.go @@ -89,8 +89,6 @@ func SaveToProfile(ctx context.Context, cfg *config.Config) error { return err } - // zeroval profile name before adding it to a section - cfg.Profile = "" cfg.ConfigFile = "" // clear old keys in case we're overriding the section @@ -99,7 +97,7 @@ func SaveToProfile(ctx context.Context, cfg *config.Config) error { } for _, attr := range config.ConfigAttributes { - if attr.IsZero(cfg) { + if attr.IsZero(cfg) || attr.Name == "profile" { continue } key := section.Key(attr.Name)