Skip to content

Commit

Permalink
Detect and throw an error if the creds can't be set in the Keyring
Browse files Browse the repository at this point in the history
Currently an error when setting the item misleadingly results in the success message.  There's nothing in the Keyring docs about this (`Set` doesn't return an error), but I've found that `nil` is returned when the call is successful, and an error is returned otherwise.

Unsure if this is good Golang practice or not.
  • Loading branch information
simpson-ross committed Jun 28, 2023
1 parent fceac03 commit 988642d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,17 @@ var addCmd = &cobra.Command{
log.Fatalf("failed to open keyring backend: %s", strings.ToLower(err.Error()))
}

_ = ring.Set(keyring.Item{
resp := ring.Set(keyring.Item{
Key: fmt.Sprintf("%s-%s", profileName, authType),
Data: []byte(authValue),
})

fmt.Println("\nSuccess! Credentials have been set and are now ready for use!")
if resp == nil {
fmt.Println("\nSuccess! Credentials have been set and are now ready for use!")
} else {
// error of some sort
log.Fatal("Error adding credentials to keyring: ", resp)
}
},
}

Expand Down

0 comments on commit 988642d

Please sign in to comment.