in git_remote_codecommit/__init__.py [0:0]
def sign(hostname, path, region, credentials):
"""
Provides a SigV4 signature for a CodeCommit url.
:param str hostname: aws hostname request is for
:param str path: resource the request is for
:param str region: region the repository resides within
:param botocore.credentials credentials: session credentials
:return: signature for the url
"""
request = botocore.awsrequest.AWSRequest(method = 'GIT', url = 'https://{}{}'.format(hostname, path))
request.context['timestamp'] = datetime.datetime.utcnow().strftime('%Y%m%dT%H%M%S')
signer = botocore.auth.SigV4Auth(credentials, 'codecommit', region)
canonical_request = 'GIT\n{}\n\nhost:{}\n\nhost\n'.format(path, hostname)
string_to_sign = signer.string_to_sign(request, canonical_request)
signature = signer.signature(string_to_sign, request)
return "{}Z{}".format(request.context['timestamp'], signature)