Sha256: dfe8b7acb1bb2441521b00492f267e1891dcb3f7a0632c10b03ddf41b4c742c9

Contents?: true

Size: 1.79 KB

Versions: 12

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

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

    #
    # describe_organization
    #
    begin
      @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
    rescue Aws::Organizations::Errors::ServiceError => e
      log_error(e.code)

      raise e unless suppressed_errors.include?(e.code) && !@options.quit_on_exception
    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
      AWSOrganizationsNotInUseException
    ]
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
aws_recon-0.5.33 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.32 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.31 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.30 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.29 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.28 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.27 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.26 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.25 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.24 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.23 lib/aws_recon/collectors/organizations.rb
aws_recon-0.5.22 lib/aws_recon/collectors/organizations.rb