Skip to content

Commit

Permalink
Merge pull request #350 from MsysTechnologiesllc/sangmeshA/Fix_vault_…
Browse files Browse the repository at this point in the history
…method_should_throw_meaningful_exception_when_no_data_bag_exists

Handled exception from vault? method
  • Loading branch information
tas50 committed Aug 12, 2020
2 parents ba503e6 + 452611e commit f95031d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ end
group :debug do
gem "pry"
gem "pry-byebug"
gem "pry-stack_explorer"
gem "pry-stack_explorer", "~> 0.4.0" # pin until we drop ruby < 2.6
gem "rb-readline"
end
1 change: 0 additions & 1 deletion chef-vault.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
# Chef-Vault Gemspec file
# Copyright 2013-2015, Nordstrom, Inc.
# Copyright 2017-2019, Chef Software, Inc.
Expand Down
11 changes: 10 additions & 1 deletion lib/chef-vault/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,16 @@ def self.vault?(vault, name)
def self.data_bag_item_type(vault, name)
# adapted from https://github.com/opscode-cookbooks/chef-vault/blob/v1.3.0/libraries/chef_vault_item.rb
# and https://github.com/sensu/sensu-chef/blob/2.9.0/libraries/sensu_helpers.rb
dbi = Chef::DataBagItem.load(vault, name)
begin
dbi = Chef::DataBagItem.load(vault, name)
rescue Net::HTTPServerException => http_error
if http_error.response.code == "404"
raise ChefVault::Exceptions::ItemNotFound,
"#{vault}/#{name} not found"
else
raise http_error
end
end
encrypted = dbi.detect do |_, v|
v.is_a?(Hash) && v.key?("encrypted_data")
end
Expand Down

0 comments on commit f95031d

Please sign in to comment.