Class: Bolt::Secret

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

Constant Summary collapse

KNOWN_KEYS =
{
  'createkeys' => %w[keysize private_key public_key],
  'encrypt'    => %w[public_key],
  'decrypt'    => %w[private_key public_key]
}.freeze

Class Method Summary collapse

Class Method Details

.execute(plugins, outputter, options) ⇒ Object



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/bolt/secret.rb', line 13

def self.execute(plugins, outputter, options)
  name   = options[:plugin] || 'pkcs7'
  plugin = plugins.by_name(name)

  unless plugin
    raise Bolt::Plugin::PluginError::Unknown, name
  end

  case options[:action]
  when 'createkeys'
    opts = { 'force' => options[:force] }.compact
    result = plugins.get_hook(name, :secret_createkeys).call(opts)
    outputter.print_message(result)
  when 'encrypt'
    encrypted = plugins.get_hook(name, :secret_encrypt).call('plaintext_value' => options[:object])
    outputter.print_message(encrypted)
  when 'decrypt'
    decrypted = plugins.get_hook(name, :secret_decrypt).call('encrypted_value' => options[:object])
    outputter.print_message(decrypted)
  end

  0
end