Sha256: 8334aac0e2df6bd472db29b3daca1408e0ff7c87245fdcdc342dcd109941b88a

Contents?: true

Size: 1.59 KB

Versions: 17

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

17 entries across 17 versions & 1 rubygems

Version Path
aws_recon-0.2.24 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.23 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.22 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.21 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.20 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.19 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.18 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.17 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.16 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.15 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.14 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.13 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.12 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.11 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.10 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.9 lib/aws_recon/collectors/shield.rb
aws_recon-0.2.8 lib/aws_recon/collectors/shield.rb