cecil 0.0.13__py3-none-any.whl → 0.0.15__py3-none-any.whl
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 cecil might be problematic. Click here for more details.
- cecil/__init__.py +1 -0
- cecil/client.py +36 -12
- cecil/errors.py +62 -0
- {cecil-0.0.13.dist-info → cecil-0.0.15.dist-info}/METADATA +1 -1
- cecil-0.0.15.dist-info/RECORD +8 -0
- cecil-0.0.13.dist-info/RECORD +0 -7
- {cecil-0.0.13.dist-info → cecil-0.0.15.dist-info}/WHEEL +0 -0
- {cecil-0.0.13.dist-info → cecil-0.0.15.dist-info}/licenses/LICENSE.txt +0 -0
cecil/__init__.py
CHANGED
cecil/client.py
CHANGED
|
@@ -6,6 +6,13 @@ import snowflake.connector
|
|
|
6
6
|
from pydantic import BaseModel
|
|
7
7
|
from requests import auth
|
|
8
8
|
|
|
9
|
+
from .errors import (
|
|
10
|
+
Error,
|
|
11
|
+
_handle_bad_request,
|
|
12
|
+
_handle_not_found,
|
|
13
|
+
_handle_unprocessable_entity,
|
|
14
|
+
)
|
|
15
|
+
|
|
9
16
|
from .models import (
|
|
10
17
|
AOI,
|
|
11
18
|
AOICreate,
|
|
@@ -21,7 +28,7 @@ from .models import (
|
|
|
21
28
|
)
|
|
22
29
|
|
|
23
30
|
# TODO: find a way to get this version from __about__.py
|
|
24
|
-
SDK_VERSION = "0.0.
|
|
31
|
+
SDK_VERSION = "0.0.15"
|
|
25
32
|
|
|
26
33
|
# TODO: Documentation (Google style)
|
|
27
34
|
# TODO: Add HTTP retries
|
|
@@ -106,6 +113,7 @@ class Client:
|
|
|
106
113
|
res = self._post(
|
|
107
114
|
url=f"/v0/recover-api-key",
|
|
108
115
|
model=RecoverAPIKeyRequest(email=email),
|
|
116
|
+
skip_auth=True,
|
|
109
117
|
)
|
|
110
118
|
|
|
111
119
|
return RecoverAPIKey(**res)
|
|
@@ -115,9 +123,10 @@ class Client:
|
|
|
115
123
|
|
|
116
124
|
return RotateAPIKey(**res)
|
|
117
125
|
|
|
118
|
-
def _request(self, method: str, url: str, **kwargs) -> Dict:
|
|
126
|
+
def _request(self, method: str, url: str, skip_auth=False, **kwargs) -> Dict:
|
|
119
127
|
|
|
120
|
-
|
|
128
|
+
if skip_auth is False:
|
|
129
|
+
self._set_auth()
|
|
121
130
|
|
|
122
131
|
headers = {"cecil-python-sdk-version": SDK_VERSION}
|
|
123
132
|
|
|
@@ -133,21 +142,36 @@ class Client:
|
|
|
133
142
|
r.raise_for_status()
|
|
134
143
|
return r.json()
|
|
135
144
|
|
|
136
|
-
except requests.exceptions.ConnectionError
|
|
137
|
-
raise
|
|
145
|
+
except requests.exceptions.ConnectionError:
|
|
146
|
+
raise Error("failed to connect to the Cecil Platform")
|
|
138
147
|
except requests.exceptions.HTTPError as err:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
match err.response.status_code:
|
|
149
|
+
case 400:
|
|
150
|
+
_handle_bad_request(err.response)
|
|
151
|
+
case 401:
|
|
152
|
+
raise Error("unauthorised")
|
|
153
|
+
case 404:
|
|
154
|
+
_handle_not_found(err.response)
|
|
155
|
+
case 422:
|
|
156
|
+
_handle_unprocessable_entity(err.response)
|
|
157
|
+
case 500:
|
|
158
|
+
raise Error("internal server error")
|
|
159
|
+
case _:
|
|
160
|
+
raise Error(
|
|
161
|
+
f"request failed with code {err.response.status_code}",
|
|
162
|
+
err.response.text,
|
|
163
|
+
)
|
|
144
164
|
|
|
145
165
|
def _get(self, url: str, **kwargs) -> Dict:
|
|
146
166
|
return self._request(method="get", url=url, **kwargs)
|
|
147
167
|
|
|
148
|
-
def _post(self, url: str, model: BaseModel, **kwargs) -> Dict:
|
|
168
|
+
def _post(self, url: str, model: BaseModel, skip_auth=False, **kwargs) -> Dict:
|
|
149
169
|
return self._request(
|
|
150
|
-
method="post",
|
|
170
|
+
method="post",
|
|
171
|
+
url=url,
|
|
172
|
+
json=model.model_dump(by_alias=True),
|
|
173
|
+
skip_auth=skip_auth,
|
|
174
|
+
**kwargs,
|
|
151
175
|
)
|
|
152
176
|
|
|
153
177
|
def _set_auth(self) -> None:
|
cecil/errors.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Error(Exception):
|
|
5
|
+
def __init__(self, message: str, details=None):
|
|
6
|
+
self.message = message
|
|
7
|
+
self.details = details
|
|
8
|
+
|
|
9
|
+
if self.details is not None:
|
|
10
|
+
super().__init__(f"{self.message} \n{json.dumps(self.details, indent=2)}")
|
|
11
|
+
return
|
|
12
|
+
|
|
13
|
+
super().__init__(self.message)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _format_json_key(value: str):
|
|
17
|
+
return "".join(["_" + i.lower() if i.isupper() else i for i in value]).lstrip("_")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _is_json(value: str):
|
|
21
|
+
try:
|
|
22
|
+
json.loads(value)
|
|
23
|
+
return True
|
|
24
|
+
except ValueError:
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _handle_bad_request(response):
|
|
29
|
+
if not _is_json(response.text):
|
|
30
|
+
raise Error("bad request")
|
|
31
|
+
|
|
32
|
+
details = {}
|
|
33
|
+
for key, value in response.json().items():
|
|
34
|
+
details[_format_json_key(key)] = value
|
|
35
|
+
|
|
36
|
+
raise Error("bad request", details)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _handle_not_found(response):
|
|
40
|
+
if not _is_json(response.text):
|
|
41
|
+
raise Error("resource not found")
|
|
42
|
+
|
|
43
|
+
details = {}
|
|
44
|
+
for key, value in response.json().items():
|
|
45
|
+
details[_format_json_key(key)] = value
|
|
46
|
+
|
|
47
|
+
raise Error("resource not found", details)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _handle_unprocessable_entity(response):
|
|
51
|
+
if not _is_json(response.text):
|
|
52
|
+
raise Error(f"failed to process request")
|
|
53
|
+
|
|
54
|
+
res_body = response.json()
|
|
55
|
+
if "params" not in res_body:
|
|
56
|
+
raise Error(f"failed to process request")
|
|
57
|
+
|
|
58
|
+
details = {}
|
|
59
|
+
for key, value in res_body["params"].items():
|
|
60
|
+
details[_format_json_key(key)] = value
|
|
61
|
+
|
|
62
|
+
raise Error(f"failed to process request", details)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
cecil/__init__.py,sha256=9-O5DAnOHvBuzPAjkK10GiOnCY9rb4SW1k0CIrHorr0,53
|
|
2
|
+
cecil/client.py,sha256=4ft1FL6KePfleTf-oepi10yRJ3RdVeZ0qNRdFyLm6c8,5783
|
|
3
|
+
cecil/errors.py,sha256=r9NNRtv_oO_hblnh-VOlAf767cJqmlnbJfHB63OA_zY,1538
|
|
4
|
+
cecil/models.py,sha256=6p9AedCDdkK-ptK2r5pc9AKG8rgZHw-YYDvRgXPAQqI,2544
|
|
5
|
+
cecil-0.0.15.dist-info/METADATA,sha256=wnQowxMqcWRjlNsThxwypFnck_TuDDFmNCzZr34_Y54,2677
|
|
6
|
+
cecil-0.0.15.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
7
|
+
cecil-0.0.15.dist-info/licenses/LICENSE.txt,sha256=mUexcmfYx3bG1VIzAdQTOf_NzStYw6-QkKVdUY_d4i4,1066
|
|
8
|
+
cecil-0.0.15.dist-info/RECORD,,
|
cecil-0.0.13.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
cecil/__init__.py,sha256=MF64bwUCd4sm3dvcxZnkb4ujHtxT_KeuXdD0nVieEt4,27
|
|
2
|
-
cecil/client.py,sha256=wgEYWuTZeJv81oiCoNU0rUrDlwnXI1sQFiLLa51BvyI,5070
|
|
3
|
-
cecil/models.py,sha256=6p9AedCDdkK-ptK2r5pc9AKG8rgZHw-YYDvRgXPAQqI,2544
|
|
4
|
-
cecil-0.0.13.dist-info/METADATA,sha256=6Py3ar6ZlMOwaX3zo4TScat1uvcZk2jSECFc8CXmBZM,2677
|
|
5
|
-
cecil-0.0.13.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
6
|
-
cecil-0.0.13.dist-info/licenses/LICENSE.txt,sha256=mUexcmfYx3bG1VIzAdQTOf_NzStYw6-QkKVdUY_d4i4,1066
|
|
7
|
-
cecil-0.0.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|