Skip to content

Commit 5e1c2bd

Browse files
committed
Make base URL more dynamic
1 parent c90e412 commit 5e1c2bd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

singlestoredb/management/manager.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
)
6363
if not new_access_token:
6464
raise ManagementError(msg='No management token was configured.')
65+
6566
self._is_jwt = not access_token and new_access_token and is_jwt(new_access_token)
6667
self._sess = requests.Session()
6768
self._sess.headers.update({
@@ -70,10 +71,25 @@ def __init__(
7071
'Accept': 'application/json',
7172
'User-Agent': f'SingleStoreDB-Python/{client_version}',
7273
})
74+
75+
# The base URL must be able to be set dynamically using the default_base_url
76+
# class variable or the environment variable SINGLESTOREDB_MANAGEMENT_BASE_URL.
77+
# Check to see if the current default_base_url or the environment variable
78+
# is different from the default_base_url and use that if so.
79+
config_base_url = config.get_option('management.base_url')
80+
env_base_url = os.environ.get('SINGLESTOREDB_MANAGEMENT_BASE_URL', '').strip()
81+
if base_url:
82+
pass
83+
elif config_base_url and config_base_url != type(self).default_base_url:
84+
base_url = config_base_url
85+
elif env_base_url and env_base_url != type(self).default_base_url:
86+
base_url = env_base_url
87+
7388
self._base_url = urljoin(
7489
base_url or type(self).default_base_url,
7590
version or type(self).default_version,
7691
) + '/'
92+
7793
self._params: Dict[str, str] = {}
7894
if organization_id:
7995
self._params['organizationID'] = organization_id

0 commit comments

Comments
 (0)