Class: AWS4::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/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) ⇒ Signer

Returns a new instance of Signer.



13
14
15
16
17
# File 'lib/aws4/signer.rb', line 13

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.



10
11
12
# File 'lib/aws4/signer.rb', line 10

def access_key
  @access_key
end

#bodyObject (readonly)

Returns the value of attribute body.



11
12
13
# File 'lib/aws4/signer.rb', line 11

def body
  @body
end

#dateObject (readonly)

Returns the value of attribute date.



11
12
13
# File 'lib/aws4/signer.rb', line 11

def date
  @date
end

#headersObject (readonly)

Returns the value of attribute headers.



11
12
13
# File 'lib/aws4/signer.rb', line 11

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



11
12
13
# File 'lib/aws4/signer.rb', line 11

def method
  @method
end

#regionObject (readonly)

Returns the value of attribute region.



10
11
12
# File 'lib/aws4/signer.rb', line 10

def region
  @region
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



10
11
12
# File 'lib/aws4/signer.rb', line 10

def secret_key
  @secret_key
end

#serviceObject (readonly)

Returns the value of attribute service.



11
12
13
# File 'lib/aws4/signer.rb', line 11

def service
  @service
end

#uriObject (readonly)

Returns the value of attribute uri.



11
12
13
# File 'lib/aws4/signer.rb', line 11

def uri
  @uri
end

Instance Method Details

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



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/aws4/signer.rb', line 19

def sign(method, uri, headers, body, debug = false)
  @method = method.upcase
  @uri = uri
  @headers = headers
  @body = body
  @service = @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