Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Fix error handling of credential loading #234

Merged
merged 4 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions pkg/secrethub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ func (i AppInfo) ValidateName() error {
// If no key credential could be found, a Client is returned that can only be used for unauthenticated routes.
func NewClient(with ...ClientOption) (*Client, error) {
client := &Client{
httpClient: http.NewClient(),
repoIndexKeys: make(map[api.RepoPath]*crypto.SymmetricKey),
appInfo: []*AppInfo{},
defaultPassphraseReader: credentials.FromEnv("SECRETHUB_CREDENTIAL_PASSPHRASE"),
httpClient: http.NewClient(),
repoIndexKeys: make(map[api.RepoPath]*crypto.SymmetricKey),
appInfo: []*AppInfo{},
}

err := client.with(with...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -157,10 +157,8 @@ func NewClient(with ...ClientOption) (*Client, error) {
}

err := client.with(WithCredentials(provider))
// nolint: staticcheck
if err != nil {
// TODO: log that default credential was not loaded.
// Do go on because we want to allow an unauthenticated client.
return nil, err
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/secrethub/credentials/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func ImportKey(credentialReader, passphraseReader Reader) (Key, error) {
if envPassphrase != "" {
credential, err := decryptKey([]byte(envPassphrase), encoded)
if err != nil {
if crypto.IsWrongKey(err) {
err = ErrCannotDecryptCredential
}
return Key{}, fmt.Errorf("decrypting credential with passphrase read from $%s: %v", credentialPassphraseEnvVar, err)
jpcoenen marked this conversation as resolved.
Show resolved Hide resolved
}
return Key{key: credential}, nil
Expand Down