Skip to content

Commit

Permalink
Fix for login command with not all flags; Added automatic context swi…
Browse files Browse the repository at this point in the history
…tch after login execution and credential update

Signed-off-by: Patrick Eschenbach <patrickeschenbach96@gmail.com>
  • Loading branch information
qcserestipy committed Dec 23, 2024
1 parent 49f1d5b commit b9d3754
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/harbor/root/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func LoginCommand() *cobra.Command {
} else {
err = createLoginView(&loginView)
}
} else if currentCredentialName != "" {
} else if currentCredentialName != "" && loginView.Name == "" && loginView.Server == "" && loginView.Username == "" && loginView.Password == "" {
var resolvedLoginView login.LoginView
creds := config.Credentials
key, err := utils.GetEncryptionKey()
Expand Down
4 changes: 3 additions & 1 deletion pkg/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ func UpdateCredentialsInConfigFile(updatedCredential Credential, configPath stri
for i, cred := range c.Credentials {
if cred.Name == updatedCredential.Name {
c.Credentials[i] = updatedCredential
c.CurrentCredentialName = updatedCredential.Name
updated = true
break
}
Expand All @@ -501,6 +502,7 @@ func UpdateCredentialsInConfigFile(updatedCredential Credential, configPath stri
log.Fatalf("failed to write updated config file: %v", err)
}

log.Infof("Updated credential '%s' in config file at %s", updatedCredential.Name, configPath)
log.Infof("Updated credential '%s' in config file at %s.", updatedCredential.Name, configPath)
log.Infof("Switched to context '%s'", updatedCredential.Name)
return nil
}

0 comments on commit b9d3754

Please sign in to comment.