Sha256: a4b5355020ba488c08b449b07a360b409079fcc44f56cb0e688a95936ceee500

Contents?: true

Size: 1.91 KB

Versions: 37

Compression:

Stored size: 1.91 KB

Contents

module Fog
  module AWS
    class Storage
      class Real
        require 'fog/aws/requests/storage/cors_utils'

        # Sets the cors configuration for your bucket. If the configuration exists, Amazon S3 replaces it.
        #
        # @param bucket_name [String] name of bucket to modify
        # @param cors [Hash]
        #   * CORSConfiguration [Array]:
        #     * ID [String]: A unique identifier for the rule.
        #     * AllowedMethod [String]: An HTTP method that you want to allow the origin to execute.
        #     * AllowedOrigin [String]: An origin that you want to allow cross-domain requests from.
        #     * AllowedHeader [String]: Specifies which headers are allowed in a pre-flight OPTIONS request via the Access-Control-Request-Headers header.
        #     * MaxAgeSeconds [String]: The time in seconds that your browser is to cache the preflight response for the specified resource.
        #     * ExposeHeader [String]: One or more headers in the response that you want customers to be able to access from their applications.
        #
        # @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTcors.html

        def put_bucket_cors(bucket_name, cors)
          data = Fog::AWS::Storage.hash_to_cors(cors)

          headers = {}
          headers['Content-MD5'] = Base64.encode64(OpenSSL::Digest::MD5.digest(data)).strip
          headers['Content-Type'] = 'application/json'
          headers['Date'] = Fog::Time.now.to_date_header

          request({
            :body     => data,
            :expects  => 200,
            :headers  => headers,
            :bucket_name => bucket_name,
            :method   => 'PUT',
            :query    => {'cors' => nil}
          })
        end
      end

      class Mock
        def put_bucket_cors(bucket_name, cors)
          self.data[:cors][:bucket][bucket_name] = Fog::AWS::Storage.hash_to_cors(cors)
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
fog-aws-3.30.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.29.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.28.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.27.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.26.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.25.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.24.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.23.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.22.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.21.1 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.21.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.20.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.19.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.18.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.17.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.16.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.15.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.14.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.13.0 lib/fog/aws/requests/storage/put_bucket_cors.rb
fog-aws-3.12.0 lib/fog/aws/requests/storage/put_bucket_cors.rb