Class: Presss::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/presss.rb

Overview

Computes the Authorization header for a AWS request based on a message, the access key ID and secret access key.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key) ⇒ Authorization

Returns a new instance of Authorization.



13
14
15
# File 'lib/presss.rb', line 13

def initialize(access_key_id, secret_access_key)
  @access_key_id, @secret_access_key = access_key_id, secret_access_key
end

Instance Attribute Details

#access_key_idObject

Returns the value of attribute access_key_id.



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

def access_key_id
  @access_key_id
end

#secret_access_keyObject

Returns the value of attribute secret_access_key.



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

def secret_access_key
  @secret_access_key
end

Instance Method Details

#header(string) ⇒ Object

Returns the value for the Authorization header for a message contents.



18
19
20
# File 'lib/presss.rb', line 18

def header(string)
  'AWS ' + access_key_id + ':' + sign(string)
end

#hmac_sha1(string) ⇒ Object



27
28
29
# File 'lib/presss.rb', line 27

def hmac_sha1(string)
  OpenSSL::HMAC.digest('sha1', secret_access_key, string)
end

#sign(string) ⇒ Object

Returns a signature for a AWS request message.



23
24
25
# File 'lib/presss.rb', line 23

def sign(string)
  Base64.encode64(hmac_sha1(string)).strip
end