@@ -37,7 +37,7 @@ def doAuth(self, method, bucket, key, path_args, headers, expires=None):
37
37
}
38
38
39
39
def getSignature (self , method , bucket , key , path_args , headers , expires = None ):
40
- canonical_string = self .__make_canonicalstring (method , bucket , key , path_args , headers , expires )
40
+ canonical_string = self .__make_canonical_string (method , bucket , key , path_args , headers , expires )
41
41
return {
42
42
'Signature' : self .hmacSha128 (canonical_string ),
43
43
const .CANONICAL_STRING : canonical_string
@@ -53,10 +53,10 @@ def hmacSha128(self, canonical_string):
53
53
54
54
return encode_canonical
55
55
56
- def __make_canonicalstring (self , method , bucket_name , key , path_args , headers , expires = None ):
56
+ def __make_canonical_string (self , method , bucket_name , key , path_args , headers , expires = None ):
57
57
interesting_headers = self .__make_canonicalstring_interesting_headers (headers , expires )
58
- keylist = sorted (interesting_headers .keys ())
59
- str_list = self .__make_canonicalstring_str_list (keylist , method , interesting_headers )
58
+ key_list = sorted (interesting_headers .keys ())
59
+ str_list = self .__make_canonicalstring_str_list (key_list , method , interesting_headers )
60
60
URI = ''
61
61
_bucket_name = self .server if self .is_cname else bucket_name
62
62
if _bucket_name :
@@ -100,18 +100,18 @@ def __make_canonicalstring_interesting_headers(self, headers, expires):
100
100
s = headers .get (hash_key )
101
101
interesting_headers [lk ] = '' .join (s )
102
102
103
- keylist = interesting_headers .keys ()
103
+ key_list = interesting_headers .keys ()
104
104
105
- if self .ha .date_header () in keylist :
105
+ if self .ha .date_header () in key_list :
106
106
interesting_headers [const .DATE_HEADER .lower ()] = ''
107
107
108
108
if expires :
109
109
interesting_headers [const .DATE_HEADER .lower ()] = expires
110
110
111
- if const .CONTENT_TYPE_HEADER .lower () not in keylist :
111
+ if const .CONTENT_TYPE_HEADER .lower () not in key_list :
112
112
interesting_headers [const .CONTENT_TYPE_HEADER .lower ()] = ''
113
113
114
- if const .CONTENT_MD5_HEADER .lower () not in keylist :
114
+ if const .CONTENT_MD5_HEADER .lower () not in key_list :
115
115
interesting_headers [const .CONTENT_MD5_HEADER .lower ()] = ''
116
116
117
117
return interesting_headers
@@ -148,24 +148,25 @@ def doAuth(self, method, bucket, key, args_path, headers):
148
148
headers = headers if isinstance (headers , dict ) else {}
149
149
headers [self .ha .content_sha256_header ()] = self .CONTENT_SHA256
150
150
151
- credenttial = self .getCredenttial ()
151
+ credential = self .getCredential ()
152
152
headMap = self .setMapKeyLower (headers )
153
153
signedHeaders = self .getSignedHeaders (headMap )
154
154
ret = self .getSignature (method , bucket , key , args_path , headMap , signedHeaders )
155
155
auth = 'AWS4-HMAC-SHA256 Credential=%s,SignedHeaders=%s,Signature=%s' % (
156
- credenttial , signedHeaders , ret ['Signature' ])
156
+ credential , signedHeaders , ret ['Signature' ])
157
157
return {
158
158
const .AUTHORIZATION_HEADER : auth ,
159
159
const .CANONICAL_REQUEST : ret [const .CANONICAL_REQUEST ]
160
160
}
161
161
162
- def getCredenttial (self ):
162
+ def getCredential (self ):
163
163
return '%s/%s/%s/s3/aws4_request' % (self .ak , self .shortDate , self .region )
164
164
165
165
def getScope (self ):
166
166
return '%s/%s/s3/aws4_request' % (self .shortDate , self .region )
167
167
168
- def getSignedHeaders (self , headMap ):
168
+ @staticmethod
169
+ def getSignedHeaders (headMap ):
169
170
headList = sorted (headMap .items (), key = lambda d : d [0 ])
170
171
signedHeaders = ''
171
172
i = 0
@@ -194,7 +195,8 @@ def getSignature(self, method, bucket, key, args_path, headMap, signedHeaders, p
194
195
const .CANONICAL_REQUEST : cannonicalRequest
195
196
}
196
197
197
- def hmacSha256 (self , signingKey , stringToSign ):
198
+ @staticmethod
199
+ def hmacSha256 (signingKey , stringToSign ):
198
200
return hmac .new (signingKey , stringToSign , hashlib .sha256 ).hexdigest ()
199
201
200
202
def getSigningKey_python2 (self ):
@@ -222,10 +224,12 @@ def getCanonicalRequest(self, method, bucket, key, args_path, headMap, signedHea
222
224
output .append (self .CONTENT_SHA256 if payload is None else payload )
223
225
return '\n ' .join (output )
224
226
225
- def __shaCannonicalRequest_python2 (self , cannonicalRequest ):
227
+ @staticmethod
228
+ def __shaCannonicalRequest_python2 (cannonicalRequest ):
226
229
return hashlib .sha256 (cannonicalRequest ).hexdigest ()
227
230
228
- def __shaCannonicalRequest_python3 (self , cannonicalRequest ):
231
+ @staticmethod
232
+ def __shaCannonicalRequest_python3 (cannonicalRequest ):
229
233
return hashlib .sha256 (cannonicalRequest .encode ('UTF-8' )).hexdigest ()
230
234
231
235
def getCanonicalURI (self , bucket = None , key = None ):
@@ -238,7 +242,8 @@ def getCanonicalURI(self, bucket=None, key=None):
238
242
URI = '/'
239
243
return util .encode_object_key (URI )
240
244
241
- def getCanonicalQueryString (self , args_path ):
245
+ @staticmethod
246
+ def getCanonicalQueryString (args_path ):
242
247
canonMap = {}
243
248
for key , value in args_path .items ():
244
249
canonMap [key ] = value
@@ -252,7 +257,8 @@ def getCanonicalQueryString(self, args_path):
252
257
i = 1
253
258
return queryStr
254
259
255
- def getCanonicalHeaders (self , headMap ):
260
+ @staticmethod
261
+ def getCanonicalHeaders (headMap ):
256
262
headList = sorted (headMap .items (), key = lambda d : d [0 ])
257
263
canonicalHeaderStr = ''
258
264
for val in headList :
@@ -264,7 +270,8 @@ def getCanonicalHeaders(self, headMap):
264
270
canonicalHeaderStr += val [0 ] + ':' + str (val [1 ]) + '\n '
265
271
return canonicalHeaderStr
266
272
267
- def setMapKeyLower (self , inputMap ):
273
+ @staticmethod
274
+ def setMapKeyLower (inputMap ):
268
275
outputMap = {}
269
276
for key in inputMap .keys ():
270
277
outputMap [key .lower ()] = inputMap [key ]
0 commit comments