Skip to content

Commit af1421d

Browse files
author
Pedro Rodrigues
committed
use management.version when version is not passed
1 parent b473889 commit af1421d

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

singlestoredb/management/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def manage_cluster(
440440
access_token : str, optional
441441
The API key or other access token for the cluster management API
442442
version : str, optional
443-
Version of the API to use
443+
Version of the API to use (default: 'v1')
444444
base_url : str, optional
445445
Base URL of the cluster management API
446446
organization_id: str, optional

singlestoredb/management/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def manage_files(
534534
access_token : str, optional
535535
The API key or other access token for the files management API
536536
version : str, optional
537-
Version of the API to use
537+
Version of the API to use (default: 'v1')
538538
base_url : str, optional
539539
Base URL of the files management API
540540
organization_id : str, optional

singlestoredb/management/manager.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def is_jwt(token: str) -> bool:
4444
class Manager(object):
4545
"""SingleStoreDB manager base class."""
4646

47+
#: Management API version if none is specified.
48+
default_version = config.get_option('management.version') or 'v1'
49+
4750
#: Base URL if none is specified.
4851
default_base_url = config.get_option('management.base_url') \
4952
or 'https://api.singlestore.com'
@@ -52,7 +55,7 @@ class Manager(object):
5255
obj_type = ''
5356

5457
def __init__(
55-
self, access_token: Optional[str] = None, version: Optional[str] = 'v1',
58+
self, access_token: Optional[str] = None, version: Optional[str] = None,
5659
base_url: Optional[str] = None, *, organization_id: Optional[str] = None,
5760
):
5861
from .. import __version__ as client_version
@@ -62,6 +65,8 @@ def __init__(
6265
if not new_access_token:
6366
raise ManagementError(msg='No management token was configured.')
6467

68+
self.version = version or self.default_version
69+
6570
self._is_jwt = not access_token and new_access_token and is_jwt(new_access_token)
6671
self._sess = requests.Session()
6772
self._sess.headers.update({
@@ -71,13 +76,11 @@ def __init__(
7176
'User-Agent': f'SingleStoreDB-Python/{client_version}',
7277
})
7378

74-
self._base_url = ''.join([
79+
self._base_url = (
7580
base_url
7681
or config.get_option('management.base_url')
77-
or type(self).default_base_url,
78-
'/',
79-
])
80-
self._version = version
82+
or type(self).default_base_url
83+
) + '/'
8184
self._access_token = new_access_token
8285
self._params: Dict[str, str] = {}
8386
if organization_id:
@@ -89,7 +92,7 @@ def copy(self) -> 'Manager':
8992
new_manager._is_jwt = self._is_jwt
9093
new_manager._sess = deepcopy(self._sess)
9194
new_manager._base_url = self._base_url
92-
new_manager._version = self._version
95+
new_manager.version = self.version
9396
new_manager._access_token = self._access_token
9497
new_manager._params = deepcopy(self._params)
9598
return new_manager
@@ -98,7 +101,7 @@ def __getattr__(self, name: str) -> Any:
98101
"""Handle dynamic version attributes (v2, v3, etc.)."""
99102
if re.match(r'^v\d+[0-9a-z]*$', name):
100103
new_mgr = self.copy()
101-
new_mgr._version = name
104+
new_mgr.version = name
102105
return new_mgr
103106
return super().__getattribute__(name)
104107

@@ -323,8 +326,3 @@ def _wait_on_state(
323326
out = getattr(self, f'get_{self.obj_type}')(out.id)
324327

325328
return out
326-
327-
328-
class ManagerV2(Manager):
329-
"""V2 API implementation."""
330-
default_version = 'v2'

singlestoredb/management/region.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def manage_regions(
143143
access_token : str, optional
144144
The API key or other access token for the workspace management API
145145
version : str, optional
146-
Version of the API to use
146+
Version of the API to use (default: 'v1')
147147
base_url : str, optional
148148
Base URL of the workspace management API
149149

singlestoredb/management/workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,7 @@ def manage_workspaces(
19781978
access_token : str, optional
19791979
The API key or other access token for the workspace management API
19801980
version : str, optional
1981-
Version of the API to use
1981+
Version of the API to use (default is 'v1')
19821982
base_url : str, optional
19831983
Base URL of the workspace management API
19841984
organization_id : str, optional

0 commit comments

Comments
 (0)