Class: Hiera::Backend::Eyaml::Actions::EncryptAction

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera/backend/eyaml/actions/encrypt_action.rb

Class Method Summary collapse

Class Method Details

.executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hiera/backend/eyaml/actions/encrypt_action.rb', line 11

def self.execute 
  case Eyaml::Options[:source]
    when :eyaml
      parser = Parser::ParserFactory.decrypted_parser
      tokens = parser.parse(Eyaml::Options[:input_data])
      encrypted = tokens.map{ |token| token.to_encrypted }
      encrypted.join
    else
      encryptor = Encryptor.find
      ciphertext = encryptor.encode( encryptor.encrypt(Eyaml::Options[:input_data]) )
      token = Parser::EncToken.new(:block, Eyaml::Options[:input_data], encryptor, ciphertext, nil, '    ')
      case Eyaml::Options[:output]
        when "block"
          token.to_encrypted :label => Eyaml::Options[:label], :use_chevron => !Eyaml::Options[:label].nil?, :format => :block
        when "string"
          token.to_encrypted :label => Eyaml::Options[:label], :format => :string
        when "examples"
          string = token.to_encrypted :label => Eyaml::Options[:label] || 'string', :format => :string
          block = token.to_encrypted :label => Eyaml::Options[:label] || 'block', :format => :block
          "#{string}\n\nOR\n\n#{block}"
        else
          token.to_encrypted :format => :string
      end
  end
end