def _verify_boomi_licensing()

in functions/source/LicenseVerificationAndTokenGenerator/lambda_function.py [0:0]


def _verify_boomi_licensing(username, password, account):
    _headers = _create_auth_headers(username, password, account)
    API_URL = f"https://api.boomi.com/api/rest/v1/{account}/Account/{account}"
    resp = requests.get(API_URL, headers=_headers)
    resp.raise_for_status()
    json_resp = resp.json()

    account_status = json_resp['status']
    enterprise_licenses_purchased = json_resp['licensing']['enterprise']['purchased']
    enterprise_licenses_used = json_resp['licensing']['enterprise']['used']

    # Is the account active?
    if account_status == 'active':
        logger.info(f"Account is active")
    else:
        logger.error('Exception: Boomi account is inactive')
        raise Exception(f"Boomi account {account} is inactive.")

    # Do we have license entitelements at all?
    if enterprise_licenses_purchased > enterprise_licenses_used:
        logger.info(f"Licenses are available - Purchased: {enterprise_licenses_purchased} / Used: {enterprise_licenses_used}")
    else:
        logger.error('Exception: No enterprise license available')
        raise Exception(f"No enterprise licenses for account {account} are available. Purchased: {enterprise_licenses_purchased}, Used: {enterprise_licenses_used}")