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
|
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{
|
cfg := config.Config{
|
||||||
Host: perisistentAuth.Host,
|
Host: perisistentAuth.Host,
|
||||||
AccountID: perisistentAuth.AccountID,
|
AccountID: perisistentAuth.AccountID,
|
||||||
AuthType: "databricks-cli",
|
AuthType: "databricks-cli",
|
||||||
Profile: profileName,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if configureCluster {
|
if configureCluster {
|
||||||
|
@ -77,6 +78,7 @@ var loginCmd = &cobra.Command{
|
||||||
cfg.ClusterID = clusterId
|
cfg.ClusterID = clusterId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.Profile = profileName
|
||||||
err = databrickscfg.SaveToProfile(ctx, &cfg)
|
err = databrickscfg.SaveToProfile(ctx, &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -76,6 +76,9 @@ func (l profileFromHostLoader) Configure(cfg *config.Config) error {
|
||||||
// Normalized version of the configured host.
|
// Normalized version of the configured host.
|
||||||
host := normalizeHost(cfg.Host)
|
host := normalizeHost(cfg.Host)
|
||||||
match, err := findMatchingProfile(configFile, func(s *ini.Section) bool {
|
match, err := findMatchingProfile(configFile, func(s *ini.Section) bool {
|
||||||
|
if cfg.Profile != "" {
|
||||||
|
return cfg.Profile == s.Name()
|
||||||
|
}
|
||||||
key, err := s.GetKey("host")
|
key, err := s.GetKey("host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracef(ctx, "section %s: %s", s.Name(), err)
|
log.Tracef(ctx, "section %s: %s", s.Name(), err)
|
||||||
|
|
|
@ -89,8 +89,6 @@ func SaveToProfile(ctx context.Context, cfg *config.Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// zeroval profile name before adding it to a section
|
|
||||||
cfg.Profile = ""
|
|
||||||
cfg.ConfigFile = ""
|
cfg.ConfigFile = ""
|
||||||
|
|
||||||
// clear old keys in case we're overriding the section
|
// 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 {
|
for _, attr := range config.ConfigAttributes {
|
||||||
if attr.IsZero(cfg) {
|
if attr.IsZero(cfg) || attr.Name == "profile" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
key := section.Key(attr.Name)
|
key := section.Key(attr.Name)
|
||||||
|
|
Loading…
Reference in New Issue