Sha256: 27dc153a2cfba5d21188123c2095e4368d6ed0921166233ba180db296307ba29

Contents?: true

Size: 1.56 KB

Versions: 44

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

#
# Collect Org resources
#
class Organizations < Mapper
  #
  # Returns an array of resources.
  #
  def collect
    resources = []

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

      struct = OpenStruct.new(response.organization.to_h)
      struct.type = 'organization'

      resources.push(struct.to_h)
    end

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

      response.handshakes.each do |handshake|
        struct = OpenStruct.new(handshake.to_h)
        struct.type = 'handshake'

        resources.push(struct.to_h)
      end
    end

    #
    # list_policies
    #
    begin
      @client.list_policies({ filter: 'SERVICE_CONTROL_POLICY' }).each_with_index do |response, page|
        log(response.context.operation_name, page)

        response.policies.each do |policy|
          struct = OpenStruct.new(policy.to_h)
          struct.type = 'service_control_policy'
          struct.content = @client.describe_policy({ policy_id: policy.id }).policy.content.parse_policy

          resources.push(struct.to_h)
        end
      end
    rescue Aws::Organizations::Errors::ServiceError => e
      log_error(e.code)

      raise e unless suppressed_errors.include?(e.code) && !@options.quit_on_exception
    end

    resources
  end

  private

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

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
aws_recon-0.5.21 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.20 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.19 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.18 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.17 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.16 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.15 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.14 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.13 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.12 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.11 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.10 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.9 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.8 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.7 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.6 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.5 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.4 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.3 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.2 lib/aws_recon/collectors/organizations.rb