sumo-wrapper-python 0.3.4__tar.gz → 0.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sumo-wrapper-python might be problematic. Click here for more details.
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/.github/workflows/linting.yml +13 -13
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/.gitignore +1 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/PKG-INFO +1 -1
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/pyproject.toml +1 -1
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/requirements/requirements.txt +1 -1
- sumo-wrapper-python-0.3.5/src/sumo/wrapper/_blob_client.py +58 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/_call_azure_api.py +15 -15
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/_call_sumo_api.py +6 -2
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/sumo_client.py +244 -20
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/version.py +2 -2
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo_wrapper_python.egg-info/PKG-INFO +1 -1
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo_wrapper_python.egg-info/requires.txt +1 -1
- sumo-wrapper-python-0.3.4/src/sumo/wrapper/_blob_client.py +0 -30
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/.flake8 +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/.github/workflows/publish_release.yml +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/.github/workflows/pytest.yml +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/.readthedocs.yaml +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/LICENSE +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/README.md +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/conftest.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/docs/Makefile +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/docs/conf.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/docs/index.rst +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/docs/make.bat +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/requirements/requirements_docs.txt +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/requirements/requirements_test.txt +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/setup.cfg +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/setup.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/__init__.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/__init__.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/_auth.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/_logging.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/_new_auth.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/_request_error.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/config.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo/wrapper/login.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo_wrapper_python.egg-info/SOURCES.txt +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo_wrapper_python.egg-info/dependency_links.txt +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo_wrapper_python.egg-info/entry_points.txt +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo_wrapper_python.egg-info/not-zip-safe +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo_wrapper_python.egg-info/top_level.txt +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/tests/test_call_sumo_api.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/tests/test_sumo_thin_client.py +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/tests/testdata/case.yml +0 -0
- {sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/tests/testdata/surface.yml +0 -0
|
@@ -18,7 +18,7 @@ jobs:
|
|
|
18
18
|
python-version: ${{ matrix.python-version }}
|
|
19
19
|
- uses: psf/black@stable
|
|
20
20
|
with:
|
|
21
|
-
options: "--check --verbose --line-length
|
|
21
|
+
options: "--check --verbose --line-length 79"
|
|
22
22
|
src: "./src/sumo/wrapper"
|
|
23
23
|
flake8:
|
|
24
24
|
runs-on: ubuntu-latest
|
|
@@ -26,15 +26,15 @@ jobs:
|
|
|
26
26
|
matrix:
|
|
27
27
|
python-version: ["3.8"]
|
|
28
28
|
steps:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
- uses: actions/checkout@v3
|
|
30
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
31
|
+
uses: actions/setup-python@v3
|
|
32
|
+
with:
|
|
33
|
+
python-version: ${{ matrix.python-version }}
|
|
34
|
+
- name: Install dependencies
|
|
35
|
+
run: |
|
|
36
|
+
python -m pip install --upgrade pip
|
|
37
|
+
pip install flake8
|
|
38
|
+
- name: Analysing the code with flake8
|
|
39
|
+
run: |
|
|
40
|
+
flake8 src/sumo/wrapper --config .flake8
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
|
|
3
|
+
from ._request_error import raise_request_error_exception
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BlobClient:
|
|
7
|
+
"""Upload blobs to blob store using pre-authorized URLs"""
|
|
8
|
+
|
|
9
|
+
def upload_blob(self, blob: bytes, url: str):
|
|
10
|
+
"""Upload a blob.
|
|
11
|
+
|
|
12
|
+
Parameters:
|
|
13
|
+
blob: byte string to upload
|
|
14
|
+
url: pre-authorized URL to blob store
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
headers = {
|
|
18
|
+
"Content-Type": "application/octet-stream",
|
|
19
|
+
"Content-Length": str(len(blob)),
|
|
20
|
+
"x-ms-blob-type": "BlockBlob",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
response = httpx.put(url, data=blob, headers=headers)
|
|
25
|
+
except httpx.ProxyError as err:
|
|
26
|
+
raise_request_error_exception(503, err)
|
|
27
|
+
|
|
28
|
+
if response.is_error:
|
|
29
|
+
raise_request_error_exception(response.status_code, response.text)
|
|
30
|
+
|
|
31
|
+
return response
|
|
32
|
+
|
|
33
|
+
async def upload_blob_async(self, blob: bytes, url: str):
|
|
34
|
+
"""Upload a blob async.
|
|
35
|
+
|
|
36
|
+
Parameters:
|
|
37
|
+
blob: byte string to upload
|
|
38
|
+
url: pre-authorized URL to blob store
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
headers = {
|
|
42
|
+
"Content-Type": "application/octet-stream",
|
|
43
|
+
"Content-Length": str(len(blob)),
|
|
44
|
+
"x-ms-blob-type": "BlockBlob",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
async with httpx.AsyncClient() as client:
|
|
49
|
+
response = await client.put(
|
|
50
|
+
url=url, data=blob, headers=headers
|
|
51
|
+
)
|
|
52
|
+
except httpx.ProxyError as err:
|
|
53
|
+
raise_request_error_exception(503, err)
|
|
54
|
+
|
|
55
|
+
if response.is_error:
|
|
56
|
+
raise_request_error_exception(response.status_code, response.text)
|
|
57
|
+
|
|
58
|
+
return response
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import httpx
|
|
2
2
|
import logging
|
|
3
3
|
|
|
4
4
|
from ._auth import Auth
|
|
@@ -154,9 +154,9 @@ class CallAzureApi:
|
|
|
154
154
|
|
|
155
155
|
headers = {"Content-Type": "application/json", "Authorization": bearer}
|
|
156
156
|
|
|
157
|
-
response =
|
|
157
|
+
response = httpx.get(url, headers=headers)
|
|
158
158
|
|
|
159
|
-
if
|
|
159
|
+
if response.is_error:
|
|
160
160
|
_raise_request_error_exception(response.status_code, response.text)
|
|
161
161
|
|
|
162
162
|
return response.json()
|
|
@@ -182,9 +182,9 @@ class CallAzureApi:
|
|
|
182
182
|
|
|
183
183
|
headers = {"Content-Type": "html/text", "Authorization": bearer}
|
|
184
184
|
|
|
185
|
-
response =
|
|
185
|
+
response = httpx.get(url, headers=headers)
|
|
186
186
|
|
|
187
|
-
if
|
|
187
|
+
if response.is_error:
|
|
188
188
|
_raise_request_error_exception(response.status_code, response.text)
|
|
189
189
|
|
|
190
190
|
return None
|
|
@@ -210,9 +210,9 @@ class CallAzureApi:
|
|
|
210
210
|
|
|
211
211
|
headers = {"Content-Type": "application/json", "Authorization": bearer}
|
|
212
212
|
|
|
213
|
-
response =
|
|
213
|
+
response = httpx.get(url, headers=headers)
|
|
214
214
|
|
|
215
|
-
if
|
|
215
|
+
if response.is_error:
|
|
216
216
|
_raise_request_error_exception(response.status_code, response.text)
|
|
217
217
|
|
|
218
218
|
return response.content
|
|
@@ -249,11 +249,11 @@ class CallAzureApi:
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
try:
|
|
252
|
-
response =
|
|
253
|
-
except
|
|
252
|
+
response = httpx.post(url, data=blob, json=json, headers=headers)
|
|
253
|
+
except httpx.ProxyError as err:
|
|
254
254
|
_raise_request_error_exception(503, err)
|
|
255
255
|
|
|
256
|
-
if
|
|
256
|
+
if response.is_error:
|
|
257
257
|
_raise_request_error_exception(response.status_code, response.text)
|
|
258
258
|
|
|
259
259
|
return response
|
|
@@ -293,11 +293,11 @@ class CallAzureApi:
|
|
|
293
293
|
headers["Authorization"] = bearer
|
|
294
294
|
|
|
295
295
|
try:
|
|
296
|
-
response =
|
|
297
|
-
except
|
|
296
|
+
response = httpx.put(url, data=blob, json=json, headers=headers)
|
|
297
|
+
except httpx.ProxyError as err:
|
|
298
298
|
_raise_request_error_exception(503, err)
|
|
299
299
|
|
|
300
|
-
if
|
|
300
|
+
if response.is_error:
|
|
301
301
|
_raise_request_error_exception(response.status_code, response.text)
|
|
302
302
|
|
|
303
303
|
return response
|
|
@@ -321,9 +321,9 @@ class CallAzureApi:
|
|
|
321
321
|
"Authorization": bearer,
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
response =
|
|
324
|
+
response = httpx.delete(url, headers=headers)
|
|
325
325
|
|
|
326
|
-
if
|
|
326
|
+
if response.is_error:
|
|
327
327
|
_raise_request_error_exception(response.status_code, response.text)
|
|
328
328
|
|
|
329
329
|
return response.json()
|
|
@@ -30,7 +30,9 @@ class CallSumoApi:
|
|
|
30
30
|
self.base_url = f"https://main-sumo-{env}.radix.equinor.com/api/v1"
|
|
31
31
|
|
|
32
32
|
resource_id = (
|
|
33
|
-
resource_id
|
|
33
|
+
resource_id
|
|
34
|
+
if resource_id
|
|
35
|
+
else APP_REGISTRATION[env]["RESOURCE_ID"]
|
|
34
36
|
)
|
|
35
37
|
client_id = (
|
|
36
38
|
client_id if client_id else APP_REGISTRATION[env]["CLIENT_ID"]
|
|
@@ -224,7 +226,9 @@ class CallSumoApi:
|
|
|
224
226
|
Return
|
|
225
227
|
string: The object id of the newly created object, or error message.
|
|
226
228
|
"""
|
|
227
|
-
return self._post_objects(
|
|
229
|
+
return self._post_objects(
|
|
230
|
+
object_id=parent_id, json=json, bearer=bearer
|
|
231
|
+
)
|
|
228
232
|
|
|
229
233
|
def update_child_level_json(
|
|
230
234
|
self, json, object_id=None, url=None, bearer=None
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import jwt
|
|
3
|
-
import time
|
|
4
1
|
import logging
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
import jwt
|
|
5
6
|
|
|
6
|
-
from .config import APP_REGISTRATION, TENANT_ID
|
|
7
|
-
from ._new_auth import NewAuth
|
|
8
|
-
from ._request_error import raise_request_error_exception
|
|
9
7
|
from ._blob_client import BlobClient
|
|
10
8
|
from ._logging import LogHandlerSumo
|
|
9
|
+
from ._new_auth import NewAuth
|
|
10
|
+
from ._request_error import raise_request_error_exception
|
|
11
|
+
from .config import APP_REGISTRATION, TENANT_ID
|
|
11
12
|
|
|
12
13
|
logger = logging.getLogger("sumo.wrapper")
|
|
13
14
|
|
|
@@ -97,6 +98,10 @@ class SumoClient:
|
|
|
97
98
|
sumo = SumoClient("dev")
|
|
98
99
|
|
|
99
100
|
sumo.blob_client.upload_blob(blob, blob_url)
|
|
101
|
+
|
|
102
|
+
Uploading blob async::
|
|
103
|
+
|
|
104
|
+
await sumo.blob_client.upload_blob_async(blob, blob_url)
|
|
100
105
|
"""
|
|
101
106
|
|
|
102
107
|
return self._blob_client
|
|
@@ -190,13 +195,14 @@ class SumoClient:
|
|
|
190
195
|
"authorization": f"Bearer {token}",
|
|
191
196
|
}
|
|
192
197
|
|
|
193
|
-
response =
|
|
198
|
+
response = httpx.get(
|
|
194
199
|
f"{self.base_url}{path}",
|
|
195
200
|
params=self._process_params(params),
|
|
196
201
|
headers=headers,
|
|
202
|
+
follow_redirects=True,
|
|
197
203
|
)
|
|
198
204
|
|
|
199
|
-
if
|
|
205
|
+
if response.is_error:
|
|
200
206
|
raise_request_error_exception(response.status_code, response.text)
|
|
201
207
|
|
|
202
208
|
if "/blob" in path:
|
|
@@ -210,7 +216,7 @@ class SumoClient:
|
|
|
210
216
|
blob: bytes = None,
|
|
211
217
|
json: dict = None,
|
|
212
218
|
params: dict = None,
|
|
213
|
-
) ->
|
|
219
|
+
) -> httpx.Response:
|
|
214
220
|
"""Performs a POST-request to the Sumo API.
|
|
215
221
|
|
|
216
222
|
Takes either blob or json as a payload,
|
|
@@ -262,7 +268,7 @@ class SumoClient:
|
|
|
262
268
|
content_length = 0
|
|
263
269
|
|
|
264
270
|
if blob or json:
|
|
265
|
-
content_length = len(json) if json else len(blob)
|
|
271
|
+
content_length = len(str(json)) if json else len(blob)
|
|
266
272
|
|
|
267
273
|
headers = {
|
|
268
274
|
"Content-Type": content_type,
|
|
@@ -271,24 +277,24 @@ class SumoClient:
|
|
|
271
277
|
}
|
|
272
278
|
|
|
273
279
|
try:
|
|
274
|
-
response =
|
|
280
|
+
response = httpx.post(
|
|
275
281
|
f"{self.base_url}{path}",
|
|
276
282
|
data=blob,
|
|
277
283
|
json=json,
|
|
278
284
|
headers=headers,
|
|
279
285
|
params=params,
|
|
280
286
|
)
|
|
281
|
-
except
|
|
287
|
+
except httpx.ProxyError as err:
|
|
282
288
|
raise_request_error_exception(503, err)
|
|
283
289
|
|
|
284
|
-
if
|
|
290
|
+
if response.is_error:
|
|
285
291
|
raise_request_error_exception(response.status_code, response.text)
|
|
286
292
|
|
|
287
293
|
return response
|
|
288
294
|
|
|
289
295
|
def put(
|
|
290
296
|
self, path: str, blob: bytes = None, json: dict = None
|
|
291
|
-
) ->
|
|
297
|
+
) -> httpx.Response:
|
|
292
298
|
"""Performs a PUT-request to the Sumo API.
|
|
293
299
|
|
|
294
300
|
Takes either blob or json as a payload,
|
|
@@ -317,17 +323,17 @@ class SumoClient:
|
|
|
317
323
|
headers = {
|
|
318
324
|
"Content-Type": content_type,
|
|
319
325
|
"authorization": f"Bearer {token}",
|
|
320
|
-
"Content-Length": str(len(json) if json else len(blob)),
|
|
326
|
+
"Content-Length": str(len(str(json)) if json else len(blob)),
|
|
321
327
|
}
|
|
322
328
|
|
|
323
329
|
try:
|
|
324
|
-
response =
|
|
330
|
+
response = httpx.put(
|
|
325
331
|
f"{self.base_url}{path}", data=blob, json=json, headers=headers
|
|
326
332
|
)
|
|
327
|
-
except
|
|
333
|
+
except httpx.ProxyError as err:
|
|
328
334
|
raise_request_error_exception(503, err)
|
|
329
335
|
|
|
330
|
-
if
|
|
336
|
+
if response.is_error:
|
|
331
337
|
raise_request_error_exception(response.status_code, response.text)
|
|
332
338
|
|
|
333
339
|
return response
|
|
@@ -357,9 +363,9 @@ class SumoClient:
|
|
|
357
363
|
"Authorization": f"Bearer {token}",
|
|
358
364
|
}
|
|
359
365
|
|
|
360
|
-
response =
|
|
366
|
+
response = httpx.delete(f"{self.base_url}{path}", headers=headers)
|
|
361
367
|
|
|
362
|
-
if
|
|
368
|
+
if response.is_error:
|
|
363
369
|
raise_request_error_exception(response.status_code, response.text)
|
|
364
370
|
|
|
365
371
|
return response.json()
|
|
@@ -381,3 +387,221 @@ class SumoClient:
|
|
|
381
387
|
handler = LogHandlerSumo(self)
|
|
382
388
|
logger.addHandler(handler)
|
|
383
389
|
return logger
|
|
390
|
+
|
|
391
|
+
async def get_async(self, path: str, **params):
|
|
392
|
+
"""Performs an async GET-request to the Sumo API.
|
|
393
|
+
|
|
394
|
+
Args:
|
|
395
|
+
path: Path to a Sumo endpoint
|
|
396
|
+
params: Keyword arguments treated as query parameters
|
|
397
|
+
|
|
398
|
+
Returns:
|
|
399
|
+
Sumo JSON response as a dictionary
|
|
400
|
+
|
|
401
|
+
Examples:
|
|
402
|
+
Retrieving user data from Sumo::
|
|
403
|
+
|
|
404
|
+
sumo = SumoClient("dev")
|
|
405
|
+
|
|
406
|
+
userdata = await sumo.getAsync(path="/userdata")
|
|
407
|
+
|
|
408
|
+
Searching for cases::
|
|
409
|
+
|
|
410
|
+
sumo = SuomClient("dev")
|
|
411
|
+
|
|
412
|
+
cases = await sumo.getAsync(
|
|
413
|
+
path="/search",
|
|
414
|
+
query="class:case",
|
|
415
|
+
size=3
|
|
416
|
+
)
|
|
417
|
+
"""
|
|
418
|
+
token = self._retrieve_token()
|
|
419
|
+
|
|
420
|
+
headers = {
|
|
421
|
+
"Content-Type": "application/json",
|
|
422
|
+
"authorization": f"Bearer {token}",
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async with httpx.AsyncClient() as client:
|
|
426
|
+
response = await client.get(
|
|
427
|
+
f"{self.base_url}{path}",
|
|
428
|
+
params=self._process_params(params),
|
|
429
|
+
headers=headers,
|
|
430
|
+
)
|
|
431
|
+
|
|
432
|
+
if response.is_error:
|
|
433
|
+
raise_request_error_exception(response.status_code, response.text)
|
|
434
|
+
|
|
435
|
+
if "/blob" in path:
|
|
436
|
+
return response.content
|
|
437
|
+
|
|
438
|
+
return response.json()
|
|
439
|
+
|
|
440
|
+
async def post_async(
|
|
441
|
+
self,
|
|
442
|
+
path: str,
|
|
443
|
+
blob: bytes = None,
|
|
444
|
+
json: dict = None,
|
|
445
|
+
params: dict = None,
|
|
446
|
+
) -> httpx.Response:
|
|
447
|
+
"""Performs an async POST-request to the Sumo API.
|
|
448
|
+
|
|
449
|
+
Takes either blob or json as a payload,
|
|
450
|
+
will raise an error if both are provided.
|
|
451
|
+
|
|
452
|
+
Args:
|
|
453
|
+
path: Path to a Sumo endpoint
|
|
454
|
+
blob: Blob payload
|
|
455
|
+
json: Json payload
|
|
456
|
+
|
|
457
|
+
Returns:
|
|
458
|
+
Sumo response object
|
|
459
|
+
|
|
460
|
+
Raises:
|
|
461
|
+
ValueError: If both blob and json parameters have been provided
|
|
462
|
+
|
|
463
|
+
Examples:
|
|
464
|
+
Uploading case metadata::
|
|
465
|
+
|
|
466
|
+
case_metadata = {...}
|
|
467
|
+
sumo = SumoClient("dev")
|
|
468
|
+
|
|
469
|
+
new_case = await sumo.postAsync(
|
|
470
|
+
path="/objects",
|
|
471
|
+
json=case_metadata
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
new_case_id = new_case.json()["_id"]
|
|
475
|
+
|
|
476
|
+
Uploading object metadata::
|
|
477
|
+
|
|
478
|
+
object_metadata = {...}
|
|
479
|
+
sumo = SumoClient("dev")
|
|
480
|
+
|
|
481
|
+
new_objet = await sumo.postAsync(
|
|
482
|
+
path=f"/objects('{new_case_id}')",
|
|
483
|
+
json=object_metadata
|
|
484
|
+
)
|
|
485
|
+
"""
|
|
486
|
+
|
|
487
|
+
token = self._retrieve_token()
|
|
488
|
+
|
|
489
|
+
if blob and json:
|
|
490
|
+
raise ValueError("Both blob and json given to post.")
|
|
491
|
+
|
|
492
|
+
content_type = (
|
|
493
|
+
"application/octet-stream" if blob else "application/json"
|
|
494
|
+
)
|
|
495
|
+
content_length = 0
|
|
496
|
+
|
|
497
|
+
if blob or json:
|
|
498
|
+
content_length = len(str(json)) if json else len(blob)
|
|
499
|
+
|
|
500
|
+
headers = {
|
|
501
|
+
"Content-Type": content_type,
|
|
502
|
+
"authorization": f"Bearer {token}",
|
|
503
|
+
"Content-Length": str(content_length),
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
try:
|
|
507
|
+
async with httpx.AsyncClient() as client:
|
|
508
|
+
response = await client.post(
|
|
509
|
+
url=f"{self.base_url}{path}",
|
|
510
|
+
data=blob,
|
|
511
|
+
json=json,
|
|
512
|
+
headers=headers,
|
|
513
|
+
params=params,
|
|
514
|
+
)
|
|
515
|
+
except httpx.ProxyError as err:
|
|
516
|
+
raise_request_error_exception(503, err)
|
|
517
|
+
|
|
518
|
+
if response.is_error:
|
|
519
|
+
raise_request_error_exception(response.status_code, response.text)
|
|
520
|
+
|
|
521
|
+
return response
|
|
522
|
+
|
|
523
|
+
async def put_async(
|
|
524
|
+
self, path: str, blob: bytes = None, json: dict = None
|
|
525
|
+
) -> httpx.Response:
|
|
526
|
+
"""Performs an async PUT-request to the Sumo API.
|
|
527
|
+
|
|
528
|
+
Takes either blob or json as a payload,
|
|
529
|
+
will raise an error if both are provided.
|
|
530
|
+
|
|
531
|
+
Args:
|
|
532
|
+
path: Path to a Sumo endpoint
|
|
533
|
+
blob: Blob payload
|
|
534
|
+
json: Json payload
|
|
535
|
+
|
|
536
|
+
Returns:
|
|
537
|
+
Sumo response object
|
|
538
|
+
"""
|
|
539
|
+
|
|
540
|
+
token = self._retrieve_token()
|
|
541
|
+
|
|
542
|
+
if blob and json:
|
|
543
|
+
raise ValueError("Both blob and json given to post")
|
|
544
|
+
|
|
545
|
+
content_type = (
|
|
546
|
+
"application/json"
|
|
547
|
+
if json is not None
|
|
548
|
+
else "application/octet-stream"
|
|
549
|
+
)
|
|
550
|
+
|
|
551
|
+
headers = {
|
|
552
|
+
"Content-Type": content_type,
|
|
553
|
+
"authorization": f"Bearer {token}",
|
|
554
|
+
"Content-Length": str(len(str(json)) if json else len(blob)),
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
try:
|
|
558
|
+
async with httpx.AsyncClient() as client:
|
|
559
|
+
response = await client.put(
|
|
560
|
+
url=f"{self.base_url}{path}",
|
|
561
|
+
data=blob,
|
|
562
|
+
json=json,
|
|
563
|
+
headers=headers,
|
|
564
|
+
)
|
|
565
|
+
except httpx.ProxyError as err:
|
|
566
|
+
raise_request_error_exception(503, err)
|
|
567
|
+
|
|
568
|
+
if response.is_error:
|
|
569
|
+
raise_request_error_exception(response.status_code, response.text)
|
|
570
|
+
|
|
571
|
+
return response
|
|
572
|
+
|
|
573
|
+
async def delete_async(self, path: str) -> dict:
|
|
574
|
+
"""Performs an async DELETE-request to the Sumo API.
|
|
575
|
+
|
|
576
|
+
Args:
|
|
577
|
+
path: Path to a Sumo endpoint
|
|
578
|
+
|
|
579
|
+
Returns:
|
|
580
|
+
Sumo JSON resposne as a dictionary
|
|
581
|
+
|
|
582
|
+
Examples:
|
|
583
|
+
Deleting object::
|
|
584
|
+
|
|
585
|
+
object_id = ...
|
|
586
|
+
sumo = SumoClient("dev")
|
|
587
|
+
|
|
588
|
+
await sumo.deleteAsync(path=f"/objects('{object_id}')")
|
|
589
|
+
"""
|
|
590
|
+
|
|
591
|
+
token = self._retrieve_token()
|
|
592
|
+
|
|
593
|
+
headers = {
|
|
594
|
+
"Content-Type": "application/json",
|
|
595
|
+
"Authorization": f"Bearer {token}",
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
async with httpx.AsyncClient() as client:
|
|
599
|
+
response = await client.delete(
|
|
600
|
+
url=f"{self.base_url}{path}",
|
|
601
|
+
headers=headers,
|
|
602
|
+
)
|
|
603
|
+
|
|
604
|
+
if response.is_error:
|
|
605
|
+
raise_request_error_exception(response.status_code, response.text)
|
|
606
|
+
|
|
607
|
+
return response.json()
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
from ._request_error import raise_request_error_exception
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class BlobClient:
|
|
6
|
-
"""Upload blobs to blob store using pre-authorized URLs"""
|
|
7
|
-
|
|
8
|
-
def upload_blob(self, blob: bytes, url: str):
|
|
9
|
-
"""Upload a blob.
|
|
10
|
-
|
|
11
|
-
Parameters:
|
|
12
|
-
blob: byte string to upload
|
|
13
|
-
url: pre-authorized URL to blob store
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
headers = {
|
|
17
|
-
"Content-Type": "application/octet-stream",
|
|
18
|
-
"Content-Length": str(len(blob)),
|
|
19
|
-
"x-ms-blob-type": "BlockBlob",
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
try:
|
|
23
|
-
response = requests.put(url, data=blob, headers=headers)
|
|
24
|
-
except requests.exceptions.ProxyError as err:
|
|
25
|
-
raise_request_error_exception(503, err)
|
|
26
|
-
|
|
27
|
-
if not response.ok:
|
|
28
|
-
raise_request_error_exception(response.status_code, response.text)
|
|
29
|
-
|
|
30
|
-
return response
|
|
File without changes
|
{sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/.github/workflows/publish_release.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sumo-wrapper-python-0.3.4 → sumo-wrapper-python-0.3.5}/src/sumo_wrapper_python.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|