Skip to content

Commit 499972d

Browse files
Sync monorepo state at "Support data bulk upload of file to ExecuteMutator via S3 buckets" (#98)
1 parent 3dda011 commit 499972d

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.6.1
4+
5+
- Add SDK method for data import via ExecuteMutator
6+
37
## 1.6.0 - 25-03-2025
48

59
- Add methods to retrieve and set external OIDC issuers for a tenant

src/usercloudssdk/asyncclient.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,23 @@ async def GetExternalOIDCIssuersAsync(self) -> list[str]:
969969
async def UpdateExternalOIDCIssuersAsync(self, issuers: list[str]) -> list[str]:
970970
return await self._put_async("/userstore/oidcissuers", json_data=issuers)
971971

972+
async def UploadDataImportFileAsync(
973+
self, file_path: Path, import_type: str = "executemutator"
974+
) -> uuid.UUID:
975+
json_data = await self._get_async(
976+
f"/userstore/upload/dataimport?import_type={import_type}"
977+
)
978+
import_id = uuid.UUID(json_data["import_id"])
979+
with open(file_path, "rb") as f:
980+
resp = await self._client.put_async(json_data["presigned_url"], content=f)
981+
if resp.status_code >= 400:
982+
raise UserCloudsSDKError.from_response(resp)
983+
return import_id
984+
985+
async def CheckDataImportStatusAsync(self, import_id: uuid.UUID) -> dict:
986+
json_data = await self._get_async(f"/userstore/upload/dataimport/{import_id}")
987+
return json_data
988+
972989
# Access Token Helpers
973990

974991
async def _get_access_token_async(self) -> str:

src/usercloudssdk/client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,21 @@ def GetExternalOIDCIssuers(self) -> list[str]:
929929
def UpdateExternalOIDCIssuers(self, issuers: list[str]) -> list[str]:
930930
return self._put("/userstore/oidcissuers", json_data=issuers)
931931

932+
def UploadDataImportFile(
933+
self, file_path: Path, import_type: str = "executemutator"
934+
) -> uuid.UUID:
935+
json_data = self._get(f"/userstore/upload/dataimport?import_type={import_type}")
936+
import_id = uuid.UUID(json_data["import_id"])
937+
with open(file_path, "rb") as f:
938+
resp = self._client.put(json_data["presigned_url"], content=f)
939+
if resp.status_code >= 400:
940+
raise UserCloudsSDKError.from_response(resp)
941+
return import_id
942+
943+
def CheckDataImportStatus(self, import_id: uuid.UUID) -> dict:
944+
json_data = self._get(f"/userstore/upload/dataimport/{import_id}")
945+
return json_data
946+
932947
# Access Token Helpers
933948

934949
def _get_access_token(self) -> str:

src/usercloudssdk/ucjson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def serializer(obj):
1717

1818

1919
def loads(data: str) -> dict:
20-
return json.loads(data)
20+
return json.loads(data) if data else {}
2121

2222

2323
def dumps(data: dict) -> str:

tools/genasyncclient.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,24 @@ async def _download_async(self, url) -> str:
213213
)
214214
# replace self._get with await self._get_async
215215
line = re.sub(r"\sself\._get\(", r" await self._get_async(", line)
216+
# replace self._client.get with await self._client.get_async
217+
line = re.sub(r"\sself\._client.get\(", r" await self._client.get_async(", line)
216218
# replace self._post with await self._post_async
217219
line = re.sub(r"\sself\._post\(", r" await self._post_async(", line)
220+
# replace self._client.post with await self._client.post_async
221+
line = re.sub(
222+
r"\sself\._client.post\(", r" await self._client.post_async(", line
223+
)
218224
# replace self._put with await self._put_async
219225
line = re.sub(r"\sself\._put\(", r" await self._put_async(", line)
226+
# replace self._client.put with await self._client.put_async
227+
line = re.sub(r"\sself\._client.put\(", r" await self._client.put_async(", line)
220228
# replace self._delete with await self._delete_async
221229
line = re.sub(r"\sself\._delete\(", r" await self._delete_async(", line)
230+
# replace self._client.delete with await self._client.delete_async
231+
line = re.sub(
232+
r"\sself\._client.delete\(", r" await self._client.delete_async(", line
233+
)
222234
# replace self._download with await self._download_async
223235
line = re.sub(r"\sself\._download\(", r" await self._download_async(", line)
224236
# replace self._download with await self._download_async

0 commit comments

Comments
 (0)