Module: Jerakia::Response::Filter::Encryption

Defined in:
lib/jerakia/response/filter/encryption.rb

Instance Method Summary collapse

Instance Method Details

#decrypt(data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jerakia/response/filter/encryption.rb', line 30

def decrypt(data)
  if encrypted?(data)
    public_key = config["eyaml"]["public_key"]
    private_key = config["eyaml"]["private_key"]
    Hiera::Backend::Eyaml::Options[:pkcs7_private_key] = private_key
    Hiera::Backend::Eyaml::Options[:pkcs7_public_key] = public_key
    parser = Hiera::Backend::Eyaml::Parser::ParserFactory.hiera_backend_parser
    
    tokens = parser.parse(data)
    decrypted = tokens.map{ |token| token.to_plain_text }
    plaintext = decrypted.join
    Jerakia.log.debug(plaintext)
    plaintext.chomp!
    data.clear.insert(0,plaintext)
  else
    data
  end
end

#encrypted?(data) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/jerakia/response/filter/encryption.rb', line 49

def encrypted?(data)
  /.*ENC\[.*?\]/ =~ data ? true : false
end

#filter_encryption(opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/jerakia/response/filter/encryption.rb', line 21

def filter_encryption(opts={})
  parse_values do |val|
    if val.is_a?(String)
      decrypt val
    end
    val
  end
end