diff --git a/api/organisations/subscriptions/licensing/helpers.py b/api/organisations/subscriptions/licensing/helpers.py index b86687753985..9cf8e2eb65ef 100644 --- a/api/organisations/subscriptions/licensing/helpers.py +++ b/api/organisations/subscriptions/licensing/helpers.py @@ -9,9 +9,16 @@ logger: logging.Logger = logging.getLogger(name=__name__) +class PrivateKeyMissingError(RuntimeError): + pass + + def sign_licence(licence: str) -> str: message = licence.encode("utf-8") + if not settings.SUBSCRIPTION_LICENCE_PRIVATE_KEY: + raise PrivateKeyMissingError("Private key is missing") + # Load the private key from PEM private_key = serialization.load_pem_private_key( settings.SUBSCRIPTION_LICENCE_PRIVATE_KEY.encode("utf-8"), password=None