Class: Awful::Secret

Inherits:
Cli show all
Defined in:
lib/awful/secret.rb

Constant Summary collapse

COLORS =
{
  AWSCURRENT: :green
}

Instance Method Summary collapse

Methods inherited from Cli

#initialize, #ll, #version

Constructor Details

This class inherits a constructor from Awful::Cli

Instance Method Details

#delete(id) ⇒ Object



49
50
51
52
53
# File 'lib/awful/secret.rb', line 49

def delete(id)
  if yes?("Really delete secret #{id}?", :yellow)
    puts client.delete_secret(secret_id: id, recovery_window_in_days: options[:window]).deletion_date
  end
end

#get(id) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/awful/secret.rb', line 29

def get(id)
  string = client.get_secret_value(secret_id: id).secret_string
  begin
    hash = JSON.parse(string)
    hash.each { |k,v| hash[k] = "#{v.bytesize} bytes" } unless options[:show]
    print_table hash.sort
  rescue JSON::ParserError
    puts string
  end
end

#history(id) ⇒ Object



41
42
43
44
45
# File 'lib/awful/secret.rb', line 41

def history(id)
  print_table client.list_secret_version_ids(secret_id: id).versions.map { |v|
    [ v.version_id, color(v.version_stages.join(',')), v.created_date ]
  }
end

#ls(prefix = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/awful/secret.rb', line 16

def ls(prefix = nil)
  client.list_secrets.map(&:secret_list).flatten.tap do |secrets|
    secrets.select! { |s| s.name.start_with?(prefix) } if prefix
  end.map do |s|
    [ s.name, s.created_date, s.primary_region ]
  end.tap do |list|
    print_table list.sort
  end
end