mirror of https://github.com/databricks/cli.git
Fixed error on multiple profiles and failure to create a new profile with configured cluster (#513)
This commit is contained in:
parent
f2a2d058d1
commit
d23d4aef3a
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue