Module: Awspec::Helper::Finder::Efs

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

Instance Method Summary collapse

Instance Method Details

#find_efs(id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/awspec/helper/finder/efs.rb', line 6

def find_efs(id)
  begin
    res = efs_client.describe_file_systems({
                                             file_system_id: id,
                                             max_items: 1
                                           })
  rescue StandardError
    # Aws::EFS::Errors::BadRequest (invalid file system ID: my-efs)
    file_system_id = get_id_by_name_tag(id)
    res = efs_client.describe_file_systems({
                                             file_system_id: file_system_id,
                                             max_items: 1
                                           })
  end
  res.file_systems.single_resource(id)
end

#find_efs_tags(id, tag_key) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/awspec/helper/finder/efs.rb', line 23

def find_efs_tags(id, tag_key)
  begin
    tag_set = efs_client.describe_tags({ file_system_id: id })
  rescue StandardError
    # Aws::EFS::Errors::BadRequest (invalid file system ID: my-efs)
    file_system_id = get_id_by_name_tag(id)
    tag_set = efs_client.describe_tags({
                                         file_system_id: file_system_id
                                       })
  end
  tag_query = tag_set.tags.find { |tag| tag.key == tag_key }
  return tag_query if tag_query
end

#get_id_by_name_tag(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/awspec/helper/finder/efs.rb', line 37

def get_id_by_name_tag(name)
  # takes a name tag and iterates inventory and returns file_system obj
  inventory = efs_client.describe_file_systems
  file_systems = inventory.file_systems.select do |fs|
    tag_query = efs_client.describe_tags({
                                           file_system_id: fs.file_system_id
                                         })
    name_tag = tag_query.tags.find { |tag| tag.key == 'Name' } if tag_query.tags
    name_tag && name_tag.value == name
  end
  file_systems.single_resource(name).file_system_id
end

#get_name_by_id(id) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/awspec/helper/finder/efs.rb', line 50

def get_name_by_id(id)
  tag_query = efs_client.describe_tags({
                                         file_system_id: id
                                       })
  name_tag = tag_query.tags.find { |tag| tag.key == 'Name' }
  return name_tag.value if name_tag
end

#select_all_file_systemsObject



58
59
60
61
# File 'lib/awspec/helper/finder/efs.rb', line 58

def select_all_file_systems
  file_systems_query = efs_client.describe_file_systems
  file_systems_query.file_systems
end