class Chef::Knife::HitoriDataBagDec

Public Instance Methods

decrypt_data_bag() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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