Last active
August 29, 2015 13:56
-
-
Save workmad3/8804159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate your password in your preferred manner, such as SecureRandom.base64(30) | |
node[:my_super_secret_password] ||= NodeEncryption.encrypt_value("super_secret!") | |
# Later on, recover the password | |
my_super_secret_password = NodeEncryption.decrypt_value(node[:my_super_secret_password]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NodeEncryption | |
def self.encrypt_value(value) | |
secret = Chef::EncryptedDataBagItem.load_secret("/etc/chef/secret") | |
Chef::EncryptedDataBagItem::Encryptor.new(value, secret).for_encrypted_item | |
end | |
def self.decrypt_value(value, item_name) | |
secret = Chef::EncryptedDataBagItem.load_secret("/etc/chef/secret") | |
Chef::EncryptedDataBagItem::Decryptor.for(value, secret).for_decrypted_item | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment