Class: Hiera::Backend::Eyaml::Subcommands::Recrypt

Inherits:
Hiera::Backend::Eyaml::Subcommand show all
Defined in:
lib/hiera/backend/eyaml/subcommands/recrypt.rb

Class Method Summary collapse

Methods inherited from Hiera::Backend::Eyaml::Subcommand

all_options, attach_option, find, hidden?, load_config_file, parse, prettyname

Class Method Details

.descriptionObject



16
17
18
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 16

def self.description
  "recrypt an eyaml file"
end

.executeObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 32

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 }.join

  filename = Eyaml::Options[:eyaml]
  File.open("#{filename}", 'w') { |file|
    file.write encrypted_output
  }

  nil
end

.helptextObject



20
21
22
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 20

def self.helptext
  "Usage: eyaml recrypt [options] <some-eyaml-file>"
end

.optionsObject



12
13
14
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 12

def self.options
  []
end

.validate(options) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/hiera/backend/eyaml/subcommands/recrypt.rb', line 24

def self.validate options
  Trollop::die "You must specify an eyaml file" if ARGV.empty?
  options[:source] = :eyaml
  options[:eyaml] = ARGV.shift
  options[:input_data] = File.read options[:eyaml]
  options
end