Class: AWS4Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/activemessaging/adapters/aws4_signer.rb

Constant Summary collapse

RFC8601BASIC =
"%Y%m%dT%H%M%SZ"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ AWS4Signer

Returns a new instance of AWS4Signer.



24
25
26
27
28
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 24

def initialize(config)
  @access_key = config[:access_key] || config["access_key"]
  @secret_key = config[:secret_key] || config["secret_key"]
  @region = config[:region] || config["region"]
end

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.



21
22
23
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 21

def access_key
  @access_key
end

#bodyObject (readonly)

Returns the value of attribute body.



22
23
24
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 22

def body
  @body
end

#dateObject (readonly)

Returns the value of attribute date.



22
23
24
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 22

def date
  @date
end

#headersObject (readonly)

Returns the value of attribute headers.



22
23
24
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 22

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



22
23
24
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 22

def method
  @method
end

#regionObject (readonly)

Returns the value of attribute region.



21
22
23
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 21

def region
  @region
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



21
22
23
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 21

def secret_key
  @secret_key
end

#serviceObject (readonly)

Returns the value of attribute service.



22
23
24
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 22

def service
  @service
end

#uriObject (readonly)

Returns the value of attribute uri.



22
23
24
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 22

def uri
  @uri
end

Instance Method Details

#sign(method, uri, headers, body = nil, debug = false, service_name = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/activemessaging/adapters/aws4_signer.rb', line 30

def sign(method, uri, headers, body = nil, debug = false, service_name=nil)
  @method = method.upcase
  @uri = uri
  @headers = headers
  @body = body
  @service = service_name || @uri.host.split(".", 2)[0]
  date_header = headers["Date"] || headers["DATE"] || headers["date"]
  @date = (date_header ? Time.parse(date_header) : Time.now).utc.strftime(RFC8601BASIC)
  dump if debug
  signed = headers.dup
  signed['Authorization'] = authorization(headers)
  signed
end