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

Return nil on 404 not found #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

crayfishx
Copy link
Contributor

The current implementation raises an exception if the lookup fails to resolve a result.... this just doesn't make sense for a data lookup, its more that conceivable that most of the time we will look up a value that might not exist.... raising an exception here means there is no way to handle this within Puppet and limits the usability of this function.

Instead of raising an exception, this PR changes the behaviour so that unresolved lookups return nil (Undef) and can therefore be handled within Puppet code.

$secret = vault_lookup('secret/data/no_exist')
if $secret {
  $plantext = $secret.unwrap
}

Without this patch I fail to see how you can ever look up a value that doesn't exist, since it raises an exception and fails the Puppet run it becomes un-handlable.

@bastelfreak bastelfreak added the bug Something isn't working label Sep 28, 2022
@bastelfreak
Copy link
Member

there is an explicit test for the old behaviour, I wam wondering if this was implemented on purpose, but I dont see a reason for it 🤔

@smortex
Copy link
Member

smortex commented Sep 29, 2022

This seems in-line with the behavior of lookup when no value is found:

romain@zappy ~ % puppet apply -te 'lookup("foo") notify { "does something": }'
Error: Function lookup() did not find a value for the name 'foo'
romain@zappy ~ % echo $?
1

You can pass more parameters to lookup() to set a default value. Maybe it makes sense to match the parameters / behavior with the function from Puppet core.

@binford2k
Copy link
Member

See #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants