python3-core-api-client 0.1__py3-none-any.whl → 0.2__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.
- cyberfusion/CoreApiClient/connector.py +4 -7
- {python3_core_api_client-0.1.dist-info → python3_core_api_client-0.2.dist-info}/METADATA +40 -11
- {python3_core_api_client-0.1.dist-info → python3_core_api_client-0.2.dist-info}/RECORD +5 -5
- {python3_core_api_client-0.1.dist-info → python3_core_api_client-0.2.dist-info}/WHEEL +1 -1
- {python3_core_api_client-0.1.dist-info → python3_core_api_client-0.2.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,5 @@
|
|
1
1
|
import json
|
2
2
|
from typing import Optional, Tuple
|
3
|
-
from urllib.parse import urlparse
|
4
3
|
|
5
4
|
from cyberfusion.CoreApiClient._encoders import DatetimeEncoder
|
6
5
|
from cyberfusion.CoreApiClient.exceptions import CallException, AuthenticationException
|
@@ -17,7 +16,7 @@ import importlib.metadata
|
|
17
16
|
from cyberfusion.CoreApiClient.http import Response
|
18
17
|
|
19
18
|
|
20
|
-
class
|
19
|
+
class CoreApiClient:
|
21
20
|
def __init__(
|
22
21
|
self,
|
23
22
|
base_url: str = "https://core-api.cyberfusion.io",
|
@@ -50,10 +49,6 @@ class CoreApiConnector:
|
|
50
49
|
|
51
50
|
self.requests_session = requests_session or self.get_default_requests_session()
|
52
51
|
|
53
|
-
@property
|
54
|
-
def root_url(self) -> str:
|
55
|
-
return urlparse(self.base_url)._replace(path="").geturl()
|
56
|
-
|
57
52
|
@property
|
58
53
|
def authentication_headers(self) -> Dict[str, str]:
|
59
54
|
headers = {}
|
@@ -73,7 +68,7 @@ class CoreApiConnector:
|
|
73
68
|
|
74
69
|
if login:
|
75
70
|
response = self.requests_session.post(
|
76
|
-
"".join([self.
|
71
|
+
"".join([self.base_url, "/api/v1/login/access-token"]),
|
77
72
|
data={"username": self.username, "password": self.password},
|
78
73
|
verify=certifi.where(),
|
79
74
|
timeout=60,
|
@@ -181,6 +176,8 @@ class CoreApiConnector:
|
|
181
176
|
|
182
177
|
return session
|
183
178
|
|
179
|
+
|
180
|
+
class CoreApiConnector(CoreApiClient):
|
184
181
|
@cached_property
|
185
182
|
def login(self) -> resources.login.Login:
|
186
183
|
return resources.login.Login(self)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: python3-core-api-client
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2
|
4
4
|
Summary: Python client for Core API.
|
5
5
|
Author-email: Cyberfusion <support@cyberfusion.io>
|
6
6
|
Project-URL: Source, https://github.com/CyberfusionIO/python3-core-api-client
|
@@ -52,7 +52,7 @@ Refer to the [API documentation](https://core-api.cyberfusion.io/) for informati
|
|
52
52
|
|
53
53
|
Initialise the `CoreApiConnector` with your username and password **or** API key.
|
54
54
|
|
55
|
-
The connector takes care of authentication, and offers several resources (
|
55
|
+
The connector takes care of authentication, and offers several resources (e.g. `virtual_hosts`) and endpoints (e.g. `list_virtual_hosts`).
|
56
56
|
|
57
57
|
```python
|
58
58
|
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
@@ -78,7 +78,7 @@ This client takes care of authentication.
|
|
78
78
|
|
79
79
|
If authentication using username and password fails, `cyberfusion.CoreApiClient.exceptions.AuthenticationException` is thrown.
|
80
80
|
|
81
|
-
If authentication using API key fails, the regular `CallException` exception
|
81
|
+
If authentication using API key fails, the regular `CallException` exception is raised.
|
82
82
|
|
83
83
|
Don't have an API user? Contact Cyberfusion.
|
84
84
|
|
@@ -86,8 +86,6 @@ Don't have an API user? Contact Cyberfusion.
|
|
86
86
|
|
87
87
|
The client uses a fluent interface to build requests.
|
88
88
|
|
89
|
-
To view all possible requests:
|
90
|
-
|
91
89
|
- Start with the connector
|
92
90
|
- Go to the desired resource
|
93
91
|
- Call the desired endpoint
|
@@ -115,7 +113,7 @@ connector.mail_domains.create_mail_domain(
|
|
115
113
|
|
116
114
|
Models are validated before sending the request (using [Pydantic](https://docs.pydantic.dev/latest/)). If invalid data is provided, `pydantic.ValidationError` is thrown.
|
117
115
|
|
118
|
-
|
116
|
+
Code example:
|
119
117
|
|
120
118
|
```python
|
121
119
|
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
@@ -135,15 +133,44 @@ connector.mail_aliases.create_mail_alias(
|
|
135
133
|
# throw pydantic.ValidationError
|
136
134
|
```
|
137
135
|
|
138
|
-
The exception
|
136
|
+
The exception has an `errors()` method to get all validation errors.
|
137
|
+
|
138
|
+
Code example:
|
139
|
+
|
140
|
+
```python
|
141
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
142
|
+
|
143
|
+
from cyberfusion.CoreApiClient.models import MailAliasCreateRequest
|
144
|
+
|
145
|
+
import pydantic
|
146
|
+
|
147
|
+
connector = CoreApiConnector(
|
148
|
+
username='username', password='password'
|
149
|
+
)
|
150
|
+
|
151
|
+
try:
|
152
|
+
connector.mail_aliases.create_mail_alias(
|
153
|
+
MailAliasCreateRequest(
|
154
|
+
local_part='&^@$#^&@$#^&',
|
155
|
+
mail_domain_id=1,
|
156
|
+
)
|
157
|
+
)
|
158
|
+
except pydantic.ValidationError as e:
|
159
|
+
errors = e.errors()
|
160
|
+
|
161
|
+
for error in errors:
|
162
|
+
print(error['loc'])
|
163
|
+
print(error['msg'])
|
164
|
+
print(error['type'])
|
165
|
+
```
|
139
166
|
|
140
167
|
## Responses
|
141
168
|
|
142
169
|
### Get model from response
|
143
170
|
|
144
|
-
Calling
|
171
|
+
Calling an endpoint returns the resource model.
|
145
172
|
|
146
|
-
|
173
|
+
Code example:
|
147
174
|
|
148
175
|
```python
|
149
176
|
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
@@ -169,6 +196,8 @@ mail_domain_resource = connector.mail_domains.create_mail_domain(
|
|
169
196
|
|
170
197
|
If a request returns an unexpected HTTP status code, `cyberfusion.CoreApiClient.exceptions.CallException` is thrown.
|
171
198
|
|
199
|
+
The exception includes the response, and the HTTP status code.
|
200
|
+
|
172
201
|
## Enums
|
173
202
|
|
174
203
|
Some properties only accept certain values (enums).
|
@@ -191,7 +220,7 @@ connector = CoreApiConnector(
|
|
191
220
|
)
|
192
221
|
```
|
193
222
|
|
194
|
-
Don't pass a custom session? A default one is created,
|
223
|
+
Don't pass a custom session? A default one is created, with retries enabled.
|
195
224
|
|
196
225
|
### Manual requests
|
197
226
|
|
@@ -215,7 +244,7 @@ response.headers
|
|
215
244
|
response.failed
|
216
245
|
```
|
217
246
|
|
218
|
-
To raise `cyberfusion.CoreApiClient.exceptions.CallException` in case of an unexpected HTTP status code, use `send_or_fail`.
|
247
|
+
To raise `cyberfusion.CoreApiClient.exceptions.CallException` in case of an unexpected HTTP status code, use `send_or_fail` instead of `send`. It takes the same parameters.
|
219
248
|
|
220
249
|
### Generating models
|
221
250
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
cyberfusion/CoreApiClient/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
cyberfusion/CoreApiClient/_encoders.py,sha256=wyYUK_82h_hOPRvdxIzYta7Ek1TSSYMORR1QF1XfcRA,186
|
3
|
-
cyberfusion/CoreApiClient/connector.py,sha256=
|
3
|
+
cyberfusion/CoreApiClient/connector.py,sha256=ifnlovR-HiMfGXwIAoibFutXPV_iDWN-oGanu4GkhW4,12704
|
4
4
|
cyberfusion/CoreApiClient/exceptions.py,sha256=fNxPtzVL4SzPiVNZmBTu1l8D57dkCxMxflyIXDPLE4Q,204
|
5
5
|
cyberfusion/CoreApiClient/http.py,sha256=z6ZyfQyUnA3QDCmej2BEIw9BOlTYoCE8zvTZ0-u_VoQ,429
|
6
6
|
cyberfusion/CoreApiClient/interfaces.py,sha256=P0wCbmSNEpB-eF49PHudc_qXM4blIXm4TsD2AB0z_7Q,269
|
@@ -53,7 +53,7 @@ cyberfusion/CoreApiClient/resources/tombstones.py,sha256=AH7G23dD_I-qqmr98AmzsFD
|
|
53
53
|
cyberfusion/CoreApiClient/resources/unix_users.py,sha256=moqa5CjNSzueccMGms9mNhtUSDFw1UapWlB8QM6Agjk,3636
|
54
54
|
cyberfusion/CoreApiClient/resources/url_redirects.py,sha256=1Y386s9Bge8gBaXucSUBi1npNPPQpMLLVGXqVxA2YFM,2368
|
55
55
|
cyberfusion/CoreApiClient/resources/virtual_hosts.py,sha256=SAo6QPQGO-IJJCwW71zEEdA5FGdAn-6ADdn1iuA03wg,3716
|
56
|
-
python3_core_api_client-0.
|
57
|
-
python3_core_api_client-0.
|
58
|
-
python3_core_api_client-0.
|
59
|
-
python3_core_api_client-0.
|
56
|
+
python3_core_api_client-0.2.dist-info/METADATA,sha256=GiVOnEZmhURfOt4VbSlncbahgqS_u0XMrgEwGrgViJs,7022
|
57
|
+
python3_core_api_client-0.2.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
58
|
+
python3_core_api_client-0.2.dist-info/top_level.txt,sha256=ss011q9S6SL_KIIyq7iujFmIYa0grSjlnInO7cDkeag,12
|
59
|
+
python3_core_api_client-0.2.dist-info/RECORD,,
|
{python3_core_api_client-0.1.dist-info → python3_core_api_client-0.2.dist-info}/top_level.txt
RENAMED
File without changes
|