10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/encrypt_data_bag.rb', line 10
def from_file(secret_file, input_file, output_file)
secret = Chef::EncryptedDataBagItem.load_secret(secret_file)
raw_item = IO.read(input_file)
item = is_json_file?(input_file) ? JSON.parse(raw_item) : eval(raw_item)
item = Hash[item.map { |k, v| [k.to_s, v] }]
encrypted_item = Chef::EncryptedDataBagItem.encrypt_data_bag_item(item, secret)
File.open(output_file, "w") do |file|
if is_json_file?(output_file)
file.print(JSON.pretty_generate(encrypted_item))
else
file.write(encrypted_item.pretty_inspect)
end
end
end
|