Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Feature/aes signature #50

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
format code
  • Loading branch information
YoungWing committed Nov 9, 2022
commit 7f325dc4e8684841aa3510b642c60438001efcae
1 change: 1 addition & 0 deletions aftership/courier.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def detect_courier(tracking, **kwargs):
response = make_request('POST', 'couriers/detect', json=dict(tracking=tracking), **kwargs)
return process_response(response)


def post_orders(order, **kwargs):
response = make_request('POST', 'commerce/v1/orders', json=dict(order=json.loads(order)), **kwargs)
return process_response(response)
8 changes: 5 additions & 3 deletions aftership/hmac/hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import base64
import hmac


class Hmac():
def __init__(self, api_secret):
self.api_secret = api_secret

def hmac_signature(self, sign_string: str) -> str:
if self.api_secret is None:
self.api_secret = os.getenv('AFTERSHIP_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()
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: 1 addition & 1 deletion aftership/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from aftership.signstring.signstring import SignString

from .const import AFTERSHIP_API_KEY, API_ENDPOINT, API_VERSION, AS_SIGNATURE_HMAC_SHA256, AS_API_KEY, CONTENT_TYPE, SIGNATURE_AES_HMAC_SHA256
from .const import AFTERSHIP_API_KEY, API_ENDPOINT, AS_SIGNATURE_HMAC_SHA256, AS_API_KEY, CONTENT_TYPE, SIGNATURE_AES_HMAC_SHA256
from .util import get_api_key, get_api_secret


Expand Down
1 change: 1 addition & 0 deletions aftership/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get_api_key():
return aftership.api_key
return os.getenv('AFTERSHIP_API_KEY')


def get_api_secret():
"""Get AfterShip API secret"""
if aftership.api_secret is not None:
Expand Down