@@ -48,18 +48,21 @@ class Real
48
48
def initialize ( options = { } )
49
49
50
50
@use_iam_profile = options [ :use_iam_profile ]
51
- setup_credentials ( options )
52
51
53
52
@instrumentor = options [ :instrumentor ]
54
53
@instrumentor_name = options [ :instrumentor_name ] || 'fog.aws.ses'
55
54
@connection_options = options [ :connection_options ] || { }
56
55
options [ :region ] ||= 'us-east-1'
56
+ @region = options [ :region ]
57
+
57
58
@host = options [ :host ] || "email.#{ options [ :region ] } .amazonaws.com"
58
59
@path = options [ :path ] || '/'
59
60
@persistent = options [ :persistent ] || false
60
61
@port = options [ :port ] || 443
61
62
@scheme = options [ :scheme ] || 'https'
62
63
@connection = Fog ::XML ::Connection . new ( "#{ @scheme } ://#{ @host } :#{ @port } #{ @path } " , @persistent , @connection_options )
64
+
65
+ setup_credentials ( options )
63
66
end
64
67
65
68
def reload
@@ -74,7 +77,7 @@ def setup_credentials(options)
74
77
@aws_session_token = options [ :aws_session_token ]
75
78
@aws_credentials_expire_at = options [ :aws_credentials_expire_at ]
76
79
77
- @hmac = Fog ::HMAC . new ( 'sha256' , @aws_secret_access_key )
80
+ @signer = Fog ::AWS :: SignatureV4 . new ( @aws_access_key_id , @aws_secret_access_key , @region , 'ses' )
78
81
end
79
82
80
83
def request ( params )
@@ -87,20 +90,20 @@ def request(params)
87
90
'Content-Type' => 'application/x-www-form-urlencoded' ,
88
91
'Date' => Fog ::Time . now . to_date_header ,
89
92
}
90
- headers [ 'x-amz-security-token' ] = @aws_session_token if @aws_session_token
91
- #AWS3-HTTPS AWSAccessKeyId=<Your AWS Access Key ID>, Algorithm=HmacSHA256, Signature=<Signature>
92
- headers [ 'X-Amzn-Authorization' ] = 'AWS3-HTTPS '
93
- headers [ 'X-Amzn-Authorization' ] << 'AWSAccessKeyId=' << @aws_access_key_id
94
- headers [ 'X-Amzn-Authorization' ] << ', Algorithm=HmacSHA256'
95
- headers [ 'X-Amzn-Authorization' ] << ', Signature=' << Base64 . encode64 ( @hmac . sign ( headers [ 'Date' ] ) ) . chomp!
96
-
97
- body = ''
98
- for key in params . keys . sort
99
- unless ( value = params [ key ] ) . nil?
100
- body << " #{ key } = #{ CGI . escape ( value . to_s ) . gsub ( / \+ / , '%20' ) } &"
101
- end
102
- end
103
- body . chop! # remove trailing '&'
93
+
94
+ body , headers = AWS . signed_params_v4 (
95
+ params ,
96
+ { 'Content-Type' => 'application/x-www-form-urlencoded' } ,
97
+ {
98
+ :method => 'POST' ,
99
+ :aws_session_token => @aws_session_token ,
100
+ :signer => @signer ,
101
+ :host => @host ,
102
+ :path => @path ,
103
+ :port => @port ,
104
+ :version => '2010-12-01'
105
+ }
106
+ )
104
107
105
108
if @instrumentor
106
109
@instrumentor . instrument ( "#{ @instrumentor_name } .request" , params ) do
0 commit comments