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
10
11
# File 'lib/awspec/helper/finder/alb.rb', line 4

def find_alb(id)
  res = elbv2_client.describe_load_balancers({ names: [id] })
  res.load_balancers.select do |lb|
    lb.type == 'application'
  end.single_resource(id)
rescue Aws::ElasticLoadBalancingV2::Errors::LoadBalancerNotFound
  return nil
end

#find_alb_listener(arn) ⇒ Object



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

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

#find_alb_target_group(id) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/awspec/helper/finder/alb.rb', line 38

def find_alb_target_group(id)
  res = elbv2_client.describe_target_groups({ names: [id] })
  res.target_groups.select do |tg|
    %w(HTTP HTTPS).include?(tg.protocol)
  end.single_resource(id)
rescue StandardError
  return nil
end

#select_alb_by_vpc_id(vpc_id) ⇒ Object



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

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 && lb.type == 'application'
  end
end

#select_alb_listener_by_alb_arn(arn) ⇒ Object



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

def select_alb_listener_by_alb_arn(arn)
  selected = []
  next_marker = nil
  loop do
    res = elbv2_client.describe_listeners({ marker: next_marker, load_balancer_arn: arn })
    selected += res.listeners unless res.nil?
    (res.nil? && next_marker = res.next_marker) || break
  end
  selected
end

#select_all_alb_tags(id) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/awspec/helper/finder/alb.rb', line 58

def select_all_alb_tags(id)
  res = elbv2_client.describe_tags({ resource_arns: [id] })
  res.tag_descriptions.select do |resource|
    resource.resource_arn == id
  end.first.tags
rescue StandardError
  return nil
end

#select_rule_by_alb_listener_id(id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/awspec/helper/finder/alb.rb', line 47

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