Class: RightScale::CloudApi::AWS::RequestSigner
- Inherits:
-
CloudApi::Routine
- Object
- CloudApi::Routine
- RightScale::CloudApi::AWS::RequestSigner
- Defined in:
- lib/cloud/aws/base/routines/request_signer.rb
Overview
Request signer for AWS services.
Defined Under Namespace
Classes: Error
Constant Summary collapse
- MAX_GET_REQUEST_PATH_LENGTH =
Use POST verb if GET’s path is getting too big.
2000
Instance Method Summary collapse
-
#process ⇒ void
Authenticates an AWS request.
Instance Method Details
#process ⇒ void
This method returns an undefined value.
Authenticates an AWS request
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cloud/aws/base/routines/request_signer.rb', line 45 def process # Make sure all the required params are set @data[:request][:params]['AWSAccessKeyId'] = @data[:credentials][:aws_access_key_id] @data[:request][:params]['Version'] ||= @data[:options][:api_version] # Compile a final request path @data[:request][:path] = Utils::join_urn(@data[:connection][:uri].path, @data[:request][:relative_path]) # Sign the request sign_proc = Proc::new do |data| Utils::AWS::sign_v2_signature( data[:credentials][:aws_secret_access_key], data[:request][:params] || {}, data[:request][:verb], data[:connection][:uri].host, data[:request][:path] ) end signed_path = sign_proc.call(@data) # Rebuild the request as POST if its path is too long if signed_path.size > MAX_GET_REQUEST_PATH_LENGTH && @data[:request][:verb] == :get @data[:request][:verb] = :post signed_path = sign_proc.call(@data) end # Set new path or body and content-type case @data[:request][:verb] when :get @data[:request][:path] << "?#{signed_path}" when :post @data[:request][:body] = signed_path @data[:request][:headers]['content-type'] = 'application/x-www-form-urlencoded; charset=utf-8' else fail Error::new("Unsupported HTTP verb: #{@data[:request][:verb]}") end end |