enpi_api.l2.util.client
1from enpi_api.l1 import openapi_client 2from enpi_api.l2.util.env import get_api_host, get_api_key 3 4 5class ApiHostNotSet(Exception): 6 """Raised when `ENPI_API_HOST` is not set as an environment variable.""" 7 8 def __init__(self) -> None: 9 """@private""" 10 super().__init__("Must set either ENPI_API_HOST environment variable.") 11 12 13class ApiKeyNotSet(Exception): 14 """Raised when `ENPI_API_KEY` is not as an environment variable or passed as an argument to the client.""" 15 16 def __init__(self) -> None: 17 """@private""" 18 super().__init__("Must set either ENPI_API_KEY environment variable or pass it as an argument.") 19 20 21def get_configuration(api_key: str | None = None) -> openapi_client.Configuration: 22 host = get_api_host() 23 if host is None: 24 raise ApiHostNotSet() 25 26 if api_key is None: 27 api_key = get_api_key() 28 if api_key is None: 29 raise ApiKeyNotSet() 30 return openapi_client.Configuration(host=host, api_key=dict(enpiApiKey=api_key)) 31 32 33def get_client(api_key: str | None = None) -> openapi_client.ApiClient: 34 return openapi_client.ApiClient(get_configuration(api_key))
class
ApiHostNotSet(builtins.Exception):
6class ApiHostNotSet(Exception): 7 """Raised when `ENPI_API_HOST` is not set as an environment variable.""" 8 9 def __init__(self) -> None: 10 """@private""" 11 super().__init__("Must set either ENPI_API_HOST environment variable.")
Raised when ENPI_API_HOST is not set as an environment variable.
class
ApiKeyNotSet(builtins.Exception):
14class ApiKeyNotSet(Exception): 15 """Raised when `ENPI_API_KEY` is not as an environment variable or passed as an argument to the client.""" 16 17 def __init__(self) -> None: 18 """@private""" 19 super().__init__("Must set either ENPI_API_KEY environment variable or pass it as an argument.")
Raised when ENPI_API_KEY is not as an environment variable or passed as an argument to the client.
def
get_configuration( api_key: str | None = None) -> enpi_api.l1.openapi_client.configuration.Configuration:
22def get_configuration(api_key: str | None = None) -> openapi_client.Configuration: 23 host = get_api_host() 24 if host is None: 25 raise ApiHostNotSet() 26 27 if api_key is None: 28 api_key = get_api_key() 29 if api_key is None: 30 raise ApiKeyNotSet() 31 return openapi_client.Configuration(host=host, api_key=dict(enpiApiKey=api_key))
def
get_client( api_key: str | None = None) -> enpi_api.l1.openapi_client.api_client.ApiClient: