Class: ElasticLoadBalancingV2

Inherits:
Mapper
  • Object
show all
Defined in:
lib/aws_recon/collectors/elasticloadbalancingv2.rb

Overview

Collect ELBv2 resources

Constant Summary

Constants inherited from Mapper

Mapper::SINGLE_REGION_SERVICES

Instance Method Summary collapse

Methods inherited from Mapper

#initialize

Constructor Details

This class inherits a constructor from Mapper

Instance Method Details

#collectObject

Returns an array of resources.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/aws_recon/collectors/elasticloadbalancingv2.rb', line 10

def collect
  resources = []

  #
  # describe_load_balancers
  #
  @client.describe_load_balancers.each_with_index do |response, page|
    log(response.context.operation_name, page)

    response.load_balancers.each do |elb|
      struct = OpenStruct.new(elb.to_h)
      struct.type = 'load_balancer'
      struct.arn = elb.load_balancer_arn
      struct.load_balancer_version = 'v2'
      struct.load_balancer_type = elb.type
      struct.listeners = []
      struct.target_groups = []

      # describe_load_balancer_attributes
      struct.attributes = @client
                          .describe_load_balancer_attributes({ load_balancer_arn: elb.load_balancer_arn })
                          .attributes.map(&:to_h)

      # describe_tags
      struct.tags = @client
                    .describe_tags({ resource_arns: [elb.load_balancer_arn] })
                    .tag_descriptions.map(&:tags)
                    .flatten.map(&:to_h)

      # describe_listeners
      @client.describe_listeners({ load_balancer_arn: elb.load_balancer_arn }).each_with_index do |response, _page|
        log(response.context.operation_name, page)

        response.listeners.each do |listener|
          struct.listeners.push(listener.to_h)
        end
      end

      # describe_target_groups
      @client.describe_target_groups({ load_balancer_arn: elb.load_balancer_arn }).each_with_index do |response, page|
        log(response.context.operation_name, page)

        response.target_groups.each do |target_group|
          tg = OpenStruct.new(target_group.to_h)

          # describe_target_health
          tg.health_descriptions = @client
                                   .describe_target_health({ target_group_arn: target_group.target_group_arn })
                                   .target_health_descriptions.map(&:to_h)

          struct.target_groups.push(tg.to_h)
        end
      end

      resources.push(struct.to_h)
    end
  end

  resources
end