Skip to content

Instantly share code, notes, and snippets.

@afirth
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afirth/8829468 to your computer and use it in GitHub Desktop.
Save afirth/8829468 to your computer and use it in GitHub Desktop.
def self.load(data_bag, name, secret = nil) #secret can be nil
raw_hash = Chef::DataBagItem.load(data_bag, name) #load the raw (encrypted) hash into a databag object
secret = secret || self.load_secret #if secret is specified, this or operator short circuits and returns the first value. if secret is nil, calls self.load secret (L7)
self.new(raw_hash, secret) #return a new object
end
def self.load_secret(path=nil) #again, path can be nil
path ||= Chef::Config[:encrypted_data_bag_secret] # a shortcut to saying path = path || Chef::Config... as L3
if !path #nothing in path, means the default secret location wasn't set either. are you seeing this error?
raise ArgumentError, "No secret specified to load_secret and no secret found at #{Chef::Config.platform_specific_path('/etc/chef/encrypted_data_bag_secret')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment