Class: Bolt::Secret::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/secret/base.rb

Direct Known Subclasses

Plugin::Pkcs7

Instance Method Summary collapse

Instance Method Details

#decode(code) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/bolt/secret/base.rb', line 15

def decode(code)
  format = %r{\AENC\[(?<plugin>\w+),(?<encoded>[\w\s+-=/]+)\]\s*\z}
  match = format.match(code)

  raise Bolt::ValidationError, "Could not parse as an encrypted value: #{code}" unless match

  raw = Base64.decode64(match[:encoded])
  [raw, match[:plugin]]
end

#encode(raw) ⇒ Object



10
11
12
13
# File 'lib/bolt/secret/base.rb', line 10

def encode(raw)
  coded = Base64.encode64(raw).strip
  "ENC[#{name.upcase},#{coded}]"
end

#hooksObject



6
7
8
# File 'lib/bolt/secret/base.rb', line 6

def hooks
  %i[resolve_reference secret_encrypt secret_decrypt secret_createkeys validate_resolve_reference]
end

#secret_decrypt(opts) ⇒ Object Also known as: resolve_reference



30
31
32
33
# File 'lib/bolt/secret/base.rb', line 30

def secret_decrypt(opts)
  raw, _plugin = decode(opts['encrypted_value'])
  decrypt_value(raw)
end

#secret_encrypt(opts) ⇒ Object



25
26
27
28
# File 'lib/bolt/secret/base.rb', line 25

def secret_encrypt(opts)
  encrypted = encrypt_value(opts['plaintext_value'])
  encode(encrypted)
end

#validate_resolve_reference(opts) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/bolt/secret/base.rb', line 36

def validate_resolve_reference(opts)
  # TODO: Remove deprecation warning
  if opts.include?('encrypted-value')
    msg = "Parsing error: The 'encrypted-value' key is deprecated and can no longer be used. " \
          "In your Bolt config files, please use 'encrypted_value' instead."
    raise Bolt::ValidationError, msg
  end
  decode(opts['encrypted_value'])
end