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 path information for related lookup errors #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions lib/puppet/functions/vault_lookup/lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def lookup(path, vault_url = nil)

secret_response = connection.get("/v1/#{path}", 'X-Vault-Token' => token)
unless secret_response.is_a?(Net::HTTPOK)
message = "Received #{secret_response.code} response code from vault at #{uri.host} for secret lookup"
message = "Received #{secret_response.code} response code from vault at #{uri.host} for #{path} lookup"
raise Puppet::Error, append_api_errors(message, secret_response)
end

begin
data = JSON.parse(secret_response.body)['data']
rescue StandardError
raise Puppet::Error, 'Error parsing json secret data from vault response'
raise Puppet::Error, "Error parsing json secret data from vault response for #{path} path"
end

Puppet::Pops::Types::PSensitiveType::Sensitive.new(data)
Expand Down
4 changes: 2 additions & 2 deletions spec/functions/lookup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

expect {
function.execute('secret/test', 'https://vault.doesnotexist:8200')
}.to raise_error(Puppet::Error, %r{Received 403 response code from vault at vault.doesnotexist for secret lookup.*permission denied})
}.to raise_error(Puppet::Error, %r{Received 403 response code from vault at vault.doesnotexist for .*lookup.*permission denied})
end

it 'raises a Puppet error when warning present' do
Expand All @@ -120,7 +120,7 @@

expect {
function.execute('secret/test', 'https://vault.doesnotexist:8200')
}.to raise_error(Puppet::Error, %r{Received 404 response code from vault at vault.doesnotexist for secret lookup.*Invalid path for a versioned K/V secrets engine})
}.to raise_error(Puppet::Error, %r{Received 404 response code from vault at vault.doesnotexist for .*lookup.*Invalid path for a versioned K/V secrets engine})
end

it 'logs on, requests a secret using a token, and returns the data wrapped in the Sensitive type' do
Expand Down