Sha256: ed9d66d01c298602f126216a9cfd8b2b6487c8bf24f695e5aba84a76f70aa0a3

Contents?: true

Size: 1.96 KB

Versions: 36

Compression:

Stored size: 1.96 KB

Contents

module Fog
  module Storage
    class InternetArchive
      class Real
        require 'fog/internet_archive/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::Storage::InternetArchive.hash_to_cors(cors)

          headers = {}
          headers['Content-MD5'] = Base64.encode64(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,
            :host     => "#{bucket_name}.#{@host}",
            :method   => 'PUT',
            :query    => {'cors' => nil}
          })
        end
      end

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

Version data entries

36 entries across 34 versions & 6 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-internet-archive-0.0.1/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-internet-archive-0.0.1/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-internet-archive-0.0.1/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.40.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.39.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-internet-archive-0.0.1 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.38.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.37.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.36.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.35.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-2.0.0.pre.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.34.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.33.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.32.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.31.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.30.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.29.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb
fog-1.28.0 lib/fog/internet_archive/requests/storage/put_bucket_cors.rb