Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sentinel error for missing KV secrets #16699

Merged
merged 8 commits into from
Aug 12, 2022
Merged

Conversation

averche
Copy link
Contributor

@averche averche commented Aug 11, 2022

Adding a sentinel error value ErrSecretNotFound. With this change, callers can check specifically for non-existing secrets:

secret, err := client.KvV2("secret").Get("foo")

if errors.Is(err, vault.ErrSecretNotFound) {
    // handle missing secret
}
if err != nil {
    // handle other errors
}

An example where this would be useful is when implementing an "upsert" behavior, as suggested in #16483. The caller can check the error returned from KVv2.Patch for errors.Is(err, vault.ErrSecretNotFound) and call KvV2.Put accordingly.

@averche averche marked this pull request as ready for review August 12, 2022 18:14
api/kv_v2.go Show resolved Hide resolved
changelog/16699.txt Outdated Show resolved Hide resolved
Copy link
Collaborator

@digivava digivava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, and good improvements to some tests as well. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants