Advertisement
Guest User

Untitled

a guest
May 28th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class ::Hash
  2. # this method will recursively search for values starting from "databag/"
  3. # and replaces them with the values from the databags if present
  4. def decrypt
  5. self.each do |key,value|
  6. if value.instance_of? ::Hash
  7. # we need to go deeper!
  8. self[key] = value.decrypt
  9. elsif value.instance_of? ::String
  10. # starts with "databag/ ?
  11. if /databag\//.match(value)
  12. databag, databag_item, databag_item_key = value.split('/').drop(1)
  13. if databag and databag_item and databag_item_key
  14. # replace or skip
  15. replacement = Chef::EncryptedDataBagItem.load databag, databag_item rescue nil
  16. self[key] = replacement[databag_item_key] rescue value
  17. end
  18. end
  19. end
  20. end
  21. end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement