Skip to content

Commit 77840b5

Browse files
committed
added support for new workspaces features
1 parent c67dd40 commit 77840b5

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

kbcstorage/branches.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,10 @@ def metadata(self, branch_id="default"):
4141

4242
url = f"{self.base_url}branch/{branch_id}/metadata"
4343
return self._get(url)
44+
45+
def branch_detail(self, branch_id="default"):
46+
"""
47+
Get branch details
48+
"""
49+
url = f"{self.base_url}dev-branches/{branch_id}"
50+
return self._get(url)

kbcstorage/workspaces.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def detail(self, workspace_id):
7272
url = '{}/{}'.format(self.base_url, workspace_id)
7373
return self._get(url)
7474

75-
def create(self, backend=None, timeout=None):
75+
def create(self, backend=None, timeout=None, login_type=None, public_key=None, read_all_objects=False):
7676
"""
7777
Create a new Workspace and return the credentials.
7878
@@ -87,7 +87,10 @@ def create(self, backend=None, timeout=None):
8787
"""
8888
body = {
8989
'backend': backend,
90-
'statementTimeoutSeconds': timeout
90+
'statementTimeoutSeconds': timeout,
91+
'loginType': login_type,
92+
'publicKey': public_key,
93+
'readOnlyStorageAccess': str(read_all_objects).lower()
9194
}
9295

9396
return self._post(self.base_url, data=body)
@@ -122,7 +125,17 @@ def reset_password(self, workspace_id):
122125
url = '{}/{}/password'.format(self.base_url, workspace_id)
123126
return self._post(url)
124127

125-
def load_tables(self, workspace_id, table_mapping, preserve=None):
128+
def set_public_key(self, workspace_id, public_key):
129+
"""
130+
Set the public key for the workspace.
131+
"""
132+
data = {
133+
'publicKey': public_key
134+
}
135+
url = '{}/{}/public-key'.format(self.base_url, workspace_id)
136+
return self._post(url, json=data)
137+
138+
def load_tables(self, workspace_id: int | str, table_mapping: dict | list[dict], preserve=True, load_type='load'):
126139
"""
127140
Load tabes from storage into a workspace.
128141
@@ -140,11 +153,23 @@ def load_tables(self, workspace_id, table_mapping, preserve=None):
140153
Todo:
141154
* Column data types.
142155
"""
143-
body = _make_body(table_mapping)
144-
body['preserve'] = preserve
145-
url = '{}/{}/load'.format(self.base_url, workspace_id)
156+
load_type = load_type.lower()
157+
if load_type not in ['load', 'load-clone']:
158+
raise ValueError("Invalid load_type: {}, supports only load and load-clone".format(load_type))
159+
160+
url = '{}/{}/{}'.format(self.base_url, workspace_id, load_type)
161+
162+
req = None
163+
if isinstance(table_mapping, dict):
164+
body = _make_body(table_mapping)
165+
body['preserve'] = str(preserve).lower()
166+
req = self._post(url, data=body)
167+
elif isinstance(table_mapping, list):
168+
body = {'input': table_mapping}
169+
body['preserve'] = str(preserve).lower()
170+
req = self._post(url, json=body)
146171

147-
return self._post(url, data=body)
172+
return req
148173

149174
def load_files(self, workspace_id, file_mapping):
150175
"""

0 commit comments

Comments
 (0)