superfaktura_api: raise exception when some credentials are not set

This commit is contained in:
Richard Kubíček
2025-01-16 14:10:07 +01:00
parent 5b2743a26a
commit 4cfaa2a03c
2 changed files with 7 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
setup( setup(
name='superfaktura_client', name='superfaktura_client',
version='0.0.1', version='0.0.2',
packages=find_namespace_packages(), packages=find_namespace_packages(),
url='https://github.com/eledio-helpers/superfaktura-client', url='https://github.com/eledio-helpers/superfaktura-client',
license='', license='',

View File

@@ -8,6 +8,9 @@ from dotenv import load_dotenv # type: ignore
class SuperFakturaAPIException(Exception): class SuperFakturaAPIException(Exception):
pass pass
class SuperFakturaAPIMissingCredentialsException(Exception):
pass
class SuperFakturaAPI: class SuperFakturaAPI:
def __init__(self) -> None: def __init__(self) -> None:
@@ -16,6 +19,9 @@ class SuperFakturaAPI:
self._api_url = os.getenv("SUPERFAKTURA_API_URL") self._api_url = os.getenv("SUPERFAKTURA_API_URL")
_api_mail = os.getenv("SUPERFAKTURA_API_EMAIL") _api_mail = os.getenv("SUPERFAKTURA_API_EMAIL")
_api_company_id = os.getenv("SUPERFAKTURA_API_COMPANY_ID") _api_company_id = os.getenv("SUPERFAKTURA_API_COMPANY_ID")
if not _api_key or not self._api_url or not _api_mail or not _api_company_id:
raise SuperFakturaAPIMissingCredentialsException('Please ensure, that necessary credentials are set. Please see README.md')
self._auth_header = { self._auth_header = {
"Authorization": f"SFAPI email={_api_mail}&apikey={_api_key}&company_id={_api_company_id}" "Authorization": f"SFAPI email={_api_mail}&apikey={_api_key}&company_id={_api_company_id}"
} }