Class: AwsElbs

Inherits:
Object
  • Object
show all
Includes:
AwsPluralResourceMixin
Defined in:
lib/resources/aws/aws_elbs.rb

Defined Under Namespace

Classes: Backend

Instance Attribute Summary

Attributes included from AwsPluralResourceMixin

#table

Instance Method Summary collapse

Methods included from AwsPluralResourceMixin

included

Methods included from AwsResourceMixin

#catch_aws_errors, #check_resource_param_names, #initialize, #inspec_runner

Instance Method Details

#fetch_from_apiObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/resources/aws/aws_elbs.rb', line 45

def fetch_from_api
  backend = BackendFactory.create(inspec_runner)
  @table = []
  pagination_opts = {}
  loop do
    api_result = backend.describe_load_balancers(pagination_opts)
    @table += unpack_describe_elbs_response(api_result.load_balancer_descriptions)
    break unless api_result.next_marker

    pagination_opts = { marker: api_result.next_marker }
  end
end

#to_sObject



41
42
43
# File 'lib/resources/aws/aws_elbs.rb', line 41

def to_s
  "AWS ELBs"
end

#unpack_describe_elbs_response(load_balancers) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/resources/aws/aws_elbs.rb', line 58

def unpack_describe_elbs_response(load_balancers)
  load_balancers.map do |lb_struct|
    {
      availability_zones: lb_struct.availability_zones,
      dns_name: lb_struct.dns_name,
      external_ports: lb_struct.listener_descriptions.map { |ld| ld.listener.load_balancer_port },
      instance_ids: lb_struct.instances.map(&:instance_id),
      internal_ports: lb_struct.listener_descriptions.map { |ld| ld.listener.instance_port },
      elb_name: lb_struct.load_balancer_name,
      security_group_ids: lb_struct.security_groups,
      subnet_ids: lb_struct.subnets,
      vpc_id: lb_struct.vpc_id,
    }
  end
end

#validate_params(resource_params) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/resources/aws/aws_elbs.rb', line 16

def validate_params(resource_params)
  unless resource_params.empty?
    raise ArgumentError, "aws_elbs does not accept resource parameters."
  end

  resource_params
end