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.
Files changed (51) hide show
  1. peak/__init__.py +36 -0
  2. peak/_version.py +21 -0
  3. peak/auth.py +22 -0
  4. peak/base_client.py +52 -0
  5. peak/cli/__init_.py +20 -0
  6. peak/cli/args.py +84 -0
  7. peak/cli/cli.py +56 -0
  8. peak/cli/helpers.py +187 -0
  9. peak/cli/press/__init__.py +21 -0
  10. peak/cli/press/apps/__init__.py +40 -0
  11. peak/cli/press/apps/deployments.py +238 -0
  12. peak/cli/press/apps/specs.py +387 -0
  13. peak/cli/press/blocks/__init__.py +40 -0
  14. peak/cli/press/blocks/deployments.py +240 -0
  15. peak/cli/press/blocks/specs.py +492 -0
  16. peak/cli/press/deployments.py +78 -0
  17. peak/cli/press/specs.py +131 -0
  18. peak/cli/resources/__init__.py +21 -0
  19. peak/cli/resources/artifacts.py +310 -0
  20. peak/cli/resources/images.py +886 -0
  21. peak/cli/resources/webapps.py +356 -0
  22. peak/cli/resources/workflows.py +703 -0
  23. peak/cli/ruff.toml +11 -0
  24. peak/cli/version.py +49 -0
  25. peak/compression.py +162 -0
  26. peak/config.py +24 -0
  27. peak/constants.py +105 -0
  28. peak/exceptions.py +217 -0
  29. peak/handler.py +358 -0
  30. peak/helpers.py +184 -0
  31. peak/logger.py +48 -0
  32. peak/press/__init__.py +28 -0
  33. peak/press/apps.py +669 -0
  34. peak/press/blocks.py +707 -0
  35. peak/press/deployments.py +145 -0
  36. peak/press/specs.py +260 -0
  37. peak/py.typed +0 -0
  38. peak/resources/__init__.py +28 -0
  39. peak/resources/artifacts.py +343 -0
  40. peak/resources/images.py +675 -0
  41. peak/resources/webapps.py +278 -0
  42. peak/resources/workflows.py +625 -0
  43. peak/session.py +259 -0
  44. peak/telemetry.py +201 -0
  45. peak/template.py +231 -0
  46. peak/validators.py +48 -0
  47. peak_sdk-1.0.0.dist-info/LICENSE +201 -0
  48. peak_sdk-1.0.0.dist-info/METADATA +199 -0
  49. peak_sdk-1.0.0.dist-info/RECORD +51 -0
  50. peak_sdk-1.0.0.dist-info/WHEEL +4 -0
  51. peak_sdk-1.0.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,131 @@
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
+ """Peak specs commands."""
22
+ from typing import List, Optional
23
+
24
+ import typer
25
+ from peak.cli import args
26
+ from peak.press.specs import Spec
27
+ from rich.console import Console
28
+
29
+ app = typer.Typer(
30
+ help="Manage both Block and App specs.",
31
+ short_help="Manage both Block and App specs.",
32
+ )
33
+ console = Console()
34
+
35
+
36
+ @app.command("list", short_help="List App and Block specs.")
37
+ def list_specs(
38
+ ctx: typer.Context,
39
+ page_size: Optional[int] = args.PAGE_SIZE,
40
+ page_number: Optional[int] = args.PAGE_NUMBER,
41
+ status: Optional[List[str]] = args.STATUS_FILTER,
42
+ kind: Optional[str] = args.KIND_FILTER,
43
+ term: Optional[str] = args.TERM_FILTER,
44
+ sort: Optional[List[str]] = args.SORT_KEYS,
45
+ scope: Optional[List[str]] = args.SCOPES,
46
+ featured: Optional[bool] = args.FEATURED,
47
+ ) -> None:
48
+ """***List*** all the App and Block specs that exists for the tenant.
49
+
50
+ \b
51
+ 📝 ***Example usage:***<br/>
52
+ ```bash
53
+ peak specs list --featured --page-size 10 --page-number 1
54
+ ```
55
+
56
+ \b
57
+ 🆗 ***Response:***
58
+ ```
59
+ {
60
+ "specCount": 1,
61
+ "specs": [...],
62
+ "pageCount": 1,
63
+ "pageNumber": 1,
64
+ "pageSize": 10
65
+ }
66
+ ```
67
+
68
+ 🔗 [**API Documentation**](https://press.peak.ai/api-docs/index.htm#/Specs/get_v1_specs)
69
+ """
70
+ spec_client: Spec = ctx.obj["client"]
71
+ response = spec_client.list_specs(
72
+ status=status,
73
+ featured=featured,
74
+ kind=kind,
75
+ term=term,
76
+ sort=sort,
77
+ scope=scope,
78
+ page_size=page_size,
79
+ page_number=page_number,
80
+ return_iterator=False,
81
+ )
82
+ console.print(response)
83
+
84
+
85
+ @app.command(short_help="List deployments for a spec release.")
86
+ def list_release_deployments(
87
+ ctx: typer.Context,
88
+ spec_id: str = args.SPEC_ID,
89
+ version: str = args.RELEASE_VERSION,
90
+ page_size: Optional[int] = args.PAGE_SIZE,
91
+ page_number: Optional[int] = args.PAGE_NUMBER,
92
+ status: Optional[List[str]] = args.STATUS_FILTER,
93
+ name: Optional[str] = args.NAME_FILTER,
94
+ title: Optional[str] = args.TITLE_FILTER,
95
+ sort: Optional[List[str]] = args.SORT_KEYS,
96
+ ) -> None:
97
+ """***List*** all the deployments for a given spec release.
98
+
99
+ \b
100
+ 📝 ***Example usage:***<br/>
101
+ ```bash
102
+ peak specs list-release-deployments --spec-id "632a4e7c-ab86-4ecb-8f34-99b5da531ceb" --status deployed,failed --version 1.0.0
103
+ ```
104
+
105
+ \b
106
+ 🆗 ***Response:***
107
+ ```
108
+ {
109
+ "deploymentCount": 1,
110
+ "deployments": [...],
111
+ "pageCount": 1,
112
+ "pageNumber": 1,
113
+ "pageSize": 10,
114
+ }
115
+ ```
116
+
117
+ 🔗 [**API Documentation**](https://press.peak.ai/api-docs/index.htm#/Specs/get_v1_specs__specId__releases__release__deployments)
118
+ """
119
+ spec_client: Spec = ctx.obj["client"]
120
+ response = spec_client.list_spec_release_deployments(
121
+ spec_id=spec_id,
122
+ version=version,
123
+ status=status,
124
+ name=name,
125
+ title=title,
126
+ sort=sort,
127
+ page_size=page_size,
128
+ page_number=page_number,
129
+ return_iterator=False,
130
+ )
131
+ console.print(response)
@@ -0,0 +1,21 @@
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
+ """Resources Module."""
@@ -0,0 +1,310 @@
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
+ """Peak Artifacts service commands."""
22
+ from typing import Any, Dict, List, Optional
23
+
24
+ import typer
25
+ from peak.cli import args, helpers
26
+ from peak.resources.artifacts import Artifact
27
+ from rich.console import Console
28
+
29
+ app = typer.Typer(
30
+ help="Manage artifacts used to create resources like images.",
31
+ short_help="Create and manage Artifacts.",
32
+ )
33
+ console = Console()
34
+
35
+ _ARTIFACT_ID = typer.Argument(..., help="ID of the artifact to be used in this operation.")
36
+
37
+ _DOWNLOAD_PATH = typer.Argument(..., help="Path (including filename) where the downloaded file will be stored.")
38
+
39
+ _DOWNLOAD_VERSION = typer.Option(
40
+ None,
41
+ help="Artifact version to download. If no version is given then latest version is downloaded.",
42
+ )
43
+
44
+ _DELETE_VERSION = typer.Argument(..., help="Artifact version number to delete.")
45
+
46
+
47
+ @app.command("list", short_help="List artifacts.")
48
+ def list_artifacts(
49
+ ctx: typer.Context,
50
+ page_size: Optional[int] = args.PAGE_SIZE,
51
+ page_number: Optional[int] = args.PAGE_NUMBER,
52
+ ) -> None:
53
+ """***List*** all artifacts for the given tenant.
54
+
55
+ \b
56
+ 📝 ***Example Usage:***<br/>
57
+ ```bash
58
+ peak artifacts list --page-size 10 --page-number 1
59
+ ```
60
+
61
+ \b
62
+ 🆗 ***Response:***
63
+ ```
64
+ {
65
+ "artifactCount": 1,
66
+ "artifacts": [...],
67
+ "pageCount": 1,
68
+ "pageNumber": 1,
69
+ "pageSize": 25
70
+ }
71
+ ```
72
+
73
+ 🔗 [**API Documentation**](https://service.peak.ai/artifacts/api-docs/index.htm#/artifacts/get_api_v1_artifacts)
74
+ """
75
+ artifact_client: Artifact = ctx.obj["client"]
76
+ response = artifact_client.list_artifacts(page_size=page_size, page_number=page_number, return_iterator=False)
77
+ console.print(response)
78
+
79
+
80
+ @app.command(short_help="Describe an artifact.")
81
+ def describe(
82
+ ctx: typer.Context,
83
+ artifact_id: str = _ARTIFACT_ID,
84
+ page_number: Optional[int] = args.PAGE_NUMBER,
85
+ page_size: Optional[int] = args.PAGE_SIZE,
86
+ ) -> None:
87
+ """***Describe*** an artifact with list of its versions.
88
+
89
+ \b
90
+ 📝 ***Example usage:***<br/>
91
+ ```bash
92
+ peak artifacts describe "c7575459-e265-4944-a539-1fbb3336799e" --page-size 10 --page-number 1
93
+ ```
94
+
95
+ \b
96
+ 🆗 ***Response:***
97
+ ```
98
+ {
99
+ "description": "description of this artifact",
100
+ "id": "c7575459-e265-4944-a539-1fbb3336799e",
101
+ "name": "my-artifact",
102
+ "pageCount": 1,
103
+ "pageNumber": 1,
104
+ "pageSize": 1,
105
+ "versionCount": 1,
106
+ "versions": [...]
107
+ }
108
+ ```
109
+
110
+ 🔗 [**API Documentation**](https://service.peak.ai/artifacts/api-docs/index.htm#/artifacts/get_api_v1_artifacts__artifactId_)
111
+ """
112
+ artifact_client: Artifact = ctx.obj["client"]
113
+ response = artifact_client.describe_artifact(artifact_id=artifact_id, page_number=page_number, page_size=page_size)
114
+ console.print(response)
115
+
116
+
117
+ @app.command(short_help="Delete an artifact.")
118
+ def delete(ctx: typer.Context, artifact_id: str = _ARTIFACT_ID) -> None:
119
+ """***Delete*** an artifact along with all of its versions.
120
+
121
+ \b
122
+ 📝 ***Example usage:***<br/>
123
+ ```bash
124
+ peak artifacts delete "c7575459-e265-4944-a539-1fbb3336799e"
125
+ ```
126
+
127
+ \b
128
+ 🆗 ***Response:***
129
+ ```json
130
+ {}
131
+ ```
132
+
133
+ 🔗 [**API Documentation**](https://service.peak.ai/artifacts/api-docs/index.htm#/artifacts/delete_api_v1_artifacts__artifactId_)
134
+ """
135
+ artifact_client: Artifact = ctx.obj["client"]
136
+ response = artifact_client.delete_artifact(artifact_id=artifact_id)
137
+ console.print(response)
138
+
139
+
140
+ @app.command(short_help="Create a new artifact.")
141
+ def create(
142
+ ctx: typer.Context,
143
+ file: str = args.TEMPLATE_PATH,
144
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
145
+ params: List[str] = args.TEMPLATE_PARAMS,
146
+ ) -> None:
147
+ """***Create*** a new artifact. This also creates the first version inside the artifact.
148
+
149
+ \b
150
+ 🧩 ***Input File Schema(yaml):***<br/>
151
+ ```yaml
152
+ name (str): Name of the artifact.
153
+ description (str): Description of the artifact.
154
+ artifact (map):
155
+ path (str): Path to the artifact.
156
+ ignore_files (list(str) | required: false): Ignore files to use when creating artifact.
157
+ ```
158
+
159
+ \b
160
+ 📝 ***Example Usage:***
161
+ ```bash
162
+ peak artifacts create '/path/to/body.yaml' --params-file '/path/to/params.yaml'
163
+ ```
164
+
165
+ \b
166
+ 🆗 ***Response:***
167
+ ```json
168
+ {
169
+ "id": "c7575459-e265-4944-a539-1fbb3336799e",
170
+ "version": 1
171
+ }
172
+ ```
173
+
174
+ 🔗 [**API Documentation**](https://service.peak.ai/artifacts/api-docs/index.htm#/artifacts/post_api_v1_artifacts)
175
+ """
176
+ artifact_client: Artifact = ctx.obj["client"]
177
+ body = helpers.template_handler(file=file, params_file=params_file, params=params)
178
+ body = helpers.remove_unknown_args(body, artifact_client.create_artifact)
179
+ response: Dict[str, Any] = artifact_client.create_artifact(**body)
180
+ console.print(response)
181
+
182
+
183
+ @app.command(short_help="Update an artifact's metadata.")
184
+ def update_metadata(
185
+ ctx: typer.Context,
186
+ artifact_id: str = _ARTIFACT_ID,
187
+ file: str = args.TEMPLATE_PATH,
188
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
189
+ params: List[str] = args.TEMPLATE_PARAMS,
190
+ ) -> None:
191
+ """***Update*** an artifact's metadata.
192
+
193
+ \b
194
+ 🧩 ***Input file schema(yaml):***<br/>
195
+ ```yaml
196
+ body (map): Artifact metadata.
197
+ ```
198
+
199
+ \b
200
+ 📝 ***Example usage:***
201
+ ```bash
202
+ peak artifacts update-metadata '/path/to/body.yaml' --params-file '/path/to/params.yaml'
203
+ ```
204
+
205
+ \b
206
+ 🆗 ***Response:***
207
+ ```json
208
+ {}
209
+ ```
210
+
211
+ 🔗 [**API Documentation**](https://service.peak.ai/artifacts/api-docs/index.htm#/artifacts/patch_api_v1_artifacts__artifactId_)
212
+ """
213
+ artifact_client: Artifact = ctx.obj["client"]
214
+
215
+ body: Dict[str, Any] = helpers.template_handler(file=file, params_file=params_file, params=params)
216
+ body = helpers.remove_unknown_args(body, artifact_client.update_artifact)
217
+ response: Dict[None, None] = artifact_client.update_artifact(artifact_id, **body)
218
+ console.print(response)
219
+
220
+
221
+ @app.command(short_help="Download an artifact.")
222
+ def download(
223
+ ctx: typer.Context,
224
+ artifact_id: str = _ARTIFACT_ID,
225
+ download_path: str = _DOWNLOAD_PATH,
226
+ version: Optional[int] = _DOWNLOAD_VERSION,
227
+ ) -> None:
228
+ """***Download*** a specific version for an artifact and save it with the given filename on the local system.
229
+
230
+ \b
231
+ 📝 ***Example usage:***<br/>
232
+ ```bash
233
+ peak artifacts download "c7575459-e265-4944-a539-1fbb3336799e" '/path/to/download' --version 1
234
+ ```
235
+
236
+ \b
237
+ 🆗 ***Response:***
238
+ ```python
239
+ None
240
+ ```
241
+
242
+ 🔗 [**API Documentation**](https://service.peak.ai/artifacts/api-docs/index.htm#/artifacts/get_api_v1_artifacts__artifactId__download)
243
+ """
244
+ artifact_client: Artifact = ctx.obj["client"]
245
+ artifact_client.download_artifact(artifact_id=artifact_id, download_path=download_path, version=version)
246
+
247
+
248
+ @app.command(short_help="Create a new version of the artifact.")
249
+ def create_version(
250
+ ctx: typer.Context,
251
+ artifact_id: str = _ARTIFACT_ID,
252
+ file: str = args.TEMPLATE_PATH,
253
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
254
+ params: List[str] = args.TEMPLATE_PARAMS,
255
+ ) -> None:
256
+ """***Create*** a new version of the artifact.
257
+
258
+ \b
259
+ 🧩 ***Input file schema(yaml):***<br/>
260
+ ```yaml
261
+ artifact (map):
262
+ path (str): Path to the artifact.
263
+ ignore_files (list(str) | required: false): Ignore files to use when creating artifact.
264
+ ```
265
+
266
+ \b
267
+ 📝 ***Example usage:***
268
+ ```bash
269
+ peak artifacts create-version "c7575459-e265-4944-a539-1fbb3336799e" '/path/to/body.yaml' --params-file '/path/to/params.yaml'
270
+ ```
271
+
272
+ \b
273
+ 🆗 ***Response:***
274
+ ```json
275
+ {
276
+ "version": 2
277
+ }
278
+ ```
279
+
280
+ 🔗 [**API Documentation**](https://service.peak.ai/artifacts/api-docs/index.htm#/artifacts/put_api_v1_artifacts__artifactId_)
281
+ """
282
+ artifact_client: Artifact = ctx.obj["client"]
283
+
284
+ body: Dict[str, Any] = helpers.template_handler(file=file, params_file=params_file, params=params)
285
+ body = helpers.remove_unknown_args(body, artifact_client.create_artifact_version)
286
+ response: Dict[str, int] = artifact_client.create_artifact_version(artifact_id=artifact_id, **body)
287
+ console.print(response)
288
+
289
+
290
+ @app.command(short_help="Delete a version of an artifact.")
291
+ def delete_version(ctx: typer.Context, artifact_id: str = _ARTIFACT_ID, version: int = _DELETE_VERSION) -> None:
292
+ """***Delete*** a version of an artifact.
293
+
294
+ \b
295
+ 📝 ***Example usage:***<br/>
296
+ ```bash
297
+ peak artifacts delete-version "c7575459-e265-4944-a539-1fbb3336799e" 1
298
+ ```
299
+
300
+ \b
301
+ 🆗 ***Response:***
302
+ ```json
303
+ {}
304
+ ```
305
+
306
+ 🔗 [**API Documentation**](https://service.peak.ai/artifacts/api-docs/index.htm#/artifacts/delete_api_v1_artifacts__artifactId___version_)
307
+ """
308
+ artifact_client: Artifact = ctx.obj["client"]
309
+ response = artifact_client.delete_artifact_version(artifact_id=artifact_id, version=version)
310
+ console.print(response)