Class: Elasticity::AwsRequestV4

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

Overview

To help ensure correctness, Amazon has provided a step-by-step guide of query-and-response conversations for various types of API calls.

http://docs.aws.amazon.com/general/latest/gr/signature-v4-test-suite.html

We are working with POSTs only, where the body of the POST contains the service details, so the ‘post-x-www-form-urlencoded-parameters’ suite is the most applicable.

Constant Summary collapse

SERVICE_NAME =
'elasticmapreduce'

Instance Method Summary collapse

Constructor Details

#initialize(aws_session, ruby_service_hash) ⇒ AwsRequestV4

Returns a new instance of AwsRequestV4.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/elasticity/aws_request_v4.rb', line 15

def initialize(aws_session, ruby_service_hash)
  @aws_session = aws_session

  @ruby_service_hash = ruby_service_hash
  @operation = @ruby_service_hash[:operation]
  @ruby_service_hash.delete(:operation)

  @timestamp = Time.now.utc

  @access_key = Elasticity.configuration.access_key
  if @access_key == nil
    raise ArgumentError, '.access_key must be set in the configuration block'
  end

  @secret_key = Elasticity.configuration.secret_key
  if @secret_key == nil
    raise ArgumentError, '.secret_key must be set in the configuration block'
  end
end

Instance Method Details

#headersObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/elasticity/aws_request_v4.rb', line 35

def headers
  headers = {
    'Authorization' => "AWS4-HMAC-SHA256 Credential=#{@access_key}/#{credential_scope}, SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-target, Signature=#{aws_v4_signature}",
    'Content-Type' => 'application/x-amz-json-1.1',
    'Host' => host,
    'User-Agent' => "elasticity/#{Elasticity::VERSION}",
    'X-Amz-Content-SHA256' => Digest::SHA256.hexdigest(payload),
    'X-Amz-Date' => @timestamp.strftime('%Y%m%dT%H%M%SZ'),
    'X-Amz-Target' => "ElasticMapReduce.#{@operation}",
  }
  headers.merge!('X-Amz-Security-Token' => Elasticity.configuration.security_token) if Elasticity.configuration.security_token
  headers
end

#payloadObject



53
54
55
56
57
58
59
60
# File 'lib/elasticity/aws_request_v4.rb', line 53

def payload
  configurations = @ruby_service_hash.delete(:configurations)
  service_hash = AwsUtils.convert_ruby_to_aws_v4(@ruby_service_hash)
  return service_hash.to_json if configurations.nil?
  @ruby_service_hash[:configurations] = configurations
  service_hash['Configurations'] = configurations
  service_hash.to_json
end

#urlObject



49
50
51
# File 'lib/elasticity/aws_request_v4.rb', line 49

def url
  "https://#{host}"
end