Class: CORS::Policy::S3

Inherits:
Object
  • Object
show all
Includes:
CORS::Policy
Defined in:
lib/cors/policy/s3.rb

Overview

CORS policy for Amazon S3. See CORS module documenation for an example.

See Also:

Instance Attribute Summary

Attributes included from CORS::Policy

#attributes, #errors

Instance Method Summary collapse

Methods included from CORS::Policy

included, #initialize, #rules, #sign, #valid?

Instance Method Details

#manifestObject

Compile the S3 authorization manifest from the parameters.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cors/policy/s3.rb', line 14

def manifest
  [].tap do |manifest|
    manifest << attributes["method"].upcase
    manifest << attributes["md5"]
    manifest << attributes["content-type"]
    manifest << attributes["date"]
    normalized_headers.each do |(header, *values)|
      manifest << "#{header}:#{values.join(",")}"
    end
    manifest << attributes["filename"]
  end.join("\n")
end

#sign!(access_key, secret_access_key) ⇒ Object

Sign the #manifest with the AWS credentials.

Parameters:

  • access_key (String)
  • secret_access_key (String)


31
32
33
34
35
# File 'lib/cors/policy/s3.rb', line 31

def sign!(access_key, secret_access_key)
  digest = OpenSSL::HMAC.digest("sha1", secret_access_key, manifest)
  signature = Base64.strict_encode64(digest)
  "AWS #{access_key}:#{signature}"
end