class AWS::S3::Request
@private
def add_authorization! credentials
def add_authorization! credentials if token = credentials.session_token headers["x-amz-security-token"] = token end secret = credentials.secret_access_key signature = Core::Signer.sign(secret, string_to_sign, 'sha1') signature = URI.escape(signature) headers["authorization"] = "AWS #{credentials.access_key_id}:#{signature}" end
def body
-
(String, nil)
- The http request body.
def body if @body_stream string = @body_stream.read @body_stream.rewind string else nil end end
def body= body
-
body
(String, IO
) -- The http request body. This can be a string or
def body= body @body_stream = StringIO.new(body) end
def canonicalized_headers
is generated.
See the developer guide for more information on how this element
CanonicalizedAmzHeaders
def canonicalized_headers x_amz = headers.select{|name, value| name.to_s =~ /^x-amz-/i } x_amz = x_amz.collect{|name, value| [name.downcase, value] } x_amz = x_amz.sort_by{|name, value| name } x_amz = x_amz.collect{|name, value| "#{name}:#{value}" }.join("\n") x_amz == '' ? nil : x_amz end
def canonicalized_resource
"?logging", or "?torrent"];
[ sub-resource, if present. e.g. "?acl", "?location",
[ "/" + Bucket ] +
CanonicalizedResource =
From the S3 developer guide
def canonicalized_resource parts = [] # virtual hosted-style requests require the hostname to appear # in the canonicalized resource prefixed by a forward slash. if Client.dns_compatible_bucket_name?(bucket) and !Client.path_style_bucket_name?(bucket) then parts << "/#{bucket}" end # all requests require the portion of the un-decoded uri up to # but not including the query string parts << path # lastly any sub resource querystring params need to be appened # in lexigraphical ordered joined by '&' and prefixed by '?' params = (sub_resource_params + query_parameters_for_signature) unless params.empty? parts << '?' parts << params.sort.collect{|p| p.to_s }.join('&') end parts.join end
def host
def host Client.path_style_bucket_name?(bucket) ? @host : "#{bucket}.#{@host}" end
def metadata= metadata
def metadata= metadata Array(metadata).each do |name, value| headers["x-amz-meta-#{name}"] = value end end
def path
def path parts = [] parts << bucket if bucket and Client.path_style_bucket_name?(bucket) parts << escape_path(key) if key "/#{parts.join('/')}" end
def query_parameters
def query_parameters %w(response-content-type response-content-language response-expires response-cache-control response-content-disposition response-content-encoding) end
def query_parameters_for_signature
def query_parameters_for_signature params.select { |p| self.class.query_parameters.include?(p.name) } end
def querystring
def querystring url_encoded_params end
def signing_string_date
def signing_string_date # if a date is provided via x-amz-date then we should omit the # Date header from the signing string (should appear as a blank line) if headers.detect{|k,v| k.to_s =~ /^x-amz-date$/i } '' else headers['date'] ||= Time.now.rfc822 end end
def storage_class= storage_class
def storage_class= storage_class if storage_class.kind_of?(Symbol) headers["x-amz-storage-class"] = storage_class.to_s.upcase elsif storage_class headers["x-amz-storage-class"] = storage_class end end
def string_to_sign
CanonicalizedAmzHeaders + CanonicalizedResource;
date + "\n" +
content-type + "\n" +
content-md5 + "\n" +
HTTP-Verb + "\n" +
StringToSign =
From the S3 developer guide:
def string_to_sign [ http_method, headers.values_at('content-md5', 'content-type').join("\n"), signing_string_date, canonicalized_headers, canonicalized_resource, ].flatten.compact.join("\n") end
def sub_resource_params
def sub_resource_params params.select{|p| self.class.sub_resources.include?(p.name) } end
def sub_resources
def sub_resources %w(acl location logging notification partNumber policy requestPayment torrent uploadId uploads versionId versioning versions delete lifecycle) end