Skip to content

Commit

Permalink
Improve behavior of chef_vault_item
Browse files Browse the repository at this point in the history
* Check to see if we have a vault item before trying to laod it.
* Only load chef-vault if we have a vault item to load
* If we don't have a vault item, try loading a regular data bag instead
  • Loading branch information
mivok committed Mar 26, 2015
1 parent 09ff7ef commit 9622929
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions libraries/chef_vault_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ module ChefVaultItem
# Falls back to normal data bag item loading if the item isn't actually a
# vault item.
def chef_vault_item(bag, item)
begin
require 'chef-vault'
rescue LoadError
Chef::Log.warn("Missing gem 'chef-vault', use recipe[chef-vault] to install it first.")
end

begin
if Chef::DataBag.load(bag).key?("#{item}_keys")
# We have a vault item
begin
require 'chef-vault'
rescue LoadError
raise("Missing gem 'chef-vault', use recipe[chef-vault] to install it first.")
end
ChefVault::Item.load(bag, item)
rescue ChefVault::Exceptions::KeysNotFound, ChefVault::Exceptions::SecretDecryption
else
# We don't have a vault item, it must be a regular data bag
Chef::DataBagItem.load(bag, item)
end
end
Expand Down

2 comments on commit 9622929

@mhenrixon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes every single ChefSpec fail for me. Can someone please revert this?

5) db-server::master
     Failure/Error: cached(:chef_run) { converge }
     Chef::Exceptions::InvalidDataBagPath:
       Data bag path '/var/folders/30/vtzm8b791v35g4v99c52jgx80000gn/T/d20150506-73317-1q2frv1/data_bags' is invalid

@mivok
Copy link
Contributor Author

@mivok mivok commented on 9622929 May 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open a new issue and paste an example of the tests you're doing that fail (in addition to the error message mentioned above) please? It's not likely this is going to be reverted because it fixed a couple of showstopper bugs that resulted in production outages, but we do need to make chefspec work.

Please sign in to comment.