Created
February 12, 2013 00:34
-
-
Save hh/4758994 to your computer and use it in GitHub Desktop.
example of created an encrypted data bag contents
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
require 'chef/knife' | |
module KnifePlugins | |
class User < Chef::Knife | |
deps do | |
require 'chef/search/query' | |
require 'chef/shef/ext' | |
end | |
banner "knife user" | |
def run | |
Shef::Extensions.extend_context_object(self) | |
def_secret_file = "/etc/chef/encrypted_data_bag_secret" | |
secret_file = Chef::Config[:encrypted_data_bag_secret] || def_secret_file | |
secret=Chef::EncryptedDataBagItem.load_secret(secret_file) | |
username=ui.ask_question('New username? ') #, opts={}) | |
password=ui.ask_question('New password? ') #, opts={}) | |
dbi=Chef::DataBagItem.from_hash(Mash.new({id: username, password: password})) | |
dbi_json = Chef::EncryptedDataBagItem.encrypt_data_bag_item(dbi, secret).to_json | |
ui.output "\nPut the following in your databag" | |
ui.output "#{dbi_json}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment