Skip to content

Commit

Permalink
Enable Deletion of current API key
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Apr 27, 2024
1 parent ae2bfa4 commit d0bfe8a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/apikey/apikey_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ var apikeyRemoveCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
index, err := apiKeyFind(args[0])
if err != nil {
utility.Error("Unable find the API key %s", err.Error())
utility.Error("Unable to find the API key %s", err.Error())
os.Exit(1)
}

// Check if the requested API key is the current one
if index == config.Current.Meta.CurrentAPIKey {
utility.Warning("The API key %q is the current one, please change it before removing it", args[0])
os.Exit(1)
utility.Warning("The API key %q is the current one. If you remove it, you will need to set another API key as the current one to continue using the CLI.", args[0])
// Confirm the deletion of the current API key
if err := utility.AskForConfirm("delete the current API key"); err != nil {
fmt.Println("Operation aborted. Change the current API key before attempting removal again.")
os.Exit(1)
}
}

if utility.UserConfirmedDeletion("api key", common.DefaultYes, args[0]) {
if utility.UserConfirmedDeletion("API key", common.DefaultYes, args[0]) {
numKeys := len(config.Current.APIKeys)
delete(config.Current.APIKeys, index)
config.SaveConfig()
Expand Down

0 comments on commit d0bfe8a

Please sign in to comment.