Class: Awful::Kms
Constant Summary
collapse
- COLORS =
{
Enabled: :green,
PendingDeletion: :red,
}
Instance Method Summary
collapse
Methods inherited from Cli
#initialize
Constructor Details
This class inherits a constructor from Awful::Cli
Instance Method Details
122
123
124
125
126
127
128
129
130
|
# File 'lib/awful/kms.rb', line 122
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
92
93
94
95
|
# File 'lib/awful/kms.rb', line 92
def decrypt(data)
key = Base64.decode64(data)
puts kms.decrypt(ciphertext_blob: key)
end
|
#encrypt(id, data) ⇒ Object
86
87
88
89
|
# File 'lib/awful/kms.rb', line 86
def encrypt(id, data)
blob = kms.encrypt(key_id: id, plaintext: data).ciphertext_blob
puts Base64.encode64(blob)
end
|
71
72
73
74
75
|
# File 'lib/awful/kms.rb', line 71
def get(id)
kms.describe_key(key_id: id_or_alias(id)).key_metadata.output do |key|
puts YAML.dump(stringify_keys(key.to_hash))
end
end
|
133
134
135
|
# File 'lib/awful/kms.rb', line 133
def id(name)
alias_by_name(name).output(&method(:puts))
end
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/awful/kms.rb', line 55
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).key_metadata
[ 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
79
80
81
82
83
|
# File 'lib/awful/kms.rb', line 79
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
98
99
100
101
102
103
104
105
106
|
# File 'lib/awful/kms.rb', line 98
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
|
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/awful/kms.rb', line 109
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
|