in aliyun/log/auth.py [0:0]
def _do_sign_request(self, method, resource, params, headers, body, current_time):
credentials = self.credentials_provider.get_credentials()
if credentials.get_security_token():
headers['x-acs-security-token'] = credentials.get_security_token()
content_sha256 = sha256(body).hexdigest() \
if body else 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
headers['x-log-content-sha256'] = content_sha256
headers['x-log-date'] = current_time
current_date = current_time[:8]
canonical_headers = {}
signed_headers = ''
for original_key, value in headers.items():
key = original_key.lower()
if key == 'content-type' or key == 'host' or key.startswith('x-log-') or key.startswith('x-acs-'):
canonical_headers[key] = value
headers_to_string = ''
for key, value in sorted(canonical_headers.items()):
if len(signed_headers) > 0:
signed_headers += ';'
signed_headers += key
headers_to_string += key + ':' + value.strip() + '\n'
canonical_request = self.build_canonical_request(method, resource, params, headers_to_string,
signed_headers, content_sha256)
scope = current_date + '/' + self._region + '/sls/aliyun_v4_request'
string_to_sign = 'SLS4-HMAC-SHA256\n' \
+ current_time + '\n' \
+ scope + '\n' \
+ sha256(canonical_request.encode('utf-8')).hexdigest()
signature = self.build_sign_key(credentials.get_access_key_secret(),
self._region, current_date, string_to_sign)
return 'SLS4-HMAC-SHA256 Credential=%s/%s,Signature=%s' % (credentials.get_access_key_id(), scope, signature)