Skip to content

Instantly share code, notes, and snippets.

@hh
Created February 12, 2013 00:34
Show Gist options
  • Save hh/4758994 to your computer and use it in GitHub Desktop.
Save hh/4758994 to your computer and use it in GitHub Desktop.
example of created an encrypted data bag contents
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