Module: Awspec::Helper::Finder::Kms

Included in:
Awspec::Helper::Finder
Defined in:
lib/awspec/helper/finder/kms.rb

Instance Method Summary collapse

Instance Method Details

#find_kms_key(key_id) ⇒ Object



6
7
8
9
10
# File 'lib/awspec/helper/finder/kms.rb', line 6

def find_kms_key(key_id)
  kms_client.describe_key(key_id: key_id).
rescue StandardError
  nil
end

#find_kms_key_by_alias(key_alias_name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/awspec/helper/finder/kms.rb', line 12

def find_kms_key_by_alias(key_alias_name)
  alias_name = key_alias_name.start_with?('alias/') ? key_alias_name : "alias/#{key_alias_name}"
  found = nil
  next_marker = nil

  loop do
    res = kms_client.list_aliases(marker: next_marker, limit: 100)
    found = res.aliases.find { |key_alias| key_alias.alias_name == alias_name }
    (found.nil? && next_marker = res.next_marker) || break
  end

  find_kms_key(found.target_key_id) if found
end

#select_all_kms_aliasesObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/awspec/helper/finder/kms.rb', line 26

def select_all_kms_aliases
  all_aliases = []
  next_marker = nil

  loop do
    res = kms_client.list_aliases(marker: next_marker, limit: 100)
    all_aliases.concat(res.aliases)
    next_marker = res.next_marker || break
  end

  all_aliases
end