Module: Chef::Sugar::DataBag
Defined Under Namespace
Classes: EncryptedDataBagSecretNotGiven
Instance Method Summary collapse
-
#data_bag_item_for_environment(node, bag, id) ⇒ Hash
This algorithm attempts to find the data bag entry for the current node’s Chef environment.
-
#encrypted_data_bag_item(bag, id, secret = nil) ⇒ Hash
Helper method for loading an encrypted data bag item in a similar syntax/recipe DSL method.
-
#encrypted_data_bag_item_for_environment(node, bag, id, secret = nil) ⇒ Hash
This algorithm attempts to find the data bag entry for the current node’s Chef environment.
Instance Method Details
#data_bag_item_for_environment(node, bag, id) ⇒ Hash
This algorithm attempts to find the data bag entry for the current node’s Chef environment. If there are no environment-specific values, the “default” bucket is used. The data bag must follow the schema:
{
"default": {...},
"environment_name": {...},
"other_environment": {...},
}
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/chef/sugar/data_bag.rb', line 116 def data_bag_item_for_environment(node, bag, id) data = Chef::DataBagItem.load(bag, id) if data[node.chef_environment] Chef::Log.debug "Using #{node.chef_environment} as the key" data[node.chef_environment] else Chef::Log.debug "#{node.chef_environment} key does not exist, using `default`" data['default'] end end |
#encrypted_data_bag_item(bag, id, secret = nil) ⇒ Hash
Helper method for loading an encrypted data bag item in a similar syntax/recipe DSL method.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef/sugar/data_bag.rb', line 49 def encrypted_data_bag_item(bag, id, secret = nil) Chef::Log.debug "Loading encrypted data bag item #{bag}/#{id}" if secret.nil? && Chef::Config[:encrypted_data_bag_secret].nil? raise EncryptedDataBagSecretNotGiven.new end secret ||= File.read(Chef::Config[:encrypted_data_bag_secret]).strip Chef::EncryptedDataBagItem.load(bag, id, secret) end |
#encrypted_data_bag_item_for_environment(node, bag, id, secret = nil) ⇒ Hash
This algorithm attempts to find the data bag entry for the current node’s Chef environment. If there are no environment-specific values, the “default” bucket is used. The data bag must follow the schema:
{
"default": {...},
"environment_name": {...},
"other_environment": {...},
}
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chef/sugar/data_bag.rb', line 83 def encrypted_data_bag_item_for_environment(node, bag, id, secret = nil) data = encrypted_data_bag_item(bag, id, secret) if data[node.chef_environment] Chef::Log.debug "Using #{node.chef_environment} as the key" data[node.chef_environment] else Chef::Log.debug "#{node.chef_environment} key does not exist, using `default`" data['default'] end end |