Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/aes signature #50

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Prev Previous commit
delete unused code
  • Loading branch information
YoungWing committed Nov 10, 2022
commit e3b7a34e4502b2d47f0c543ea3f328a1c9f88e9d
2 changes: 1 addition & 1 deletion aftership/hmac/hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, api_secret):

def hmac_signature(self, sign_string: str) -> str:
if self.api_secret is None:
self.api_secret = os.getenv('AFTERSHIP_API_SECRET')
self.api_secret = os.getenv('AS_API_SECRET')
signature_str = hmac.new(bytes(self.api_secret.encode()), msg=bytes(
sign_string.encode()), digestmod=hashlib.sha256).digest()
return base64.b64encode(signature_str).decode()
2 changes: 2 additions & 0 deletions aftership/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def request_with_aes_hmac256_signature(method, url, path, content_type, **kwargs
headers = kwargs.pop('headers', dict())
if headers.get(AS_API_KEY, None) is None:
headers[AS_API_KEY] = get_as_api_key()
if headers.get(AS_API_KEY, None) is None:
return

body = kwargs.get('json', None)
date, sign_string = gen_sign_string(method, path, body, headers, content_type)
Expand Down
2 changes: 1 addition & 1 deletion aftership/signstring/signstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _get_canonicalized_resource(self, raw_url: str) -> str:

def gen_sign_string(self, method: str, uri: str, body: str, as_header: dict, content_type: str) -> tuple:
# if self.api_secret is None:
# self.api_secret = os.getenv('AFTERSHIP_API_SECRET')
# self.api_secret = os.getenv('AS_API_SECRET')

canonicalized_as_headers = self._get_canonicalized_as_headers(as_header)
canonicalized_resource = self._get_canonicalized_resource(uri)
Expand Down