lib/chef/knife/encrypt.rb in knife-crypt-0.0.2 vs lib/chef/knife/encrypt.rb in knife-crypt-0.0.3

- old
+ new

@@ -4,12 +4,23 @@ class Knife class Encrypt < Knife banner "knife encrypt DATA (options)" def run + if @name_args.empty? + show_usage + ui.fatal "You must specify data to encrypt" + exit 1 + end + decrypted_value = eval @name_args[0] + initialization_vector = @name_args[1] secret = Chef::EncryptedDataBagItem.load_secret - encrypted_value = Chef::EncryptedDataBagItem.encrypt_value decrypted_value, secret + encrypted_value = if Chef::EncryptedDataBagItem.methods.include? :encrypt_value + Chef::EncryptedDataBagItem.encrypt_value(decrypted_value, secret) + else + Chef::EncryptedDataBagItem::Encryptor.new(decrypted_value, secret, initialization_vector).for_encrypted_item["encrypted_data"] + end puts encrypted_value end end end end