mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[AWS|Elasticache] Use Signature v4
This commit is contained in:
parent
1fbfe53e78
commit
e8c0bb2be6
1 changed files with 13 additions and 9 deletions
|
@ -55,11 +55,12 @@ module Fog
|
|||
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
||||
def initialize(options={})
|
||||
@use_iam_profile = options[:use_iam_profile]
|
||||
setup_credentials(options)
|
||||
|
||||
@instrumentor = options[:instrumentor]
|
||||
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.elasticache'
|
||||
options[:region] ||= 'us-east-1'
|
||||
|
||||
@region = options[:region]
|
||||
@host = options[:host] || "elasticache.#{options[:region]}.amazonaws.com"
|
||||
@path = options[:path] || '/'
|
||||
@port = options[:port] || 443
|
||||
|
@ -67,6 +68,8 @@ module Fog
|
|||
@connection = Fog::XML::Connection.new(
|
||||
"#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]
|
||||
)
|
||||
|
||||
setup_credentials(options)
|
||||
end
|
||||
|
||||
def reload
|
||||
|
@ -81,7 +84,7 @@ module Fog
|
|||
@aws_session_token = options[:aws_session_token]
|
||||
@aws_credentials_expire_at = options[:aws_credentials_expire_at]
|
||||
|
||||
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
|
||||
@signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key, @region, 'elasticache')
|
||||
end
|
||||
|
||||
def request(params)
|
||||
|
@ -90,12 +93,13 @@ module Fog
|
|||
idempotent = params.delete(:idempotent)
|
||||
parser = params.delete(:parser)
|
||||
|
||||
body = Fog::AWS.signed_params(
|
||||
body, headers = Fog::AWS.signed_params_v4(
|
||||
params,
|
||||
{ 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
{
|
||||
:aws_access_key_id => @aws_access_key_id,
|
||||
:signer => @signer,
|
||||
:aws_session_token => @aws_session_token,
|
||||
:hmac => @hmac,
|
||||
:method => 'POST',
|
||||
:host => @host,
|
||||
:path => @path,
|
||||
:port => @port,
|
||||
|
@ -105,18 +109,18 @@ module Fog
|
|||
|
||||
if @instrumentor
|
||||
@instrumentor.instrument("#{@instrumentor_name}.request", params) do
|
||||
_request(body, idempotent, parser)
|
||||
_request(body, headers, idempotent, parser)
|
||||
end
|
||||
else
|
||||
_request(body, idempotent, parser)
|
||||
_request(body, headers, idempotent, parser)
|
||||
end
|
||||
end
|
||||
|
||||
def _request(body, idempotent, parser)
|
||||
def _request(body, headers, idempotent, parser)
|
||||
@connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:headers => headers,
|
||||
:idempotent => idempotent,
|
||||
:method => 'POST',
|
||||
:parser => parser
|
||||
|
|
Loading…
Reference in a new issue