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