mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[AWS|SNS] Use Signature v4
This commit is contained in:
parent
dc83b6543c
commit
e5d0cddf2c
1 changed files with 12 additions and 9 deletions
|
@ -49,12 +49,12 @@ module Fog
|
|||
# * SNS object with connection to AWS.
|
||||
def initialize(options={})
|
||||
@use_iam_profile = options[:use_iam_profile]
|
||||
setup_credentials(options)
|
||||
@connection_options = options[:connection_options] || {}
|
||||
@instrumentor = options[:instrumentor]
|
||||
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.sns'
|
||||
|
||||
options[:region] ||= 'us-east-1'
|
||||
@region = options[:region]
|
||||
@host = options[:host] || "sns.#{options[:region]}.amazonaws.com"
|
||||
|
||||
@path = options[:path] || '/'
|
||||
|
@ -62,6 +62,8 @@ module Fog
|
|||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
||||
|
||||
setup_credentials(options)
|
||||
end
|
||||
|
||||
def reload
|
||||
|
@ -76,7 +78,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, 'sns')
|
||||
end
|
||||
|
||||
def request(params)
|
||||
|
@ -85,12 +87,13 @@ module Fog
|
|||
idempotent = params.delete(:idempotent)
|
||||
parser = params.delete(:parser)
|
||||
|
||||
body = AWS.signed_params(
|
||||
body, headers = AWS.signed_params_v4(
|
||||
params,
|
||||
{ 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
{
|
||||
:aws_access_key_id => @aws_access_key_id,
|
||||
:method => 'POST',
|
||||
:aws_session_token => @aws_session_token,
|
||||
:hmac => @hmac,
|
||||
:signer => @signer,
|
||||
:host => @host,
|
||||
:path => @path,
|
||||
:port => @port
|
||||
|
@ -99,19 +102,19 @@ 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,
|
||||
:idempotent => idempotent,
|
||||
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
:headers => headers,
|
||||
:method => 'POST',
|
||||
:parser => parser
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue