Class: Hiera::Backend::Eyaml::Subcommands::Recrypt
Class Method Summary
collapse
all_options, attach_option, find, hidden?, load_config_file, parse, prettyname
Class Method Details
.description ⇒ Object
19
20
21
|
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 19
def self.description
'recrypt an eyaml file'
end
|
.execute ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 36
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_parser = Parser::ParserFactory.decrypted_parser
edited_tokens = decrypted_parser.parse(decrypted_input)
encrypted_output = edited_tokens.map { |t| t.to_encrypted({ change_encryption: @change_encryption }) }.join
filename = Eyaml::Options[:eyaml]
File.write("#{filename}", encrypted_output)
nil
end
|
.helptext ⇒ Object
23
24
25
|
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 23
def self.helptext
'Usage: eyaml recrypt [options] <some-eyaml-file>'
end
|
.options ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 10
def self.options
[
{ name: :change_encryption,
description: 'Specify the new encryption method that should be used for the file',
short: 'd',
default: 'pkcs7', },
]
end
|
.validate(options) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 27
def self.validate(options)
Optimist.die 'You must specify an eyaml file' if ARGV.empty?
options[:source] = :eyaml
options[:eyaml] = ARGV.shift
options[:input_data] = File.read options[:eyaml]
@change_encryption = options[:change_encryption]
options
end
|