File: location_constraint.rb

package info (click to toggle)
ruby-aws-sdk-s3 1.170.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,740 kB
  • sloc: ruby: 16,388; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module Aws
  module S3
    module Plugins

      # When making calls to {S3::Client#create_bucket} outside the
      # "classic" region, the bucket location constraint must be specified.
      # This plugin auto populates the constraint to the configured region.
      class LocationConstraint < Seahorse::Client::Plugin

        class Handler < Seahorse::Client::Handler

          def call(context)
            unless context.config.region == 'us-east-1'
              populate_location_constraint(context.params, context.config.region)
            end
            @handler.call(context)
          end

          private

          def populate_location_constraint(params, region)
            params[:create_bucket_configuration] ||= {}
            unless params[:create_bucket_configuration][:location]
              params[:create_bucket_configuration][:location_constraint] ||= region
            end
          end

        end

        handler(Handler, step: :initialize, operations: [:create_bucket])

      end
    end
  end
end