Fixed error on multiple profiles and failure to create a new profile with configured cluster (#513)

This commit is contained in:
Andrew Nester 2023-06-22 17:20:10 +02:00 committed by GitHub
parent f2a2d058d1
commit d23d4aef3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)