python3-core-api-client 0.1__tar.gz → 0.3__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.
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/PKG-INFO +40 -11
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/README.md +39 -10
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/pyproject.toml +1 -1
- python3_core_api_client-0.3/src/cyberfusion/CoreApiClient/_encoders.py +14 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/connector.py +7 -10
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/python3_core_api_client.egg-info/PKG-INFO +40 -11
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/_encoders.py +0 -7
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/setup.cfg +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/__init__.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/exceptions.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/http.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/interfaces.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/models.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/__init__.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/basic_authentication_realms.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/borg_archives.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/borg_repositories.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/certificate_managers.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/certificates.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/clusters.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/cmses.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/crons.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/custom_config_snippets.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/custom_configs.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/customers.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/daemons.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/database_user_grants.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/database_users.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/databases.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/domain_routers.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/firewall_groups.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/firewall_rules.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/fpm_pools.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/ftp_users.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/haproxy_listens.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/haproxy_listens_to_nodes.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/health.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/hosts_entries.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/htpasswd_files.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/htpasswd_users.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/login.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/logs.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/mail_accounts.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/mail_aliases.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/mail_domains.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/mail_hostnames.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/malwares.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/mariadb_encryption_keys.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/node_add_ons.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/nodes.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/passenger_apps.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/redis_instances.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/root_ssh_keys.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/security_txt_policies.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/sites.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/ssh_keys.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/task_collections.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/tombstones.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/unix_users.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/url_redirects.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/resources/virtual_hosts.py +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/python3_core_api_client.egg-info/SOURCES.txt +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/python3_core_api_client.egg-info/dependency_links.txt +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/python3_core_api_client.egg-info/requires.txt +0 -0
- {python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/python3_core_api_client.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: python3-core-api-client
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3
|
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
|
|
@@ -41,7 +41,7 @@ Refer to the [API documentation](https://core-api.cyberfusion.io/) for informati
|
|
41
41
|
|
42
42
|
Initialise the `CoreApiConnector` with your username and password **or** API key.
|
43
43
|
|
44
|
-
The connector takes care of authentication, and offers several resources (
|
44
|
+
The connector takes care of authentication, and offers several resources (e.g. `virtual_hosts`) and endpoints (e.g. `list_virtual_hosts`).
|
45
45
|
|
46
46
|
```python
|
47
47
|
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
@@ -67,7 +67,7 @@ This client takes care of authentication.
|
|
67
67
|
|
68
68
|
If authentication using username and password fails, `cyberfusion.CoreApiClient.exceptions.AuthenticationException` is thrown.
|
69
69
|
|
70
|
-
If authentication using API key fails, the regular `CallException` exception
|
70
|
+
If authentication using API key fails, the regular `CallException` exception is raised.
|
71
71
|
|
72
72
|
Don't have an API user? Contact Cyberfusion.
|
73
73
|
|
@@ -75,8 +75,6 @@ Don't have an API user? Contact Cyberfusion.
|
|
75
75
|
|
76
76
|
The client uses a fluent interface to build requests.
|
77
77
|
|
78
|
-
To view all possible requests:
|
79
|
-
|
80
78
|
- Start with the connector
|
81
79
|
- Go to the desired resource
|
82
80
|
- Call the desired endpoint
|
@@ -104,7 +102,7 @@ connector.mail_domains.create_mail_domain(
|
|
104
102
|
|
105
103
|
Models are validated before sending the request (using [Pydantic](https://docs.pydantic.dev/latest/)). If invalid data is provided, `pydantic.ValidationError` is thrown.
|
106
104
|
|
107
|
-
|
105
|
+
Code example:
|
108
106
|
|
109
107
|
```python
|
110
108
|
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
@@ -124,15 +122,44 @@ connector.mail_aliases.create_mail_alias(
|
|
124
122
|
# throw pydantic.ValidationError
|
125
123
|
```
|
126
124
|
|
127
|
-
The exception
|
125
|
+
The exception has an `errors()` method to get all validation errors.
|
126
|
+
|
127
|
+
Code example:
|
128
|
+
|
129
|
+
```python
|
130
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
131
|
+
|
132
|
+
from cyberfusion.CoreApiClient.models import MailAliasCreateRequest
|
133
|
+
|
134
|
+
import pydantic
|
135
|
+
|
136
|
+
connector = CoreApiConnector(
|
137
|
+
username='username', password='password'
|
138
|
+
)
|
139
|
+
|
140
|
+
try:
|
141
|
+
connector.mail_aliases.create_mail_alias(
|
142
|
+
MailAliasCreateRequest(
|
143
|
+
local_part='&^@$#^&@$#^&',
|
144
|
+
mail_domain_id=1,
|
145
|
+
)
|
146
|
+
)
|
147
|
+
except pydantic.ValidationError as e:
|
148
|
+
errors = e.errors()
|
149
|
+
|
150
|
+
for error in errors:
|
151
|
+
print(error['loc'])
|
152
|
+
print(error['msg'])
|
153
|
+
print(error['type'])
|
154
|
+
```
|
128
155
|
|
129
156
|
## Responses
|
130
157
|
|
131
158
|
### Get model from response
|
132
159
|
|
133
|
-
Calling
|
160
|
+
Calling an endpoint returns the resource model.
|
134
161
|
|
135
|
-
|
162
|
+
Code example:
|
136
163
|
|
137
164
|
```python
|
138
165
|
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
@@ -158,6 +185,8 @@ mail_domain_resource = connector.mail_domains.create_mail_domain(
|
|
158
185
|
|
159
186
|
If a request returns an unexpected HTTP status code, `cyberfusion.CoreApiClient.exceptions.CallException` is thrown.
|
160
187
|
|
188
|
+
The exception includes the response, and the HTTP status code.
|
189
|
+
|
161
190
|
## Enums
|
162
191
|
|
163
192
|
Some properties only accept certain values (enums).
|
@@ -180,7 +209,7 @@ connector = CoreApiConnector(
|
|
180
209
|
)
|
181
210
|
```
|
182
211
|
|
183
|
-
Don't pass a custom session? A default one is created,
|
212
|
+
Don't pass a custom session? A default one is created, with retries enabled.
|
184
213
|
|
185
214
|
### Manual requests
|
186
215
|
|
@@ -204,7 +233,7 @@ response.headers
|
|
204
233
|
response.failed
|
205
234
|
```
|
206
235
|
|
207
|
-
To raise `cyberfusion.CoreApiClient.exceptions.CallException` in case of an unexpected HTTP status code, use `send_or_fail`.
|
236
|
+
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.
|
208
237
|
|
209
238
|
### Generating models
|
210
239
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import datetime
|
2
|
+
from json import JSONEncoder
|
3
|
+
from ipaddress import IPv4Address, IPv6Address
|
4
|
+
from typing import Any
|
5
|
+
|
6
|
+
|
7
|
+
class CustomEncoder(JSONEncoder):
|
8
|
+
def default(self, o: Any) -> str:
|
9
|
+
if isinstance(o, datetime.date):
|
10
|
+
return o.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
11
|
+
elif isinstance(o, (IPv6Address, IPv4Address)):
|
12
|
+
return str(o)
|
13
|
+
|
14
|
+
return super().default(o)
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import json
|
2
2
|
from typing import Optional, Tuple
|
3
|
-
from urllib.parse import urlparse
|
4
3
|
|
5
|
-
from cyberfusion.CoreApiClient._encoders import
|
4
|
+
from cyberfusion.CoreApiClient._encoders import CustomEncoder
|
6
5
|
from cyberfusion.CoreApiClient.exceptions import CallException, AuthenticationException
|
7
6
|
|
8
7
|
from requests.sessions import Session
|
@@ -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,
|
@@ -113,13 +108,13 @@ class CoreApiConnector:
|
|
113
108
|
url = "".join([self.base_url, path])
|
114
109
|
|
115
110
|
if data and content_type == "application/json":
|
116
|
-
data = json.dumps(data, cls=
|
111
|
+
data = json.dumps(data, cls=CustomEncoder)
|
117
112
|
|
118
113
|
if query_parameters:
|
119
114
|
for key, value in query_parameters.items():
|
120
115
|
if isinstance(value, datetime.datetime):
|
121
116
|
query_parameters[key] = json.loads(
|
122
|
-
json.dumps(value, cls=
|
117
|
+
json.dumps(value, cls=CustomEncoder)
|
123
118
|
)
|
124
119
|
|
125
120
|
requests_response = self.requests_session.request(
|
@@ -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.3
|
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
|
|
File without changes
|
File without changes
|
File without changes
|
{python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/http.py
RENAMED
File without changes
|
File without changes
|
{python3_core_api_client-0.1 → python3_core_api_client-0.3}/src/cyberfusion/CoreApiClient/models.py
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
|
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
|
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
|