From 6289affb014f1eddc0bbe75b2611a574fd2a3117 Mon Sep 17 00:00:00 2001 From: Maggie Dreyer Date: Wed, 28 Nov 2018 15:57:11 -0800 Subject: [PATCH] Revert "Remove option for not raising exceptions for now." This reverts commit 5e5ed917a549323ff8f730f7df9cfdc481f6fa51, putting back the option to prevent exceptions from being raised. --- lib/puppet/functions/vault_lookup/lookup.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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)