peak-sdk 1.0.0__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.
- peak/__init__.py +36 -0
- peak/_version.py +21 -0
- peak/auth.py +22 -0
- peak/base_client.py +52 -0
- peak/cli/__init_.py +20 -0
- peak/cli/args.py +84 -0
- peak/cli/cli.py +56 -0
- peak/cli/helpers.py +187 -0
- peak/cli/press/__init__.py +21 -0
- peak/cli/press/apps/__init__.py +40 -0
- peak/cli/press/apps/deployments.py +238 -0
- peak/cli/press/apps/specs.py +387 -0
- peak/cli/press/blocks/__init__.py +40 -0
- peak/cli/press/blocks/deployments.py +240 -0
- peak/cli/press/blocks/specs.py +492 -0
- peak/cli/press/deployments.py +78 -0
- peak/cli/press/specs.py +131 -0
- peak/cli/resources/__init__.py +21 -0
- peak/cli/resources/artifacts.py +310 -0
- peak/cli/resources/images.py +886 -0
- peak/cli/resources/webapps.py +356 -0
- peak/cli/resources/workflows.py +703 -0
- peak/cli/ruff.toml +11 -0
- peak/cli/version.py +49 -0
- peak/compression.py +162 -0
- peak/config.py +24 -0
- peak/constants.py +105 -0
- peak/exceptions.py +217 -0
- peak/handler.py +358 -0
- peak/helpers.py +184 -0
- peak/logger.py +48 -0
- peak/press/__init__.py +28 -0
- peak/press/apps.py +669 -0
- peak/press/blocks.py +707 -0
- peak/press/deployments.py +145 -0
- peak/press/specs.py +260 -0
- peak/py.typed +0 -0
- peak/resources/__init__.py +28 -0
- peak/resources/artifacts.py +343 -0
- peak/resources/images.py +675 -0
- peak/resources/webapps.py +278 -0
- peak/resources/workflows.py +625 -0
- peak/session.py +259 -0
- peak/telemetry.py +201 -0
- peak/template.py +231 -0
- peak/validators.py +48 -0
- peak_sdk-1.0.0.dist-info/LICENSE +201 -0
- peak_sdk-1.0.0.dist-info/METADATA +199 -0
- peak_sdk-1.0.0.dist-info/RECORD +51 -0
- peak_sdk-1.0.0.dist-info/WHEEL +4 -0
- peak_sdk-1.0.0.dist-info/entry_points.txt +3 -0
peak/press/apps.py
ADDED
@@ -0,0 +1,669 @@
|
|
1
|
+
#
|
2
|
+
# # Copyright © 2023 Peak AI Limited. or its affiliates. All Rights Reserved.
|
3
|
+
# #
|
4
|
+
# # Licensed under the Apache License, Version 2.0 (the "License"). You
|
5
|
+
# # may not use this file except in compliance with the License. A copy of
|
6
|
+
# # the License is located at:
|
7
|
+
# #
|
8
|
+
# # https://github.com/PeakBI/peak-sdk/blob/main/LICENSE
|
9
|
+
# #
|
10
|
+
# # or in the "license" file accompanying this file. This file is
|
11
|
+
# # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
12
|
+
# # ANY KIND, either express or implied. See the License for the specific
|
13
|
+
# # language governing permissions and limitations under the License.
|
14
|
+
# #
|
15
|
+
# # This file is part of the peak-sdk.
|
16
|
+
# # see (https://github.com/PeakBI/peak-sdk)
|
17
|
+
# #
|
18
|
+
# # You should have received a copy of the APACHE LICENSE, VERSION 2.0
|
19
|
+
# # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
|
20
|
+
#
|
21
|
+
"""Apps client module."""
|
22
|
+
from __future__ import annotations
|
23
|
+
|
24
|
+
import json
|
25
|
+
from typing import Any, Dict, Iterator, List, Literal, Optional, overload
|
26
|
+
|
27
|
+
from peak.base_client import BaseClient
|
28
|
+
from peak.constants import ContentType, HttpMethods
|
29
|
+
from peak.session import Session
|
30
|
+
|
31
|
+
|
32
|
+
class App(BaseClient):
|
33
|
+
"""Client class for interacting with Apps."""
|
34
|
+
|
35
|
+
SPECS_BASE_ENDPOINT = "v1/apps/specs"
|
36
|
+
DEPLOYMENTS_BASE_ENDPOINT = "v1/apps/deployments"
|
37
|
+
|
38
|
+
@overload
|
39
|
+
def list_specs(
|
40
|
+
self,
|
41
|
+
status: Optional[List[str]] = None,
|
42
|
+
featured: Optional[bool] = None,
|
43
|
+
name: Optional[str] = None,
|
44
|
+
title: Optional[str] = None,
|
45
|
+
sort: Optional[List[str]] = None,
|
46
|
+
scope: Optional[List[str]] = None,
|
47
|
+
page_size: Optional[int] = None,
|
48
|
+
page_number: Optional[int] = None,
|
49
|
+
*,
|
50
|
+
return_iterator: Literal[False],
|
51
|
+
) -> Dict[str, Any]:
|
52
|
+
...
|
53
|
+
|
54
|
+
@overload
|
55
|
+
def list_specs(
|
56
|
+
self,
|
57
|
+
status: Optional[List[str]] = None,
|
58
|
+
featured: Optional[bool] = None,
|
59
|
+
name: Optional[str] = None,
|
60
|
+
title: Optional[str] = None,
|
61
|
+
sort: Optional[List[str]] = None,
|
62
|
+
scope: Optional[List[str]] = None,
|
63
|
+
page_size: Optional[int] = None,
|
64
|
+
page_number: Optional[int] = None,
|
65
|
+
*,
|
66
|
+
return_iterator: Literal[True] = True,
|
67
|
+
) -> Iterator[Dict[str, Any]]:
|
68
|
+
...
|
69
|
+
|
70
|
+
def list_specs(
|
71
|
+
self,
|
72
|
+
status: Optional[List[str]] = None,
|
73
|
+
featured: Optional[bool] = None,
|
74
|
+
name: Optional[str] = None,
|
75
|
+
title: Optional[str] = None,
|
76
|
+
sort: Optional[List[str]] = None,
|
77
|
+
scope: Optional[List[str]] = None,
|
78
|
+
page_size: Optional[int] = None,
|
79
|
+
page_number: Optional[int] = None,
|
80
|
+
*,
|
81
|
+
return_iterator: bool = True,
|
82
|
+
) -> Iterator[Dict[str, Any]] | Dict[str, Any]:
|
83
|
+
"""Lists all published App specs ordered by creation date. Returns info for the latest release for each spec.
|
84
|
+
|
85
|
+
REFERENCE:
|
86
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Specs/get_v1_apps_specs_>`__
|
87
|
+
|
88
|
+
Args:
|
89
|
+
status (List[str] | None): List of statuses to filter specs.
|
90
|
+
featured (bool | None): Whether to only return featured specs.
|
91
|
+
name (str | None): Only return specs whose names begins with the query string.
|
92
|
+
title (str | None): Only return specs whose title begins with the query string.
|
93
|
+
sort (List[str] | None): List of fields with desired ordering in the format `[<field>:<order>, ...]`,
|
94
|
+
where `order` is one of `['asc', 'desc']` and field is an ordered parameter within the response,
|
95
|
+
defaults to `[]`. Valid fields are `createdAt`, `createdBy`, `name`, `title`.
|
96
|
+
scope (List[str] | None): List of scopes to only return specs of those scopes. Valid values are `private`, `public` and `shared`.
|
97
|
+
page_size (int | None): Number of specs to include per page.
|
98
|
+
page_number (int | None): The page number to retrieve. Only used when `return_iterator` is False.
|
99
|
+
return_iterator (bool): Whether to return an iterator object or list of specs for a specified page number, defaults to True.
|
100
|
+
|
101
|
+
Returns:
|
102
|
+
Iterator[Dict[str, Any]] | Dict[str, Any]: an iterator object which returns an element per iteration, until there are no more elements to return.
|
103
|
+
If `return_iterator` is set to False, a dictionary containing the list and pagination details is returned instead.
|
104
|
+
|
105
|
+
Set `return_iterator` to True if you want automatic client-side pagination, or False if you want server-side pagination.
|
106
|
+
|
107
|
+
Raises:
|
108
|
+
BadRequestException: The given parameters are invalid.
|
109
|
+
UnauthorizedException: The credentials are invalid.
|
110
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
111
|
+
InternalServerErrorException: The server encountered an unexpected condition that
|
112
|
+
prevented it from fulfilling the request.
|
113
|
+
StopIteration: There are no more pages to list
|
114
|
+
"""
|
115
|
+
method, endpoint = HttpMethods.GET, f"{self.SPECS_BASE_ENDPOINT}/"
|
116
|
+
params: Dict[str, Any] = {
|
117
|
+
"status": status,
|
118
|
+
"featured": featured,
|
119
|
+
"name": name,
|
120
|
+
"title": title,
|
121
|
+
"sort": sort,
|
122
|
+
"scope": scope,
|
123
|
+
"pageSize": page_size,
|
124
|
+
}
|
125
|
+
|
126
|
+
if return_iterator:
|
127
|
+
return self.session.create_generator_request(
|
128
|
+
endpoint,
|
129
|
+
method,
|
130
|
+
content_type=ContentType.APPLICATION_JSON,
|
131
|
+
response_key="specs",
|
132
|
+
params=params,
|
133
|
+
subdomain="press",
|
134
|
+
)
|
135
|
+
|
136
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
137
|
+
endpoint,
|
138
|
+
method,
|
139
|
+
content_type=ContentType.APPLICATION_JSON,
|
140
|
+
params={**params, "pageNumber": page_number},
|
141
|
+
subdomain="press",
|
142
|
+
)
|
143
|
+
|
144
|
+
def create_spec(
|
145
|
+
self,
|
146
|
+
body: Dict[str, Any],
|
147
|
+
featured: Optional[bool] = None,
|
148
|
+
scope: Optional[str] = None,
|
149
|
+
tenants: Optional[List[str]] = None,
|
150
|
+
) -> Dict[str, str]:
|
151
|
+
"""Creates a new App spec.
|
152
|
+
|
153
|
+
All App Specs must have unique names within a tenant.
|
154
|
+
An App Spec must now be made up of already existing block specs.
|
155
|
+
Spec details (specId and release) needs to be added in the spec body inside `config` key.
|
156
|
+
|
157
|
+
REFERENCE:
|
158
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Specs/post_v1_apps_specs_>`__
|
159
|
+
|
160
|
+
Args:
|
161
|
+
body (Dict[str, Any]): A payload specifying an App's metadata, release and corresponding config in the expected format.
|
162
|
+
featured (bool | None): Whether to feature this spec. By default it is False.
|
163
|
+
scope (str | None): Specify weather tenants can discover and deploy this spec.
|
164
|
+
`private` restricts the spec to this tenant alone, `public` makes it available on all tenants
|
165
|
+
and `shared` allows specifying what set of tenants can access and use this spec.
|
166
|
+
By default it is `private`.
|
167
|
+
tenants (List[str] | None): Given a shared scope, specify what other tenants can discover and deploy this spec.
|
168
|
+
|
169
|
+
Returns:
|
170
|
+
Dict[str, str]: Id of the created app spec.
|
171
|
+
|
172
|
+
Raises:
|
173
|
+
BadRequestException: The given parameters are invalid.
|
174
|
+
UnauthorizedException: The credentials are invalid.
|
175
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
176
|
+
UnprocessableEntityException: The server was unable to process the request.
|
177
|
+
InternalServerErrorException: The server encountered an unexpected condition that
|
178
|
+
prevented it from fulfilling the request.
|
179
|
+
"""
|
180
|
+
method, endpoint = HttpMethods.POST, f"{self.SPECS_BASE_ENDPOINT}/"
|
181
|
+
|
182
|
+
body = {
|
183
|
+
"spec": json.dumps(body),
|
184
|
+
"featured": json.dumps(featured),
|
185
|
+
"scope": scope,
|
186
|
+
}
|
187
|
+
|
188
|
+
if tenants:
|
189
|
+
body["tenants"] = json.dumps(tenants)
|
190
|
+
|
191
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
192
|
+
endpoint,
|
193
|
+
method,
|
194
|
+
content_type=ContentType.APPLICATION_JSON,
|
195
|
+
body=body,
|
196
|
+
subdomain="press",
|
197
|
+
)
|
198
|
+
|
199
|
+
def describe_spec(
|
200
|
+
self,
|
201
|
+
spec_id: str,
|
202
|
+
) -> Dict[str, Any]:
|
203
|
+
"""Describes an existing App spec and also provides details of the latest release.
|
204
|
+
|
205
|
+
REFERENCE:
|
206
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Specs/get_v1_apps_specs__specId_>`__
|
207
|
+
|
208
|
+
Args:
|
209
|
+
spec_id (str): The ID of the app spec to retrieve.
|
210
|
+
|
211
|
+
Returns:
|
212
|
+
Dict[str, Any]: Dictionary containing the details of the spec.
|
213
|
+
|
214
|
+
Raises:
|
215
|
+
BadRequestException: The given parameters are invalid.
|
216
|
+
UnauthorizedException: The credentials are invalid.
|
217
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
218
|
+
NotFoundException: The given app spec does not exist.
|
219
|
+
InternalServerErrorException: The server encountered an unexpected condition that
|
220
|
+
prevented it from fulfilling the request.
|
221
|
+
"""
|
222
|
+
method, endpoint = HttpMethods.GET, f"{self.SPECS_BASE_ENDPOINT}/{spec_id}"
|
223
|
+
|
224
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
225
|
+
endpoint,
|
226
|
+
method,
|
227
|
+
content_type=ContentType.APPLICATION_JSON,
|
228
|
+
subdomain="press",
|
229
|
+
)
|
230
|
+
|
231
|
+
def update_spec_metadata(self, spec_id: str, body: Dict[str, Any]) -> Dict[None, None]:
|
232
|
+
"""Updates the metadata of an App spec.
|
233
|
+
|
234
|
+
REFERENCE:
|
235
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Specs/patch_v1_apps_specs__specId_>`__
|
236
|
+
|
237
|
+
Args:
|
238
|
+
spec_id (str): ID of the spec to update
|
239
|
+
body (Dict[str, Any]): Dictionary containing the new spec metadata
|
240
|
+
|
241
|
+
Returns:
|
242
|
+
dict: Dictionary containing the details of the updated spec.
|
243
|
+
|
244
|
+
Raises:
|
245
|
+
BadRequestException: The given parameters are invalid.
|
246
|
+
UnauthorizedException: The credentials are invalid.
|
247
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
248
|
+
NotFoundException: The given App spec does not exist.
|
249
|
+
InternalServerErrorException: the server encountered an unexpected condition that
|
250
|
+
prevented it from fulfilling the request.
|
251
|
+
"""
|
252
|
+
method, endpoint = HttpMethods.PATCH, f"{self.SPECS_BASE_ENDPOINT}/{spec_id}"
|
253
|
+
|
254
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
255
|
+
endpoint,
|
256
|
+
method,
|
257
|
+
content_type=ContentType.APPLICATION_JSON,
|
258
|
+
body=body,
|
259
|
+
subdomain="press",
|
260
|
+
)
|
261
|
+
|
262
|
+
def create_spec_release(self, spec_id: str, body: Dict[str, Any]) -> Dict[str, str]:
|
263
|
+
"""Publish a new release to an existing App spec.
|
264
|
+
|
265
|
+
REFERENCE:
|
266
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Specs/post_v1_apps_specs__specId__releases>`__
|
267
|
+
|
268
|
+
Args:
|
269
|
+
spec_id (str): Id of the spec in which new release will be created
|
270
|
+
body (Dict[str, Any]): Dictionary containing updated release and config in the expected format.
|
271
|
+
|
272
|
+
Returns:
|
273
|
+
Dict[str, str]: Dictionary containing spec id and release version
|
274
|
+
|
275
|
+
Raises:
|
276
|
+
BadRequestException: The given parameters are invalid.
|
277
|
+
UnauthorizedException: The credentials are invalid.
|
278
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
279
|
+
NotFoundException: The given app spec does not exist.
|
280
|
+
UnprocessableEntityException: The server was unable to process the request.
|
281
|
+
InternalServerErrorException: the server encountered an unexpected condition that
|
282
|
+
prevented it from fulfilling the request.
|
283
|
+
"""
|
284
|
+
method, endpoint = HttpMethods.POST, f"{self.SPECS_BASE_ENDPOINT}/{spec_id}/releases"
|
285
|
+
|
286
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
287
|
+
endpoint,
|
288
|
+
method,
|
289
|
+
content_type=ContentType.APPLICATION_JSON,
|
290
|
+
body=body,
|
291
|
+
subdomain="press",
|
292
|
+
)
|
293
|
+
|
294
|
+
def delete_spec(
|
295
|
+
self,
|
296
|
+
spec_id: str,
|
297
|
+
) -> Dict[None, None]:
|
298
|
+
"""Delete an App Spec and all it's associated releases.
|
299
|
+
|
300
|
+
REFERENCE:
|
301
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Specs/delete_v1_apps_specs__specId_>`__
|
302
|
+
|
303
|
+
Args:
|
304
|
+
spec_id (str): The ID of the App spec to delete.
|
305
|
+
|
306
|
+
Returns:
|
307
|
+
dict: Empty dict object.
|
308
|
+
|
309
|
+
Raises:
|
310
|
+
BadRequestException: The given parameters are invalid.
|
311
|
+
UnauthorizedException: The credentials are invalid.
|
312
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
313
|
+
NotFoundException: The given App spec does not exist.
|
314
|
+
UnprocessableEntityException: The server was unable to process the request.
|
315
|
+
InternalServerErrorException: the server encountered an unexpected condition that
|
316
|
+
prevented it from fulfilling the request.
|
317
|
+
"""
|
318
|
+
method, endpoint = HttpMethods.DELETE, f"{self.SPECS_BASE_ENDPOINT}/{spec_id}"
|
319
|
+
|
320
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
321
|
+
endpoint,
|
322
|
+
method,
|
323
|
+
content_type=ContentType.APPLICATION_JSON,
|
324
|
+
subdomain="press",
|
325
|
+
)
|
326
|
+
|
327
|
+
def describe_spec_release(self, spec_id: str, version: str) -> Dict[str, Any]:
|
328
|
+
"""Describes an existing App spec release.
|
329
|
+
|
330
|
+
REFERENCE:
|
331
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Specs/get_v1_apps_specs__specId__releases__release_>`__
|
332
|
+
|
333
|
+
Args:
|
334
|
+
spec_id (str): The ID of the app spec to retrieve.
|
335
|
+
version (str): The release version of spec to retrieve in valid semantic versioning format.
|
336
|
+
|
337
|
+
Returns:
|
338
|
+
Dict[str, Any]: Dictionary containing details of the spec release
|
339
|
+
|
340
|
+
Raises:
|
341
|
+
BadRequestException: The given parameters are invalid.
|
342
|
+
UnauthorizedException: The credentials are invalid.
|
343
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
344
|
+
NotFoundException: The given app spec does not exist.
|
345
|
+
InternalServerErrorException: the server encountered an unexpected condition that
|
346
|
+
prevented it from fulfilling the request.
|
347
|
+
"""
|
348
|
+
method, endpoint = HttpMethods.GET, f"{self.SPECS_BASE_ENDPOINT}/{spec_id}/releases/{version}"
|
349
|
+
|
350
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
351
|
+
endpoint,
|
352
|
+
method,
|
353
|
+
content_type=ContentType.APPLICATION_JSON,
|
354
|
+
subdomain="press",
|
355
|
+
)
|
356
|
+
|
357
|
+
@overload
|
358
|
+
def list_spec_releases(
|
359
|
+
self,
|
360
|
+
spec_id: str,
|
361
|
+
sort: Optional[List[str]] = None,
|
362
|
+
page_size: Optional[int] = None,
|
363
|
+
page_number: Optional[int] = None,
|
364
|
+
*,
|
365
|
+
return_iterator: Literal[False],
|
366
|
+
) -> Dict[str, Any]:
|
367
|
+
...
|
368
|
+
|
369
|
+
@overload
|
370
|
+
def list_spec_releases(
|
371
|
+
self,
|
372
|
+
spec_id: str,
|
373
|
+
sort: Optional[List[str]] = None,
|
374
|
+
page_size: Optional[int] = None,
|
375
|
+
page_number: Optional[int] = None,
|
376
|
+
*,
|
377
|
+
return_iterator: Literal[True] = True,
|
378
|
+
) -> Iterator[Dict[str, Any]]:
|
379
|
+
...
|
380
|
+
|
381
|
+
def list_spec_releases(
|
382
|
+
self,
|
383
|
+
spec_id: str,
|
384
|
+
sort: Optional[List[str]] = None,
|
385
|
+
page_size: Optional[int] = None,
|
386
|
+
page_number: Optional[int] = None,
|
387
|
+
*,
|
388
|
+
return_iterator: bool = True,
|
389
|
+
) -> Iterator[Dict[str, Any]] | Dict[str, Any]:
|
390
|
+
"""Get all releases of an App spec (ordered by most recently created to oldest).
|
391
|
+
|
392
|
+
REFERENCE:
|
393
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Specs/get_v1_apps_specs__specId__releases>`__
|
394
|
+
|
395
|
+
Args:
|
396
|
+
spec_id (str): The ID of the app spec to retrieve.
|
397
|
+
sort (List[str] | None): List of fields with desired ordering in the format `[<field>:<order>, ...]`,
|
398
|
+
where `order` is one of `['asc', 'desc']` and field is an ordered parameter within the response.
|
399
|
+
Valid fields are `createdAt` and `createdBy`.
|
400
|
+
page_size (int | None, optional): Number of releases to include per page.
|
401
|
+
page_number (int | None): The page number to retrieve. Only used when `return_iterator` is False.
|
402
|
+
return_iterator (bool): Whether to return an iterator object or list of releases for a specified page number, defaults to True.
|
403
|
+
|
404
|
+
Returns:
|
405
|
+
Iterator[Dict[str, Any]] | Dict[str, Any]: an iterator object which returns an element per iteration, until there are no more elements to return.
|
406
|
+
If `return_iterator` is set to False, a dictionary containing the list and pagination details is returned instead.
|
407
|
+
|
408
|
+
Set `return_iterator` to True if you want automatic client-side pagination, or False if you want server-side pagination.
|
409
|
+
|
410
|
+
Raises:
|
411
|
+
BadRequestException: The given parameters are invalid.
|
412
|
+
UnauthorizedException: The credentials are invalid.
|
413
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
414
|
+
NotFoundException: The given App spec does not exist.
|
415
|
+
InternalServerErrorException: the server encountered an unexpected condition that
|
416
|
+
prevented it from fulfilling the request.
|
417
|
+
StopIteration: There are no more pages to list
|
418
|
+
"""
|
419
|
+
method, endpoint = HttpMethods.GET, f"{self.SPECS_BASE_ENDPOINT}/{spec_id}/releases"
|
420
|
+
params: Dict[str, Any] = {"pageSize": page_size, "sort": sort}
|
421
|
+
|
422
|
+
if return_iterator:
|
423
|
+
return self.session.create_generator_request(
|
424
|
+
endpoint,
|
425
|
+
method,
|
426
|
+
content_type=ContentType.APPLICATION_JSON,
|
427
|
+
response_key="releases",
|
428
|
+
params=params,
|
429
|
+
subdomain="press",
|
430
|
+
)
|
431
|
+
|
432
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
433
|
+
endpoint,
|
434
|
+
method,
|
435
|
+
content_type=ContentType.APPLICATION_JSON,
|
436
|
+
params={**params, "pageNumber": page_number},
|
437
|
+
subdomain="press",
|
438
|
+
)
|
439
|
+
|
440
|
+
def create_deployment(self, body: Dict[str, str]) -> Dict[str, str]:
|
441
|
+
"""Creates a new deployment from App spec.
|
442
|
+
|
443
|
+
Uses the latest spec release if release version is not provided.
|
444
|
+
|
445
|
+
REFERENCE:
|
446
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Deployments/post_v1_apps_deployments>`__
|
447
|
+
|
448
|
+
Args:
|
449
|
+
body (Dict[str, str]): Dictionary containing deployment metadata, spec ID, release version and revision info.
|
450
|
+
|
451
|
+
Returns:
|
452
|
+
Dict[str, str]: ID of the created App deployment
|
453
|
+
|
454
|
+
Raises:
|
455
|
+
BadRequestException: The given parameters are invalid.
|
456
|
+
UnauthorizedException: The credentials are invalid.
|
457
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
458
|
+
NotFoundException: The given app spec release does not exist.
|
459
|
+
UnprocessableEntityException: The server was unable to process the request.
|
460
|
+
InternalServerErrorException: The server encountered an unexpected condition that
|
461
|
+
prevented it from fulfilling the request.
|
462
|
+
"""
|
463
|
+
method, endpoint = HttpMethods.POST, f"{self.DEPLOYMENTS_BASE_ENDPOINT}/"
|
464
|
+
|
465
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
466
|
+
endpoint,
|
467
|
+
method,
|
468
|
+
content_type=ContentType.APPLICATION_JSON,
|
469
|
+
body=body,
|
470
|
+
subdomain="press",
|
471
|
+
)
|
472
|
+
|
473
|
+
@overload
|
474
|
+
def list_deployments(
|
475
|
+
self,
|
476
|
+
status: Optional[List[str]] = None,
|
477
|
+
name: Optional[str] = None,
|
478
|
+
sort: Optional[List[str]] = None,
|
479
|
+
page_size: Optional[int] = None,
|
480
|
+
page_number: Optional[int] = None,
|
481
|
+
*,
|
482
|
+
return_iterator: Literal[False],
|
483
|
+
) -> Dict[str, Any]:
|
484
|
+
...
|
485
|
+
|
486
|
+
@overload
|
487
|
+
def list_deployments(
|
488
|
+
self,
|
489
|
+
status: Optional[List[str]] = None,
|
490
|
+
name: Optional[str] = None,
|
491
|
+
sort: Optional[List[str]] = None,
|
492
|
+
page_size: Optional[int] = None,
|
493
|
+
page_number: Optional[int] = None,
|
494
|
+
*,
|
495
|
+
return_iterator: Literal[True] = True,
|
496
|
+
) -> Iterator[Dict[str, Any]]:
|
497
|
+
...
|
498
|
+
|
499
|
+
def list_deployments(
|
500
|
+
self,
|
501
|
+
status: Optional[List[str]] = None,
|
502
|
+
name: Optional[str] = None,
|
503
|
+
sort: Optional[List[str]] = None,
|
504
|
+
page_size: Optional[int] = None,
|
505
|
+
page_number: Optional[int] = None,
|
506
|
+
*,
|
507
|
+
return_iterator: bool = True,
|
508
|
+
) -> Iterator[Dict[str, Any]] | Dict[str, Any]:
|
509
|
+
"""Lists App deployments ordered by creation date.
|
510
|
+
|
511
|
+
REFERENCE:
|
512
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Deployments/get_v1_apps_deployments>`__
|
513
|
+
|
514
|
+
Args:
|
515
|
+
status (List[str] | None): List of statuses to filter deployments.
|
516
|
+
name (str | None): Only return deployments whose names begins with the query string.
|
517
|
+
sort (List[str] | None): List of fields with desired ordering in the format `[<field>:<order>, ...]`,
|
518
|
+
where `order` is one of `['asc', 'desc']` and field is an ordered parameter within the response.
|
519
|
+
Valid fields are `createdAt`, `createdBy`, `name` and `title`.
|
520
|
+
page_size (int | None): Number of deployments to include per page.
|
521
|
+
page_number (int | None): The page number to retrieve. Only used when `return_iterator` is False.
|
522
|
+
return_iterator (bool): Whether to return an iterator object or list of deployments for a specified page number, defaults to True.
|
523
|
+
|
524
|
+
Returns:
|
525
|
+
Iterator[Dict[str, Any]] | Dict[str, Any]: an iterator object which returns an element per iteration, until there are no more elements to return.
|
526
|
+
If `return_iterator` is set to False, a dictionary containing the list and pagination details is returned instead.
|
527
|
+
|
528
|
+
Set `return_iterator` to True if you want automatic client-side pagination, or False if you want server-side pagination.
|
529
|
+
|
530
|
+
Raises:
|
531
|
+
BadRequestException: The given parameters are invalid.
|
532
|
+
UnauthorizedException: The credentials are invalid.
|
533
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
534
|
+
UnprocessableEntityException: The server was unable to process the request.
|
535
|
+
InternalServerErrorException: The server encountered an unexpected condition that
|
536
|
+
prevented it from fulfilling the request.
|
537
|
+
StopIteration: There are no more pages to list.
|
538
|
+
"""
|
539
|
+
method, endpoint = HttpMethods.GET, f"{self.DEPLOYMENTS_BASE_ENDPOINT}/"
|
540
|
+
|
541
|
+
params: Dict[str, Any] = {
|
542
|
+
"status": status,
|
543
|
+
"name": name,
|
544
|
+
"sort": sort,
|
545
|
+
"pageSize": page_size,
|
546
|
+
}
|
547
|
+
|
548
|
+
if return_iterator:
|
549
|
+
return self.session.create_generator_request(
|
550
|
+
endpoint,
|
551
|
+
method,
|
552
|
+
content_type=ContentType.APPLICATION_JSON,
|
553
|
+
response_key="deployments",
|
554
|
+
params=params,
|
555
|
+
subdomain="press",
|
556
|
+
)
|
557
|
+
|
558
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
559
|
+
endpoint,
|
560
|
+
method,
|
561
|
+
content_type=ContentType.APPLICATION_JSON,
|
562
|
+
params={**params, "pageNumber": page_number},
|
563
|
+
subdomain="press",
|
564
|
+
)
|
565
|
+
|
566
|
+
def describe_deployment(self, deployment_id: str) -> Dict[str, Any]:
|
567
|
+
"""Describes an existing App deployment, also provides details of the latest revision.
|
568
|
+
|
569
|
+
REFERENCE:
|
570
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Deployments/get_v1_apps_deployments__deploymentId_>`__
|
571
|
+
|
572
|
+
Args:
|
573
|
+
deployment_id (str): The ID of the App deployment to retrieve.
|
574
|
+
|
575
|
+
Returns:
|
576
|
+
Dict[str, Any]: Dictionary containing the details of the deployment.
|
577
|
+
|
578
|
+
Raises:
|
579
|
+
BadRequestException: The given parameters are invalid.
|
580
|
+
UnauthorizedException: The credentials are invalid.
|
581
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
582
|
+
NotFoundException: The given App deployment does not exist.
|
583
|
+
InternalServerErrorException: The server encountered an unexpected condition that
|
584
|
+
prevented it from fulfilling the request.
|
585
|
+
"""
|
586
|
+
method, endpoint = HttpMethods.GET, f"{self.DEPLOYMENTS_BASE_ENDPOINT}/{deployment_id}"
|
587
|
+
|
588
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
589
|
+
endpoint,
|
590
|
+
method,
|
591
|
+
content_type=ContentType.APPLICATION_JSON,
|
592
|
+
subdomain="press",
|
593
|
+
)
|
594
|
+
|
595
|
+
def delete_deployment(self, deployment_id: str) -> Dict[None, None]:
|
596
|
+
"""Deletes an App deployment.
|
597
|
+
|
598
|
+
REFERENCE:
|
599
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Deployments/delete_v1_apps_deployments__deploymentId_>`__
|
600
|
+
|
601
|
+
Args:
|
602
|
+
deployment_id (str): The ID of the App deployment to delete.
|
603
|
+
|
604
|
+
Returns:
|
605
|
+
dict: Empty dict object.
|
606
|
+
|
607
|
+
Raises:
|
608
|
+
BadRequestException: The given parameters are invalid.
|
609
|
+
UnauthorizedException: The credentials are invalid.
|
610
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
611
|
+
NotFoundException: The given App deployment does not exist.
|
612
|
+
UnprocessableEntityException: The server was unable to process the request.
|
613
|
+
InternalServerErrorException: the server encountered an unexpected condition that
|
614
|
+
prevented it from fulfilling the request.
|
615
|
+
"""
|
616
|
+
method, endpoint = HttpMethods.DELETE, f"{self.DEPLOYMENTS_BASE_ENDPOINT}/{deployment_id}"
|
617
|
+
|
618
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
619
|
+
endpoint,
|
620
|
+
method,
|
621
|
+
content_type=ContentType.APPLICATION_JSON,
|
622
|
+
subdomain="press",
|
623
|
+
)
|
624
|
+
|
625
|
+
def update_deployment_metadata(self, deployment_id: str, body: Dict[str, Dict[str, str]]) -> Dict[None, None]:
|
626
|
+
"""Update the metadata of an App deployment.
|
627
|
+
|
628
|
+
REFERENCE:
|
629
|
+
🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/App%20Deployments/patch_v1_apps_deployments__deploymentId_>`__
|
630
|
+
|
631
|
+
Args:
|
632
|
+
deployment_id (str): ID of the App deployment to update.
|
633
|
+
body (Dict[str, Dict[str, str]]): Dictionary of the new deployment metadata.
|
634
|
+
|
635
|
+
Returns:
|
636
|
+
dict: Details of the updated deployment.
|
637
|
+
|
638
|
+
Raises:
|
639
|
+
BadRequestException: The given parameters are invalid.
|
640
|
+
UnauthorizedException: The credentials are invalid.
|
641
|
+
ForbiddenException: The user does not have permission to perform the operation.
|
642
|
+
NotFoundException: The given App deployment does not exist.
|
643
|
+
InternalServerErrorException: the server encountered an unexpected condition that
|
644
|
+
prevented it from fulfilling the request.
|
645
|
+
"""
|
646
|
+
method, endpoint = HttpMethods.PATCH, f"{self.DEPLOYMENTS_BASE_ENDPOINT}/{deployment_id}"
|
647
|
+
|
648
|
+
return self.session.create_request( # type: ignore[no-any-return]
|
649
|
+
endpoint,
|
650
|
+
method,
|
651
|
+
content_type=ContentType.APPLICATION_JSON,
|
652
|
+
body=body,
|
653
|
+
subdomain="press",
|
654
|
+
)
|
655
|
+
|
656
|
+
|
657
|
+
def get_client(session: Optional[Session] = None) -> App:
|
658
|
+
"""Returns an App client.
|
659
|
+
|
660
|
+
Args:
|
661
|
+
session (Optional[Session]): A Session Object. If no session is provided, a default session is used.
|
662
|
+
|
663
|
+
Returns:
|
664
|
+
App: the App client object
|
665
|
+
"""
|
666
|
+
return App(session)
|
667
|
+
|
668
|
+
|
669
|
+
__all__: List[str] = ["get_client"]
|