-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (30 loc) · 1.12 KB
/
Copy pathutils.py
File metadata and controls
35 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#dependencies for hashing
import hashlib
import hmac
import base64
#dependencies for date formatting
from datetime import datetime
from email.utils import formatdate
def HMACSHA256Base64(apiSecretKey,message):
message = bytes(message, 'utf-8')
secret = bytes(apiSecretKey, 'utf-8')
signature = base64.b64encode(hmac.new(secret, message, digestmod=hashlib.sha256).digest())
signature=signature.decode()
return signature
def generate_headers(args,http_verb,resource_uri):
'''
formulate http headers
'''
cur_date= formatdate(timeval=None, localtime=False, usegmt=True)
cur_date_iso=datetime.utcnow().isoformat().split('.')[0]+"Z"
string_to_sign='\n'.join([http_verb,
'',
'',
cur_date_iso,
'/'.join([args.baseUrl,
resource_uri])])
signed_string=HMACSHA256Base64(args.apiSecretKey,string_to_sign)
headers={}
headers['Authorization']='AGS '+args.apiAccessKey+":"+signed_string
headers['Date']=cur_date
return headers