diff --git a/lib/puppet/functions/vault_lookup/lookup.rb b/lib/puppet/functions/vault_lookup/lookup.rb index b71ec54..e4b4a89 100644 --- a/lib/puppet/functions/vault_lookup/lookup.rb +++ b/lib/puppet/functions/vault_lookup/lookup.rb @@ -2,9 +2,21 @@ dispatch :lookup do param 'String', :path param 'String', :vault_url + optional_param 'Boolean', :raise_exceptions end - def lookup(path, vault_url) + def lookup(path, vault_url, raise_exceptions = true) + _lookup(path, vault_url) + rescue StandardError => e + raise if raise_exceptions + + Puppet.err(e.message) + nil + end + + private + + def _lookup(path, vault_url) uri = URI(vault_url) # URI is used here to just parse the vault_url into a host string # and port; it's possible to generate a URI::Generic when a scheme @@ -31,8 +43,6 @@ def lookup(path, vault_url) Puppet::Pops::Types::PSensitiveType::Sensitive.new(data) end - private - def get_auth_token(connection) response = connection.post('/v1/auth/cert/login', '') unless response.is_a?(Net::HTTPOK)