Class: Aws4Signer
- Inherits:
-
Object
- Object
- Aws4Signer
- Defined in:
- lib/aws4_signer.rb,
lib/aws4_signer/version.rb,
lib/aws4_signer/signature.rb
Defined Under Namespace
Classes: Signature
Constant Summary collapse
- VERSION =
"0.2.1"
Class Method Summary collapse
-
.uri_encode(str) ⇒ Object
to be exactly follow the AWS documentation, implement by ourselves.
Instance Method Summary collapse
-
#initialize(access_key_id, secret_access_key, region, service, security_token: nil) ⇒ Aws4Signer
constructor
A new instance of Aws4Signer.
- #sign(verb, uri, headers: {}, body: '') ⇒ Object
- #sign_http_request(req, uri = nil) ⇒ Object
Constructor Details
#initialize(access_key_id, secret_access_key, region, service, security_token: nil) ⇒ Aws4Signer
Returns a new instance of Aws4Signer.
24 25 26 27 28 29 30 |
# File 'lib/aws4_signer.rb', line 24 def initialize(access_key_id, secret_access_key, region, service, security_token: nil) @access_key_id = access_key_id @secret_access_key = secret_access_key @region = region @service = service @security_token = security_token end |
Class Method Details
.uri_encode(str) ⇒ Object
to be exactly follow the AWS documentation, implement by ourselves
14 15 16 17 18 19 20 21 22 |
# File 'lib/aws4_signer.rb', line 14 def self.uri_encode(str) str.bytes.map do |c| if %w[- . _ ~].include?(c) || (?A .. ?Z).cover?(c) || (?a .. ?z).cover?(c) || (?0 .. ?9).cover?(c) c else "%#{c.ord.to_s(16)}" end end.join end |
Instance Method Details
#sign(verb, uri, headers: {}, body: '') ⇒ Object
32 33 34 35 |
# File 'lib/aws4_signer.rb', line 32 def sign(verb, uri, headers: {}, body: '') raise ArgumentError, 'URI must provided' unless uri Signature.new(@access_key_id, @secret_access_key, @region, @service, verb, uri, headers, body, security_token: @security_token) end |
#sign_http_request(req, uri = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aws4_signer.rb', line 37 def sign_http_request(req, uri = nil) sign( req.method, uri || req.uri, headers: req.to_hash, body: req.body || '', ).tap do |signature| signature.attach_to_http_request(req) end end |