diff --git a/arkindex/__init__.py b/arkindex/__init__.py index b96c6b5223e58e19add4b9ea42664ef9542c8a6c..cf78c2e3655b7d8e5337c7529887e683be8b5a2c 100644 --- a/arkindex/__init__.py +++ b/arkindex/__init__.py @@ -1 +1 @@ -from arkindex.client import ArkindexClient # noqa: F401 +from arkindex.client import ArkindexClient, options_from_env # noqa: F401 diff --git a/arkindex/client.py b/arkindex/client.py index d1d843becbf99cde5a055fdc4f5bd345a6ad1e3d..c93b72a44afe0c01456be1ee68f1b557450934fb 100644 --- a/arkindex/client.py +++ b/arkindex/client.py @@ -1,7 +1,7 @@ """ Arkindex API Client """ -import os.path +import os import apistar import logging import yaml @@ -16,6 +16,22 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__)) logger = logging.getLogger(__name__) +def options_from_env(): + """ + Get API client keyword arguments from environment variables. + """ + options = {} + if 'ARKINDEX_API_TOKEN' in os.environ: + options['token'] = os.environ.get('ARKINDEX_API_TOKEN') + + if 'ARKINDEX_API_INTERNAL_URL' in os.environ: + options['base_url'] = os.environ.get('ARKINDEX_API_INTERNAL_URL') + elif 'ARKINDEX_API_URL' in os.environ: + options['base_url'] = os.environ.get('ARKINDEX_API_URL') + + return options + + class ArkindexClient(apistar.Client): """ An Arkindex API client.