Class: VaultUpdate

Inherits:
Object
  • Object
show all
Defined in:
lib/vault-update.rb,
lib/vault-update/version.rb

Constant Summary collapse

VERSION =
'1.1.2'.freeze

Instance Method Summary collapse

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vault-update.rb', line 15

def run
  if opts[:history]
    secret_history.sort_by { |ts, _data| ts }[-history_fetch_size..-1].each do |ts, data|
      puts "#{Time.at(ts.to_s.to_i)}:".colorize(:green)
      puts JSON.pretty_generate(data) + "\n\n"
    end
  elsif opts[:last]
    puts JSON.pretty_generate(
      (secret_history.sort_by { |ts, _data| ts }.last || fail(NoHistoryError))[1]
    )
  elsif opts[:rollback]
    rollback_secret
  elsif opts[:current]
    puts JSON.pretty_generate(vault_read(opts[:path]) || fail(NoValueError))
  else
    update
  end
rescue MissingInputError, TypeError => e
  raise e unless e.class == TypeError && e.message == 'no implicit conversion of nil into String'
  Trollop.die 'KEY and VALUE must be provided'
rescue NoUpdateError
  puts 'Nothing to do'.colorize(:light_white)
  exit 0
rescue NoHistoryError
  puts 'ERROR: '.colorize(:red) + "There is no history for #{opts[:path]}"
  exit 2
rescue NoValueError
  puts 'ERROR: '.colorize(:red) + "There is no current value for #{opts[:path]}"
  exit 3
end