14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/hiera/backend/eyaml/actions/recrypt_action.rb', line 14
def self.execute
encrypted_parser = Parser::ParserFactory.encrypted_parser
tokens = encrypted_parser.parse Eyaml::Options[:input_data]
decrypted_input = tokens.each_with_index.to_a.map{|(t,index)| t.to_decrypted :index => index}.join
decrypted_file = Utils.write_tempfile decrypted_input
edited_file = File.read decrypted_file
Utils.secure_file_delete :file => decrypted_file, :num_bytes => [edited_file.length, decrypted_input.length].max
raise StandardError, "Edited file is blank" if edited_file.empty?
decrypted_parser = Parser::ParserFactory.decrypted_parser
edited_tokens = decrypted_parser.parse(edited_file)
encrypted_output = edited_tokens.map{ |t| t.to_encrypted }.join
filename = Eyaml::Options[:eyaml]
File.open("#{filename}", 'w') { |file|
file.write encrypted_output
}
nil
end
|