Class: Awful::Kms

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

Constant Summary collapse

COLORS =
{
  Enabled:         :green,
  PendingDeletion: :red,
}

Instance Method Summary collapse

Methods inherited from Cli

#initialize, #ll, #version

Constructor Details

This class inherits a constructor from Awful::Cli

Instance Method Details

#aliasesObject



118
119
120
121
122
123
124
125
126
# File 'lib/awful/kms.rb', line 118

def aliases
  list_aliases.output do |list|
    if options[:long]
      print_table list.map { |a| [a.alias_name, a.target_key_id, a.alias_arn] }
    else
      puts list.map(&:alias_name)
    end
  end
end

#decrypt(data) ⇒ Object



88
89
90
91
# File 'lib/awful/kms.rb', line 88

def decrypt(data)
  key = Base64.decode64(data)
  puts kms.decrypt(ciphertext_blob: key)
end

#encrypt(id, data) ⇒ Object



82
83
84
85
# File 'lib/awful/kms.rb', line 82

def encrypt(id, data)
  blob = kms.encrypt(key_id: id, plaintext: data).ciphertext_blob
  puts Base64.encode64(blob)
end

#get(id) ⇒ Object



67
68
69
70
71
# File 'lib/awful/kms.rb', line 67

def get(id)
  kms.describe_key(key_id: id_or_alias(id))..output do |key|
    puts YAML.dump(stringify_keys(key.to_hash))
  end
end

#id(name) ⇒ Object



129
130
131
# File 'lib/awful/kms.rb', line 129

def id(name)
  alias_by_name(name).output(&method(:puts))
end

#lsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/awful/kms.rb', line 51

def ls
  paginate(:keys) do |marker|
    kms.list_keys(marker: marker)
  end.output do |keys|
    if options[:long]
      print_table keys.map { |k|
        key = kms.describe_key(key_id: k.key_id).
        [ aliases_hash.fetch(k.key_id, '-'), k.key_id, color(key.key_state), key.creation_date ]
      }.sort
    else
      puts keys.map(&:key_id)
    end
  end
end

#policy(id) ⇒ Object



75
76
77
78
79
# File 'lib/awful/kms.rb', line 75

def policy(id)
  kms.get_key_policy(key_id: id_or_alias(id), policy_name: options[:name]).policy.output do |policy|
    puts policy
  end
end

#tag(id, *tags) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/awful/kms.rb', line 94

def tag(id, *tags)
  kms.tag_resource(
      key_id: id_or_alias(id),
      tags: tags.map do |tag|
        k,v = tag.split(/[:=]/)
        {tag_key: k, tag_value: v}
      end
    )
end

#tags(id) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/awful/kms.rb', line 105

def tags(id)
  paginate(:tags) do |marker|
    kms.list_resource_tags(
      key_id: id_or_alias(id),
      next_marker: marker,
    )
  end.output do |tags|
    print_table tags.map(&:to_a)
  end
end