class Aws::S3Control::Plugins::ARN::ARNHandler

This plugin will extract out any ARN input and set context for other plugins to use without having to translate the ARN again.

Public Instance Methods

call(context) click to toggle source
# File lib/aws-sdk-s3control/plugins/arn.rb, line 55
def call(context)
  arn_member = _arn_member(context.operation.input.shape)
  if arn_member && (bucket = context.params[arn_member])
    resolved_region, arn = ARN.resolve_arn!(
      bucket,
      context.config.region,
      context.config.s3_use_arn_region
    )
    validate_outpost_dualstack!(context)
    if arn
      validate_config!(context, arn)

      if arn.is_a?(OutpostAccessPointARN) ||
         arn.is_a?(OutpostBucketARN)
        set_outpost_header!(context, arn)
        # disable account_id prefix for outposts urls
        context.config.disable_host_prefix_injection = true
      end
      set_account_param!(context, arn)

      # depending on the ARN's resource type, put the resource value
      # back onto params
      context.params[arn_member] = arn.input_member
      context.metadata[:s3_arn] = {
        arn: arn,
        resolved_region: resolved_region,
        dualstack: extract_dualstack_config!(context)
      }
    end
  end
  @handler.call(context)
end

Private Instance Methods

_arn_member(input) click to toggle source

This looks for BucketName or AccessPointName, but prefers BucketName for CreateAccessPoint because it contains both but should not have an Access Point ARN as AccessPointName.

# File lib/aws-sdk-s3control/plugins/arn.rb, line 104
def _arn_member(input)
  input.members.each do |member, ref|
    if ref.shape.name == 'BucketName' ||
       (ref.shape.name == 'AccessPointName' &&
        input.name != 'CreateAccessPointRequest')
      return member
    end
  end
end
extract_dualstack_config!(context) click to toggle source

other plugins use dualstack so disable it when we're done

# File lib/aws-sdk-s3control/plugins/arn.rb, line 115
def extract_dualstack_config!(context)
  dualstack = context[:use_dualstack_endpoint]
  context[:use_dualstack_endpoint] = false if dualstack
  dualstack
end
set_account_param!(context, arn) click to toggle source
# File lib/aws-sdk-s3control/plugins/arn.rb, line 133
def set_account_param!(context, arn)
  if context.params[:account_id] &&
     context.params[:account_id] != arn.account_id
    raise ArgumentError,
          'Cannot provide an Account ID that is different from the '\
          'Account ID in the ARN.'
  end
  context.params[:account_id] = arn.account_id
end
set_outpost_header!(context, arn) click to toggle source
# File lib/aws-sdk-s3control/plugins/arn.rb, line 129
def set_outpost_header!(context, arn)
  context.http_request.headers['x-amz-outpost-id'] = arn.outpost_id
end
validate_config!(context, arn) click to toggle source
# File lib/aws-sdk-s3control/plugins/arn.rb, line 121
def validate_config!(context, arn)
  if !arn.support_dualstack? && context[:use_dualstack_endpoint]
    raise ArgumentError,
          'Cannot provide an Outpost Access Point ARN when '\
          '`:use_dualstack_endpoint` is set to true.'
  end
end
validate_outpost_dualstack!(context) click to toggle source

this validation has nothing to do with ARNs (can't be in validate_config!) outposts does not support dualstack, so operations using an outpost id should be validated too.

# File lib/aws-sdk-s3control/plugins/arn.rb, line 93
def validate_outpost_dualstack!(context)
  if context.params[:outpost_id] && context[:use_dualstack_endpoint]
    raise ArgumentError,
          'Cannot provide an Outpost ID when '\
          '`:use_dualstack_endpoint` is set to true.'
  end
end