python3-core-api-client 0.1__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/PKG-INFO +236 -0
- python3_core_api_client-0.1/README.md +225 -0
- python3_core_api_client-0.1/pyproject.toml +20 -0
- python3_core_api_client-0.1/setup.cfg +12 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/__init__.py +0 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/_encoders.py +7 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/connector.py +382 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/exceptions.py +13 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/http.py +21 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/interfaces.py +9 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/models.py +5350 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/__init__.py +99 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/basic_authentication_realms.py +85 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/borg_archives.py +144 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/borg_repositories.py +134 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/certificate_managers.py +99 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/certificates.py +63 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/clusters.py +233 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/cmses.py +289 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/crons.py +76 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/custom_config_snippets.py +88 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/custom_configs.py +82 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/customers.py +97 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/daemons.py +76 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/database_user_grants.py +66 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/database_users.py +82 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/databases.py +140 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/domain_routers.py +43 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/firewall_groups.py +82 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/firewall_rules.py +67 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/fpm_pools.py +110 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/ftp_users.py +89 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/haproxy_listens.py +67 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/haproxy_listens_to_nodes.py +70 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/health.py +14 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/hosts_entries.py +63 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/htpasswd_files.py +67 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/htpasswd_users.py +82 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/login.py +28 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/logs.py +50 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/mail_accounts.py +105 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/mail_aliases.py +79 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/mail_domains.py +79 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/mail_hostnames.py +82 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/malwares.py +53 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/mariadb_encryption_keys.py +56 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/node_add_ons.py +74 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/nodes.py +112 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/passenger_apps.py +99 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/redis_instances.py +85 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/root_ssh_keys.py +77 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/security_txt_policies.py +85 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/sites.py +29 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/ssh_keys.py +77 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/task_collections.py +38 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/tombstones.py +29 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/unix_users.py +122 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/url_redirects.py +79 -0
- python3_core_api_client-0.1/src/cyberfusion/CoreApiClient/resources/virtual_hosts.py +120 -0
- python3_core_api_client-0.1/src/python3_core_api_client.egg-info/PKG-INFO +236 -0
- python3_core_api_client-0.1/src/python3_core_api_client.egg-info/SOURCES.txt +63 -0
- python3_core_api_client-0.1/src/python3_core_api_client.egg-info/dependency_links.txt +1 -0
- python3_core_api_client-0.1/src/python3_core_api_client.egg-info/requires.txt +3 -0
- python3_core_api_client-0.1/src/python3_core_api_client.egg-info/top_level.txt +1 -0
@@ -0,0 +1,236 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: python3-core-api-client
|
3
|
+
Version: 0.1
|
4
|
+
Summary: Python client for Core API.
|
5
|
+
Author-email: Cyberfusion <support@cyberfusion.io>
|
6
|
+
Project-URL: Source, https://github.com/CyberfusionIO/python3-core-api-client
|
7
|
+
Description-Content-Type: text/markdown
|
8
|
+
Requires-Dist: certifi==2022.9.24
|
9
|
+
Requires-Dist: requests==2.28.1
|
10
|
+
Requires-Dist: pydantic[email]==1.10.4
|
11
|
+
|
12
|
+
# python3-core-api-client
|
13
|
+
|
14
|
+
Python client for Core API.
|
15
|
+
|
16
|
+
This client was built for and tested on the **1.241** version of the API.
|
17
|
+
|
18
|
+
## Support
|
19
|
+
|
20
|
+
This client is officially supported by Cyberfusion.
|
21
|
+
|
22
|
+
Have questions? Ask your support questions on the [platform](https://platform.cyberfusion.io/). No access to the platform? Send an email to [support@cyberfusion.io](mailto:support@cyberfusion.io). **GitHub issues are not actively monitored.**
|
23
|
+
|
24
|
+
# Install
|
25
|
+
|
26
|
+
This client can be used in any Python project and with any framework.
|
27
|
+
|
28
|
+
This client requires Python 3.11 or higher.
|
29
|
+
|
30
|
+
## PyPI
|
31
|
+
|
32
|
+
Run the following command to install the package from PyPI:
|
33
|
+
|
34
|
+
pip3 install python3-core-api-client
|
35
|
+
|
36
|
+
## Debian
|
37
|
+
|
38
|
+
Run the following commands to build a Debian package:
|
39
|
+
|
40
|
+
mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
|
41
|
+
dpkg-buildpackage -us -uc
|
42
|
+
|
43
|
+
# Usage
|
44
|
+
|
45
|
+
## API documentation
|
46
|
+
|
47
|
+
Refer to the [API documentation](https://core-api.cyberfusion.io/) for information about API requests.
|
48
|
+
|
49
|
+
**Enums and Models** are **auto-generated** based on the OpenAPI spec - so the client is completely in line with the Core API. **Requests and Resources** are not auto-generated.
|
50
|
+
|
51
|
+
## Getting started
|
52
|
+
|
53
|
+
Initialise the `CoreApiConnector` with your username and password **or** API key.
|
54
|
+
|
55
|
+
The connector takes care of authentication, and offers several resources (such as `virtual_hosts`) and endpoints (i.e. `list_virtual_hosts`).
|
56
|
+
|
57
|
+
```python
|
58
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
59
|
+
|
60
|
+
# Using username and password
|
61
|
+
|
62
|
+
connector = CoreApiConnector(
|
63
|
+
username='username', password='password'
|
64
|
+
)
|
65
|
+
|
66
|
+
# Or using API key
|
67
|
+
|
68
|
+
connector = CoreApiConnector(
|
69
|
+
api_key='api_key'
|
70
|
+
)
|
71
|
+
|
72
|
+
virtual_hosts = connector.virtual_hosts.list_virtual_hosts()
|
73
|
+
```
|
74
|
+
|
75
|
+
## Authentication
|
76
|
+
|
77
|
+
This client takes care of authentication.
|
78
|
+
|
79
|
+
If authentication using username and password fails, `cyberfusion.CoreApiClient.exceptions.AuthenticationException` is thrown.
|
80
|
+
|
81
|
+
If authentication using API key fails, the regular `CallException` exception fis raised.
|
82
|
+
|
83
|
+
Don't have an API user? Contact Cyberfusion.
|
84
|
+
|
85
|
+
## Requests
|
86
|
+
|
87
|
+
The client uses a fluent interface to build requests.
|
88
|
+
|
89
|
+
To view all possible requests:
|
90
|
+
|
91
|
+
- Start with the connector
|
92
|
+
- Go to the desired resource
|
93
|
+
- Call the desired endpoint
|
94
|
+
|
95
|
+
Code example:
|
96
|
+
|
97
|
+
```python
|
98
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
99
|
+
|
100
|
+
from cyberfusion.CoreApiClient.models import MailDomainCreateRequest
|
101
|
+
|
102
|
+
connector = CoreApiConnector(
|
103
|
+
username='username', password='password'
|
104
|
+
)
|
105
|
+
|
106
|
+
connector.mail_domains.create_mail_domain(
|
107
|
+
MailDomainCreateRequest(
|
108
|
+
domain='cyberfusion.io',
|
109
|
+
unix_user_id=1,
|
110
|
+
is_local=True,
|
111
|
+
catch_all_forward_email_addresses=[],
|
112
|
+
)
|
113
|
+
)
|
114
|
+
```
|
115
|
+
|
116
|
+
Models are validated before sending the request (using [Pydantic](https://docs.pydantic.dev/latest/)). If invalid data is provided, `pydantic.ValidationError` is thrown.
|
117
|
+
|
118
|
+
For example:
|
119
|
+
|
120
|
+
```python
|
121
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
122
|
+
|
123
|
+
from cyberfusion.CoreApiClient.models import MailAliasCreateRequest
|
124
|
+
|
125
|
+
connector = CoreApiConnector(
|
126
|
+
username='username', password='password'
|
127
|
+
)
|
128
|
+
|
129
|
+
connector.mail_aliases.create_mail_alias(
|
130
|
+
MailAliasCreateRequest(
|
131
|
+
local_part='&^@$#^&@$#^&',
|
132
|
+
mail_domain_id=1,
|
133
|
+
)
|
134
|
+
)
|
135
|
+
# throw pydantic.ValidationError
|
136
|
+
```
|
137
|
+
|
138
|
+
The exception will provide more details about the validation errors.
|
139
|
+
|
140
|
+
## Responses
|
141
|
+
|
142
|
+
### Get model from response
|
143
|
+
|
144
|
+
Calling a n endpoint returns the resource model.
|
145
|
+
|
146
|
+
For example:
|
147
|
+
|
148
|
+
```python
|
149
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
150
|
+
|
151
|
+
from cyberfusion.CoreApiClient.models import MailDomainCreateRequest
|
152
|
+
|
153
|
+
connector = CoreApiConnector(
|
154
|
+
username='username', password='password'
|
155
|
+
)
|
156
|
+
|
157
|
+
mail_domain_resource = connector.mail_domains.create_mail_domain(
|
158
|
+
MailDomainCreateRequest(
|
159
|
+
domain='cyberfusion.io',
|
160
|
+
unix_user_id=1,
|
161
|
+
is_local=True,
|
162
|
+
catch_all_forward_email_addresses=[],
|
163
|
+
)
|
164
|
+
)
|
165
|
+
# mail_domain_resource is a model representing the API resource
|
166
|
+
```
|
167
|
+
|
168
|
+
### Throw exception on failure
|
169
|
+
|
170
|
+
If a request returns an unexpected HTTP status code, `cyberfusion.CoreApiClient.exceptions.CallException` is thrown.
|
171
|
+
|
172
|
+
## Enums
|
173
|
+
|
174
|
+
Some properties only accept certain values (enums).
|
175
|
+
|
176
|
+
Find these values in `cyberfusion.CoreApiClient.models`.
|
177
|
+
|
178
|
+
## Deep dive
|
179
|
+
|
180
|
+
### Custom `requests` session
|
181
|
+
|
182
|
+
Want to provide your own `requests` session? Pass it to the connector:
|
183
|
+
|
184
|
+
```python
|
185
|
+
import requests
|
186
|
+
|
187
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
188
|
+
|
189
|
+
connector = CoreApiConnector(
|
190
|
+
..., requests_session=requests.Session()
|
191
|
+
)
|
192
|
+
```
|
193
|
+
|
194
|
+
Don't pass a custom session? A default one is created, including retries.
|
195
|
+
|
196
|
+
### Manual requests
|
197
|
+
|
198
|
+
Don't want to use the full SDK, but easily send requests and retrieve responses from the Core API?
|
199
|
+
|
200
|
+
Initialise the connector as usual, and call `send`:
|
201
|
+
|
202
|
+
```python
|
203
|
+
import requests
|
204
|
+
|
205
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
206
|
+
|
207
|
+
connector = CoreApiConnector(...)
|
208
|
+
|
209
|
+
response = connector.send(method='GET', path='/foobar', data={}, query_parameters={})
|
210
|
+
|
211
|
+
response.status_code
|
212
|
+
response.json
|
213
|
+
response.body
|
214
|
+
response.headers
|
215
|
+
response.failed
|
216
|
+
```
|
217
|
+
|
218
|
+
To raise `cyberfusion.CoreApiClient.exceptions.CallException` in case of an unexpected HTTP status code, use `send_or_fail`.
|
219
|
+
|
220
|
+
### Generating models
|
221
|
+
|
222
|
+
Auto-generate models as follows:
|
223
|
+
|
224
|
+
datamodel-codegen --input-file-type openapi --input $file --output src/cyberfusion/CoreApiClient/models.py --target-python-version 3.11
|
225
|
+
|
226
|
+
Replace `$file` by the path to the OpenAPI spec (JSON).
|
227
|
+
|
228
|
+
Note: don't replace `models.py` in full - it contains customisations.
|
229
|
+
|
230
|
+
# Test strategy
|
231
|
+
|
232
|
+
Tests use a mock server, [Stoplight Prism](https://stoplight.io/open-source/prism).
|
233
|
+
|
234
|
+
Prism checks requests' syntactic validity - based on the OpenAPI spec.
|
235
|
+
|
236
|
+
Therefore, the resources' test suites solely call methods without asserting specifics: nearly all possible issues - invalid requests, mismatch between resource models and endpoint, etc. - are already caught by having a validating mock server.
|
@@ -0,0 +1,225 @@
|
|
1
|
+
# python3-core-api-client
|
2
|
+
|
3
|
+
Python client for Core API.
|
4
|
+
|
5
|
+
This client was built for and tested on the **1.241** version of the API.
|
6
|
+
|
7
|
+
## Support
|
8
|
+
|
9
|
+
This client is officially supported by Cyberfusion.
|
10
|
+
|
11
|
+
Have questions? Ask your support questions on the [platform](https://platform.cyberfusion.io/). No access to the platform? Send an email to [support@cyberfusion.io](mailto:support@cyberfusion.io). **GitHub issues are not actively monitored.**
|
12
|
+
|
13
|
+
# Install
|
14
|
+
|
15
|
+
This client can be used in any Python project and with any framework.
|
16
|
+
|
17
|
+
This client requires Python 3.11 or higher.
|
18
|
+
|
19
|
+
## PyPI
|
20
|
+
|
21
|
+
Run the following command to install the package from PyPI:
|
22
|
+
|
23
|
+
pip3 install python3-core-api-client
|
24
|
+
|
25
|
+
## Debian
|
26
|
+
|
27
|
+
Run the following commands to build a Debian package:
|
28
|
+
|
29
|
+
mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
|
30
|
+
dpkg-buildpackage -us -uc
|
31
|
+
|
32
|
+
# Usage
|
33
|
+
|
34
|
+
## API documentation
|
35
|
+
|
36
|
+
Refer to the [API documentation](https://core-api.cyberfusion.io/) for information about API requests.
|
37
|
+
|
38
|
+
**Enums and Models** are **auto-generated** based on the OpenAPI spec - so the client is completely in line with the Core API. **Requests and Resources** are not auto-generated.
|
39
|
+
|
40
|
+
## Getting started
|
41
|
+
|
42
|
+
Initialise the `CoreApiConnector` with your username and password **or** API key.
|
43
|
+
|
44
|
+
The connector takes care of authentication, and offers several resources (such as `virtual_hosts`) and endpoints (i.e. `list_virtual_hosts`).
|
45
|
+
|
46
|
+
```python
|
47
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
48
|
+
|
49
|
+
# Using username and password
|
50
|
+
|
51
|
+
connector = CoreApiConnector(
|
52
|
+
username='username', password='password'
|
53
|
+
)
|
54
|
+
|
55
|
+
# Or using API key
|
56
|
+
|
57
|
+
connector = CoreApiConnector(
|
58
|
+
api_key='api_key'
|
59
|
+
)
|
60
|
+
|
61
|
+
virtual_hosts = connector.virtual_hosts.list_virtual_hosts()
|
62
|
+
```
|
63
|
+
|
64
|
+
## Authentication
|
65
|
+
|
66
|
+
This client takes care of authentication.
|
67
|
+
|
68
|
+
If authentication using username and password fails, `cyberfusion.CoreApiClient.exceptions.AuthenticationException` is thrown.
|
69
|
+
|
70
|
+
If authentication using API key fails, the regular `CallException` exception fis raised.
|
71
|
+
|
72
|
+
Don't have an API user? Contact Cyberfusion.
|
73
|
+
|
74
|
+
## Requests
|
75
|
+
|
76
|
+
The client uses a fluent interface to build requests.
|
77
|
+
|
78
|
+
To view all possible requests:
|
79
|
+
|
80
|
+
- Start with the connector
|
81
|
+
- Go to the desired resource
|
82
|
+
- Call the desired endpoint
|
83
|
+
|
84
|
+
Code example:
|
85
|
+
|
86
|
+
```python
|
87
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
88
|
+
|
89
|
+
from cyberfusion.CoreApiClient.models import MailDomainCreateRequest
|
90
|
+
|
91
|
+
connector = CoreApiConnector(
|
92
|
+
username='username', password='password'
|
93
|
+
)
|
94
|
+
|
95
|
+
connector.mail_domains.create_mail_domain(
|
96
|
+
MailDomainCreateRequest(
|
97
|
+
domain='cyberfusion.io',
|
98
|
+
unix_user_id=1,
|
99
|
+
is_local=True,
|
100
|
+
catch_all_forward_email_addresses=[],
|
101
|
+
)
|
102
|
+
)
|
103
|
+
```
|
104
|
+
|
105
|
+
Models are validated before sending the request (using [Pydantic](https://docs.pydantic.dev/latest/)). If invalid data is provided, `pydantic.ValidationError` is thrown.
|
106
|
+
|
107
|
+
For example:
|
108
|
+
|
109
|
+
```python
|
110
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
111
|
+
|
112
|
+
from cyberfusion.CoreApiClient.models import MailAliasCreateRequest
|
113
|
+
|
114
|
+
connector = CoreApiConnector(
|
115
|
+
username='username', password='password'
|
116
|
+
)
|
117
|
+
|
118
|
+
connector.mail_aliases.create_mail_alias(
|
119
|
+
MailAliasCreateRequest(
|
120
|
+
local_part='&^@$#^&@$#^&',
|
121
|
+
mail_domain_id=1,
|
122
|
+
)
|
123
|
+
)
|
124
|
+
# throw pydantic.ValidationError
|
125
|
+
```
|
126
|
+
|
127
|
+
The exception will provide more details about the validation errors.
|
128
|
+
|
129
|
+
## Responses
|
130
|
+
|
131
|
+
### Get model from response
|
132
|
+
|
133
|
+
Calling a n endpoint returns the resource model.
|
134
|
+
|
135
|
+
For example:
|
136
|
+
|
137
|
+
```python
|
138
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
139
|
+
|
140
|
+
from cyberfusion.CoreApiClient.models import MailDomainCreateRequest
|
141
|
+
|
142
|
+
connector = CoreApiConnector(
|
143
|
+
username='username', password='password'
|
144
|
+
)
|
145
|
+
|
146
|
+
mail_domain_resource = connector.mail_domains.create_mail_domain(
|
147
|
+
MailDomainCreateRequest(
|
148
|
+
domain='cyberfusion.io',
|
149
|
+
unix_user_id=1,
|
150
|
+
is_local=True,
|
151
|
+
catch_all_forward_email_addresses=[],
|
152
|
+
)
|
153
|
+
)
|
154
|
+
# mail_domain_resource is a model representing the API resource
|
155
|
+
```
|
156
|
+
|
157
|
+
### Throw exception on failure
|
158
|
+
|
159
|
+
If a request returns an unexpected HTTP status code, `cyberfusion.CoreApiClient.exceptions.CallException` is thrown.
|
160
|
+
|
161
|
+
## Enums
|
162
|
+
|
163
|
+
Some properties only accept certain values (enums).
|
164
|
+
|
165
|
+
Find these values in `cyberfusion.CoreApiClient.models`.
|
166
|
+
|
167
|
+
## Deep dive
|
168
|
+
|
169
|
+
### Custom `requests` session
|
170
|
+
|
171
|
+
Want to provide your own `requests` session? Pass it to the connector:
|
172
|
+
|
173
|
+
```python
|
174
|
+
import requests
|
175
|
+
|
176
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
177
|
+
|
178
|
+
connector = CoreApiConnector(
|
179
|
+
..., requests_session=requests.Session()
|
180
|
+
)
|
181
|
+
```
|
182
|
+
|
183
|
+
Don't pass a custom session? A default one is created, including retries.
|
184
|
+
|
185
|
+
### Manual requests
|
186
|
+
|
187
|
+
Don't want to use the full SDK, but easily send requests and retrieve responses from the Core API?
|
188
|
+
|
189
|
+
Initialise the connector as usual, and call `send`:
|
190
|
+
|
191
|
+
```python
|
192
|
+
import requests
|
193
|
+
|
194
|
+
from cyberfusion.CoreApiClient.connector import CoreApiConnector
|
195
|
+
|
196
|
+
connector = CoreApiConnector(...)
|
197
|
+
|
198
|
+
response = connector.send(method='GET', path='/foobar', data={}, query_parameters={})
|
199
|
+
|
200
|
+
response.status_code
|
201
|
+
response.json
|
202
|
+
response.body
|
203
|
+
response.headers
|
204
|
+
response.failed
|
205
|
+
```
|
206
|
+
|
207
|
+
To raise `cyberfusion.CoreApiClient.exceptions.CallException` in case of an unexpected HTTP status code, use `send_or_fail`.
|
208
|
+
|
209
|
+
### Generating models
|
210
|
+
|
211
|
+
Auto-generate models as follows:
|
212
|
+
|
213
|
+
datamodel-codegen --input-file-type openapi --input $file --output src/cyberfusion/CoreApiClient/models.py --target-python-version 3.11
|
214
|
+
|
215
|
+
Replace `$file` by the path to the OpenAPI spec (JSON).
|
216
|
+
|
217
|
+
Note: don't replace `models.py` in full - it contains customisations.
|
218
|
+
|
219
|
+
# Test strategy
|
220
|
+
|
221
|
+
Tests use a mock server, [Stoplight Prism](https://stoplight.io/open-source/prism).
|
222
|
+
|
223
|
+
Prism checks requests' syntactic validity - based on the OpenAPI spec.
|
224
|
+
|
225
|
+
Therefore, the resources' test suites solely call methods without asserting specifics: nearly all possible issues - invalid requests, mismatch between resource models and endpoint, etc. - are already caught by having a validating mock server.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "python3-core-api-client"
|
7
|
+
version = "0.1"
|
8
|
+
description = "Python client for Core API."
|
9
|
+
readme = "README.md"
|
10
|
+
authors = [
|
11
|
+
{ name = "Cyberfusion", email = "support@cyberfusion.io" },
|
12
|
+
]
|
13
|
+
dependencies = [
|
14
|
+
"certifi==2022.9.24",
|
15
|
+
"requests==2.28.1",
|
16
|
+
"pydantic[email]==1.10.4",
|
17
|
+
]
|
18
|
+
|
19
|
+
[project.urls]
|
20
|
+
"Source" = "https://github.com/CyberfusionIO/python3-core-api-client"
|
File without changes
|