Class: Happening::AWS

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/happening/aws.rb

Constant Summary collapse

AMAZON_HEADER_PREFIX =
'x-amz-'
AMAZON_METADATA_PREFIX =
'x-amz-meta-'
DIGEST =
OpenSSL::Digest.new('sha1')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_access_key_id, aws_secret_access_key) ⇒ AWS

Returns a new instance of AWS.

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/happening/aws.rb', line 12

def initialize(aws_access_key_id, aws_secret_access_key)
  @aws_access_key_id = aws_access_key_id
  @aws_secret_access_key = aws_secret_access_key
  raise ArgumentError, "need AWS Access Key Id and AWS Secret Key" if blank?(aws_access_key_id) || blank?(aws_secret_access_key)
end

Instance Attribute Details

#aws_access_key_idObject

Returns the value of attribute aws_access_key_id.



10
11
12
# File 'lib/happening/aws.rb', line 10

def aws_access_key_id
  @aws_access_key_id
end

#aws_secret_access_keyObject

Returns the value of attribute aws_secret_access_key.



10
11
12
# File 'lib/happening/aws.rb', line 10

def aws_secret_access_key
  @aws_secret_access_key
end

Instance Method Details

#sign(method, path, headers = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/happening/aws.rb', line 18

def sign(method, path, headers={})
  headers = {
    'date' => utc_httpdate
  }.update(headers)
  
  request_description = canonical_request_description(method, path, headers)
  headers.update("Authorization" => "AWS #{aws_access_key_id}:#{generate_signature(request_description)}")
end