Sha256: 3e2bdb9bab85fb1184372ee46a6d42dd710bbc245c137b417e0591dcc6d6a5f9

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

class Shield < Mapper
  #
  # Returns an array of resources.
  #
  def collect
    resources = []

    #
    # describe_subscription
    #
    @client.describe_subscription.each do |response|
      log(response.context.operation_name)

      struct = OpenStruct.new(response.subscription.to_h)
      struct.type = 'subscription'
      struct.arn = "arn:aws:shield:#{@region}:#{account}:subscription"

      resources.push(struct.to_h)
    end

    #
    # describe_emergency_contact_settings
    #
    @client.describe_emergency_contact_settings.each do |response|
      log(response.context.operation_name)

      struct = OpenStruct.new
      struct.type = 'contact_list'
      struct.arn = "arn:aws:shield:#{@region}:#{account}:contact_list"
      struct.contacts = response.emergency_contact_list.map(&:to_h)

      resources.push(struct.to_h)
    end

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

      # describe_protection
      response.protections.each do |protection|
        struct = OpenStruct.new(@client.describe_protection({ protection_id: protection.id }).protection.to_h)
        struct.type = 'protection'
        struct.arn = protection.resource_arn

        resources.push(struct.to_h)
      end
    end

    resources
  rescue Aws::Shield::Errors::ServiceError => e
    log_error(e.code)
    raise e unless suppressed_errors.include?(e.code)

    [] # no access or service isn't enabled
  end

  private

  # not an error
  def suppressed_errors
    %w[
      ResourceNotFoundException
    ]
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
aws_recon-0.2.7 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.6 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.5 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.4 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.3 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.2 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.1 lib/aws_recon/collectors/shield.rb