Class: Chef::Knife::HitoriKeyCreate
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::HitoriKeyCreate
- Includes:
- HitoriBase
- Defined in:
- lib/chef/knife/hitori_key_create.rb
Instance Method Summary collapse
Methods included from HitoriBase
Instance Method Details
#create_key ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/chef/knife/hitori_key_create.rb', line 16 def create_key secret_file_path = Chef::Config[:encrypted_data_bag_secret] if ::File.exists?(secret_file_path) yes = ui.confirm("#{secret_file_path} already exists.\nOVERWRITE this?") return unless yes end do_create_key(secret_file_path) end |
#do_create_key(secret_file_path) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/chef/knife/hitori_key_create.rb', line 25 def do_create_key(secret_file_path) FileUtils.mkpath(::File.dirname(secret_file_path)) key = [OpenSSL::Random.random_bytes(512)].pack('m0') data = (1..key.size/64).inject(key) {|x,i| x.insert(i*64+i-1, "\n")} + "\n" ::File.write(secret_file_path, data) ui.info ui.color("save secret key to #{secret_file_path}", :green) end |
#run ⇒ Object
11 12 13 14 |
# File 'lib/chef/knife/hitori_key_create.rb', line 11 def run update_environment(config[:environment]) if config[:environment] create_key end |