Class: Chef::Knife::HitoriDataBagDec
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::HitoriDataBagDec
- Includes:
- HitoriBase
- Defined in:
- lib/chef/knife/hitori_data_bag_dec.rb
Instance Method Summary collapse
Methods included from HitoriBase
Instance Method Details
#decrypt_data_bag ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/chef/knife/hitori_data_bag_dec.rb', line 23 def decrypt_data_bag ui.info ui.color("Use SECRET_FILE '#{secret_file_path}'", :green) secret = Chef::EncryptedDataBagItem.load_secret(secret_file_path) ui.info ui.color("Decrypt DataBag #{Chef::Config[:data_bag_path]}/#{config[:bag]}/#{config[:item]}.json", :green) spr_creds = Chef::EncryptedDataBagItem.load(config[:bag], config[:item], secret) puts JSON.pretty_generate(spr_creds.to_hash) end |
#run ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/chef/knife/hitori_data_bag_dec.rb', line 15 def run update_environment(config[:environment]) if config[:environment] config[:bag], config[:item] = @name_args exit 1 unless validate decrypt_data_bag end |
#secret_file_path ⇒ Object
31 32 33 |
# File 'lib/chef/knife/hitori_data_bag_dec.rb', line 31 def secret_file_path config[:secret_file] || Chef::Config[:encrypted_data_bag_secret] end |
#validate ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chef/knife/hitori_data_bag_dec.rb', line 35 def validate if config[:bag].nil? || config[:item].nil? ui.error('Please specify BAG and ITEM') return false end unless secret_file_path ui.error('Please specify EncryptKey by Chef Config "encrypted_data_bag_secret" or --secret-file') return false end return true end |