Class: AWS::DynamoDB::Request
- Inherits:
-
Core::Http::Request
- Object
- Core::Http::Request
- AWS::DynamoDB::Request
- Defined in:
- lib/aws/dynamo_db/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
Attributes inherited from Core::Http::Request
#access_key_id, #headers, #host, #http_method, #params, #path, #proxy_uri
Instance Method Summary collapse
- #add_authorization!(signer) ⇒ Object
- #canonical_headers ⇒ Object
- #headers_to_sign ⇒ Object
-
#initialize(*args) ⇒ Request
constructor
A new instance of Request.
- #string_to_sign ⇒ Object
Methods inherited from Core::Http::Request
#add_param, #querystring, #ssl_ca_file, #ssl_ca_file=, #ssl_verify_peer=, #ssl_verify_peer?, #uri, #url_encoded_params, #use_ssl=, #use_ssl?
Constructor Details
#initialize(*args) ⇒ Request
Returns a new instance of Request.
22 23 24 25 |
# File 'lib/aws/dynamo_db/request.rb', line 22 def initialize(*args) super headers["content-type"] = "application/json; amzn-1.0" end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
27 28 29 |
# File 'lib/aws/dynamo_db/request.rb', line 27 def body @body end |
Instance Method Details
#add_authorization!(signer) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aws/dynamo_db/request.rb', line 29 def (signer) self.access_key_id = signer.access_key_id headers["x-amz-date"] ||= (headers["date"] ||= Time.now.rfc822) headers["host"] ||= host raise ArgumentError, "a security token is required" unless signer.session_token headers["x-amz-security-token"] = signer.session_token # compute the authorization request_hash = OpenSSL::Digest::SHA256.digest(string_to_sign) signature = signer.sign(request_hash) headers["x-amzn-authorization"] = "AWS3 "+ "AWSAccessKeyId=#{signer.access_key_id},"+ "Algorithm=HmacSHA256,"+ "SignedHeaders=#{headers_to_sign.join(';')},"+ "Signature=#{signature}" end |
#canonical_headers ⇒ Object
60 61 62 63 64 65 |
# File 'lib/aws/dynamo_db/request.rb', line 60 def canonical_headers headers_to_sign.map do |name| value = headers[name] "#{name.downcase.strip}:#{value.strip}\n" end.sort.join end |
#headers_to_sign ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/aws/dynamo_db/request.rb', line 52 def headers_to_sign headers.keys.select do |header| header == "content-encoding" || header == "host" || header =~ /^x-amz/ end end |
#string_to_sign ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/aws/dynamo_db/request.rb', line 67 def string_to_sign [http_method, "/", "", canonical_headers, body].join("\n") end |