Class: Bisques::AwsRequestAuthorization
- Inherits:
-
Object
- Object
- Bisques::AwsRequestAuthorization
- Defined in:
- lib/bisques/aws_request_authorization.rb
Overview
Instances of this class are used to create HTTP authorization headers for AWS using Signature Version 4, as per docs.amazonwebservices.com/general/latest/gr/signature-version-4.html
Usage
This is just an example of extracting the relevant information.
url = "https://sqs.us-east-1.amazon.com/"
original_headers = {"Content-Type": "text/plain"}
query = {"Action" => "ListQueues"}
body = "some body text"
credentials = AwsCredentials.default
= AwsRequestAuthorization.new
.url = url
.method = "POST"
.query = query
.body = body
.region = "us-east-1"
.service = "sqs"
.headers = original_headers
new_headers = .headers.merge(
"Authorization" => .
)
url_with_query = url + "?" + query.map{|p| p.join("=")}.join("&")
Net::HTTP.post(
url_with_query,
body,
new_headers
)
Instance Attribute Summary collapse
-
#body ⇒ Object
A string of the body being sent (for POST and PUT HTTP methods).
-
#credentials ⇒ Object
An AwsCredentials object.
-
#headers ⇒ Object
The headers to read back.
-
#method ⇒ Object
The HTTP method.
-
#query ⇒ Object
A hash of key/pairs for the query string.
-
#region ⇒ Object
The AWS region.
-
#service ⇒ Object
The AWS service.
-
#url ⇒ Object
The full URL to the API call.
Instance Method Summary collapse
-
#authorization_header ⇒ Object
The generated authorization header.
Instance Attribute Details
#body ⇒ Object
A string of the body being sent (for POST and PUT HTTP methods).
47 48 49 |
# File 'lib/bisques/aws_request_authorization.rb', line 47 def body @body end |
#credentials ⇒ Object
An AwsCredentials object.
53 54 55 |
# File 'lib/bisques/aws_request_authorization.rb', line 53 def credentials @credentials end |
#headers ⇒ Object
The headers to read back.
55 56 57 |
# File 'lib/bisques/aws_request_authorization.rb', line 55 def headers @headers end |
#method ⇒ Object
The HTTP method.
43 44 45 |
# File 'lib/bisques/aws_request_authorization.rb', line 43 def method @method end |
#query ⇒ Object
A hash of key/pairs for the query string.
45 46 47 |
# File 'lib/bisques/aws_request_authorization.rb', line 45 def query @query end |
#region ⇒ Object
The AWS region.
49 50 51 |
# File 'lib/bisques/aws_request_authorization.rb', line 49 def region @region end |
#service ⇒ Object
The AWS service.
51 52 53 |
# File 'lib/bisques/aws_request_authorization.rb', line 51 def service @service end |
#url ⇒ Object
The full URL to the API call.
41 42 43 |
# File 'lib/bisques/aws_request_authorization.rb', line 41 def url @url end |
Instance Method Details
#authorization_header ⇒ Object
The generated authorization header.
58 59 60 61 62 63 64 65 |
# File 'lib/bisques/aws_request_authorization.rb', line 58 def [ "AWS4-HMAC-SHA256", "Credential=#{credentials.aws_key}/#{request_datestamp}/#{region}/#{service}/aws4_request,", "SignedHeaders=#{signed_headers.join(";")},", "Signature=#{signature.to_s}" ].join(" ") end |