Module: Awspec::Helper::Finder::Alb

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

Instance Method Summary collapse

Instance Method Details

#find_alb(id) ⇒ Object



4
5
6
7
8
9
# File 'lib/awspec/helper/finder/alb.rb', line 4

def find_alb(id)
  res = elbv2_client.describe_load_balancers({ names: [id] })
  res.load_balancers.single_resource(id)
rescue
  return nil
end

#find_alb_listener(arn) ⇒ Object



18
19
20
21
22
23
# File 'lib/awspec/helper/finder/alb.rb', line 18

def find_alb_listener(arn)
  res = elbv2_client.describe_listeners({ listener_arns: [arn] })
  res.listeners.single_resource(arn)
rescue
  return nil
end

#find_alb_target_group(id) ⇒ Object



25
26
27
28
29
30
# File 'lib/awspec/helper/finder/alb.rb', line 25

def find_alb_target_group(id)
  res = elbv2_client.describe_target_groups({ names: [id] })
  res.target_groups.single_resource(id)
rescue
  return nil
end

#select_alb_by_vpc_id(vpc_id) ⇒ Object



11
12
13
14
15
16
# File 'lib/awspec/helper/finder/alb.rb', line 11

def select_alb_by_vpc_id(vpc_id)
  res = elbv2_client.describe_load_balancers
  res.load_balancers.select do |lb|
    lb.vpc_id == vpc_id
  end
end

#select_rule_by_alb_listener_id(id) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/awspec/helper/finder/alb.rb', line 32

def select_rule_by_alb_listener_id(id)
  selected = []
  next_marker = nil
  loop do
    res = elbv2_client.describe_rules(marker: next_marker, listener_arn: id)
    selected += res.rules unless res.nil?
    (res.nil? && next_marker = res.next_marker) || break
  end
  selected
end