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,703 @@
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 Workflow management service commands."""
22
+
23
+ from typing import Any, Dict, List, Optional
24
+
25
+ import typer
26
+ from peak.cli import args, helpers
27
+ from peak.helpers import parse_list_of_strings
28
+ from peak.resources.workflows import Workflow
29
+ from rich.console import Console
30
+ from typing_extensions import Annotated
31
+
32
+ app = typer.Typer(
33
+ help="Create Machine Learning Pipelines using Workflows. Please note that Workflows with only standard steps are supported.",
34
+ short_help="Create and manage Workflows.",
35
+ )
36
+ console = Console()
37
+
38
+ _WORKFLOW_STATUS = typer.Option(None, help="List of status to filter workflows.")
39
+
40
+ _LAST_EXECUTION_STATUS = typer.Option(
41
+ None,
42
+ help="List of execution status of the latest run of the workflows to filter them by.",
43
+ )
44
+
45
+ _LAST_MODIFIED_BY = typer.Option(None, help="List of users who last modified the workflow, used to filter workflows.")
46
+
47
+ _WORKFLOW_ID = typer.Argument(..., help="ID of the workflow to be used in this operation.")
48
+
49
+ _LIST_NAME = typer.Option(None, help="Workflow name to search for.")
50
+
51
+ _NAME = typer.Option(None, help="Name of the workflow")
52
+
53
+ _REPOSITORY = typer.Option(None, help="URL of the repository containing the required files.")
54
+
55
+ _BRANCH = typer.Option(None, help="The branch of the repository to use.")
56
+
57
+ _TOKEN = typer.Option(None, help="The token to use to access the repository.")
58
+
59
+ _COMMAND = typer.Option(None, help="The command to run when workflow step is executed.")
60
+
61
+ _IMAGE_ID = typer.Option(None, help="The ID of the image to use for the workflow step.")
62
+
63
+ _IMAGE_VERSION_ID = typer.Option(None, help="The ID of the image version to use for the workflow step.")
64
+
65
+ _INSTANCE_TYPE_ID = typer.Option(None, help="The ID of the instance type to use for the workflow step.")
66
+
67
+ _STORAGE = typer.Option(None, help="The storage to use for the workflow step.")
68
+
69
+ _STEP_TIMEOUT = typer.Option(None, help="The time after which the step timeouts.")
70
+
71
+ _CLEAR_IMAGE_CACHE = typer.Option(None, help="Whether to clear image cache on workflow execution.")
72
+
73
+ _STEP_NAMES = typer.Option(None, help="List of step names to be updated.")
74
+
75
+
76
+ @app.command(short_help="Create a new workflow.")
77
+ def create(
78
+ ctx: typer.Context,
79
+ file: str = args.TEMPLATE_PATH,
80
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
81
+ params: List[str] = args.TEMPLATE_PARAMS,
82
+ ) -> None:
83
+ """***Create*** a new workflow. Workflows with only standard steps are supported.
84
+
85
+ \b
86
+ 🧩 ***Input file schema(yaml):***<br/>
87
+ ```yaml
88
+ body (map):
89
+ name (string): Name of the worklfow.
90
+ tags (list(map) | required: false):
91
+ - name (string): Name of the tag.
92
+ triggers (list(map) | required: false):
93
+ - cron (string | required: false): A valid cron expression.
94
+ webhook (boolean | required: false): Should be true if webhook type trigger is to be used.
95
+ webhookPolicy (string | required: false): Policy of the webhook to be used. Should be "generate" when creating new worklfow.
96
+ watchers (list(map) | required: false):
97
+ - events (map):
98
+ success (boolean | required: false): Whether to call event on success.
99
+ fail (boolean | required: false): Whether to call event on success.
100
+ runtimeExceeded (int | required: false): The runtime after which event is called.
101
+ user (string | required: false): User to be notified.
102
+ webhook (map | required: false):
103
+ name (string): Name of the webhook.
104
+ url (string): URL of the webhook.
105
+ payload (string): Webhook payload.
106
+ steps(map):
107
+ <stepName> (map): Dictionary containing the step configuration. Here the key is name of the step.
108
+ imageId (int): ID of the existing image.
109
+ imageVersionId: (int | required: false): ID of the existing image version.
110
+ type (string | required: false): Type of workflow step. Currently only standard type is supported.
111
+ command (string): Command to run when step is executed.
112
+ clearImageCache (boolean | required: false): Whether to clear image cache on workflow execution.
113
+ stepTimeout (int | required: false): Time after which the step timeouts.
114
+ parameters (map | required: false):
115
+ env (map | required: false): Key-Value pair where key is the name of the env.
116
+ secrets (list(str) | required: false): List of secret names to be passed.
117
+ parents (list(str) | required: false): List containing names of steps on which this step is dependent on.
118
+ repository (map | required: false):
119
+ branch (string): Branch of the repository containing the required files.
120
+ token (string | required: false): The token to be used to clone the repository.
121
+ url (string): URL of the repository.
122
+ resources (map | required: false):
123
+ instanceTypeId (int): ID of the instance type to be used in the step.
124
+ storage (string): Storage in GB. For example, "10GB".
125
+ ```
126
+
127
+ \b
128
+ 📝 ***Example usage:***
129
+ ```bash
130
+ peak workflows create /path/to/file.yml -v /path/to/params.yml
131
+ ```
132
+
133
+ \b
134
+ 🆗 ***Response:***
135
+ ```json
136
+ {
137
+ "id": 123,
138
+ "triggers": [
139
+ {
140
+ "webhook": "db88c21d-1add-45dd-a72e-8c6b83b68dee"
141
+ }
142
+ ]
143
+ }
144
+ ```
145
+
146
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Workflows/create-workflow)
147
+ """
148
+ workflow_client: Workflow = ctx.obj["client"]
149
+
150
+ body: Dict[str, Any] = helpers.template_handler(file=file, params_file=params_file, params=params)
151
+ body = helpers.remove_unknown_args(body, workflow_client.create_workflow)
152
+ response: Dict[str, int] = workflow_client.create_workflow(**body)
153
+ console.print(response)
154
+
155
+
156
+ @app.command(short_help="Update an existing workflow.")
157
+ def update(
158
+ ctx: typer.Context,
159
+ workflow_id: int = _WORKFLOW_ID,
160
+ file: str = args.TEMPLATE_PATH,
161
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
162
+ params: List[str] = args.TEMPLATE_PARAMS,
163
+ ) -> None:
164
+ """***Update*** an existing workflow. Workflows with only standard steps are supported.
165
+
166
+ \b
167
+ 🧩 ***Input file schema(yaml):***<br/>
168
+ ```yaml
169
+ body (map):
170
+ name (string): Name of the worklfow.
171
+ tags (list(map) | required: false):
172
+ - name (string): Name of the tag.
173
+ triggers (list(map) | required: false):
174
+ - cron (string | required: false): A valid cron expression.
175
+ webhook (boolean | required: false): Should be true if webhook type trigger is to be used.
176
+ webhookPolicy (string | required: false): Policy of the webhook to be used. Should be "generate" or "preserve".
177
+ watchers (list(map) | required: false):
178
+ - events (map):
179
+ success (boolean | required: false): Whether to call event on success.
180
+ fail (boolean | required: false): Whether to call event on success.
181
+ runtimeExceeded (int | required: false): The runtime after which event is called.
182
+ user (string | required: false): User to be notified.
183
+ webhook (map | required: false):
184
+ name (string): Name of the webhook.
185
+ url (string): URL of the webhook.
186
+ payload (string): Webhook payload.
187
+ steps(map):
188
+ <stepName> (map): Dictionary containing the step configuration. Here the key is name of the step.
189
+ imageId (int): ID of the existing image.
190
+ imageVersionId: (int | required: false): ID of the existing image version.
191
+ type (string | required: false): Type of workflow step. Currently only standard type is supported.
192
+ command (string): Command to run when step is executed.
193
+ clearImageCache (boolean | required: false): Whether to clear image cache on workflow execution.
194
+ stepTimeout (int | required: false): Time after which the step timeouts.
195
+ parameters (map | required: false):
196
+ env (map | required: false): Key-Value pair where key is the name of the env.
197
+ secrets (list(str) | required: false): List of secret names to be passed.
198
+ parents (list(str) | required: false): List containing names of steps on which this step is dependent on.
199
+ repository (map | required: false):
200
+ branch (string): Branch of the repository containing the required files.
201
+ token (string | required: false): The token to be used to clone the repository.
202
+ url (string): URL of the repository.
203
+ resources (map | required: false):
204
+ instanceTypeId (int): ID of the instance type to be used in the step.
205
+ storage (string): Storage in GB. For example, "10GB".
206
+ ```
207
+
208
+ \b
209
+ 📝 ***Example usage:***
210
+ ```bash
211
+ peak workflows update 9999 /path/to/file.yml -v /path/to/params.yml
212
+ ```
213
+
214
+ \b
215
+ 🆗 ***Response:***
216
+ ```json
217
+ {
218
+ "id": 123,
219
+ "triggers": [
220
+ {
221
+ "webhook": "db88c21d-1add-45dd-a72e-8c6b83b68dee"
222
+ }
223
+ ]
224
+ }
225
+ ```
226
+
227
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Workflows/update-workflow)
228
+ """
229
+ workflow_client: Workflow = ctx.obj["client"]
230
+
231
+ body: Dict[str, Any] = helpers.template_handler(file=file, params_file=params_file, params=params)
232
+ body = helpers.remove_unknown_args(body, workflow_client.update_workflow)
233
+ response: Dict[str, Any] = workflow_client.update_workflow(workflow_id=workflow_id, **body)
234
+ console.print(response)
235
+
236
+
237
+ @app.command(short_help="Create a new workflow or Update an existing workflow.")
238
+ def create_or_update(
239
+ ctx: typer.Context,
240
+ file: str = args.TEMPLATE_PATH,
241
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
242
+ params: List[str] = args.TEMPLATE_PARAMS,
243
+ ) -> None:
244
+ """***Create*** a new workflow or ***Update*** an existing workflow based on workflow name.
245
+
246
+ \b
247
+ 🧩 ***Input file schema(yaml):***<br/>
248
+ ```yaml
249
+ body (map):
250
+ name (string): Name of the worklfow.
251
+ tags (list(map) | required: false):
252
+ - name (string): Name of the tag.
253
+ triggers (list(map) | required: false):
254
+ - cron (string | required: false): A valid cron expression.
255
+ webhook (boolean | required: false): Should be true if webhook type trigger is to be used.
256
+ webhookPolicy (string | required: false): Policy of the webhook to be used. Should be "generate" when creating new worklfow.
257
+ watchers (list(map) | required: false):
258
+ - events (map):
259
+ success (boolean | required: false): Whether to call event on success.
260
+ fail (boolean | required: false): Whether to call event on success.
261
+ runtimeExceeded (int | required: false): The runtime after which event is called.
262
+ user (string | required: false): User to be notified.
263
+ webhook (map | required: false):
264
+ name (string): Name of the webhook.
265
+ url (string): URL of the webhook.
266
+ payload (string): Webhook payload.
267
+ steps(map):
268
+ <stepName> (map): Dictionary containing the step configuration. Here the key is name of the step.
269
+ imageId (int): ID of the existing image.
270
+ imageVersionId: (int | required: false): ID of the existing image version.
271
+ type (string | required: false): Type of workflow step. Currently only standard type is supported.
272
+ command (string): Command to run when step is executed.
273
+ clearImageCache (boolean | required: false): Whether to clear image cache on workflow execution.
274
+ stepTimeout (int | required: false): Time after which the step timeouts.
275
+ parameters (map | required: false):
276
+ env (map | required: false): Key-Value pair where key is the name of the env.
277
+ secrets (list(str) | required: false): List of secret names to be passed.
278
+ parents (list(str) | required: false): List containing names of steps on which this step is dependent on.
279
+ repository (map | required: false):
280
+ branch (string): Branch of the repository containing the required files.
281
+ token (string | required: false): The token to be used to clone the repository.
282
+ url (string): URL of the repository.
283
+ resources (map | required: false):
284
+ instanceTypeId (int): ID of the instance type to be used in the step.
285
+ storage (string): Storage in GB. For example, "10GB".
286
+ ```
287
+
288
+ \b
289
+ 📝 ***Example usage:***
290
+ ```bash
291
+ peak workflows create-or-update /path/to/file.yml -v /path/to/params.yml
292
+ ```
293
+
294
+ \b
295
+ 🆗 ***Response:***
296
+ ```json
297
+ {
298
+ "id": 123,
299
+ "triggers": [
300
+ {
301
+ "webhook": "db88c21d-1add-45dd-a72e-8c6b83b68dee"
302
+ }
303
+ ]
304
+ }
305
+ ```
306
+
307
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Workflows/create-workflow)
308
+ """
309
+ workflow_client: Workflow = ctx.obj["client"]
310
+
311
+ body: Dict[str, Any] = helpers.template_handler(file=file, params_file=params_file, params=params)
312
+ body = helpers.remove_unknown_args(body, workflow_client.create_or_update_workflow)
313
+ response: Dict[str, int] = workflow_client.create_or_update_workflow(**body)
314
+ console.print(response)
315
+
316
+
317
+ @app.command(short_help="Update required fields of an existing workflow.")
318
+ def patch(
319
+ ctx: typer.Context,
320
+ workflow_id: int = _WORKFLOW_ID,
321
+ file: Annotated[
322
+ Optional[str],
323
+ typer.Argument(
324
+ ...,
325
+ help="Path to the file that defines the body for this operation, supports both `yaml` file or a `jinja` template.",
326
+ ),
327
+ ] = None,
328
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
329
+ params: List[str] = args.TEMPLATE_PARAMS,
330
+ name: str = _NAME,
331
+ repository: str = _REPOSITORY,
332
+ branch: str = _BRANCH,
333
+ token: str = _TOKEN,
334
+ image_id: int = _IMAGE_ID,
335
+ image_version_id: int = _IMAGE_VERSION_ID,
336
+ command: str = _COMMAND,
337
+ clear_image_cache: bool = _CLEAR_IMAGE_CACHE,
338
+ step_timeout: int = _STEP_TIMEOUT,
339
+ instance_type_id: int = _INSTANCE_TYPE_ID,
340
+ storage: str = _STORAGE,
341
+ step_names: List[str] = _STEP_NAMES,
342
+ ) -> None:
343
+ """***Update*** an existing workflow. Workflows with only standard steps are supported.
344
+
345
+ \b
346
+ This command allows to efficiently modify trigger details, watchers, workflow name, and specific step attributes such as repository URL, branch, token, image ID, version ID etc.
347
+
348
+ \b
349
+ By specifying step_names, we can globally update specified steps with provided parameters, streamlining the update process. If step_names is not provided, all the steps for that workflow would be updated.
350
+
351
+ \b
352
+ Alternatively, we can selectively modify individual step attributes across different steps by providing the details in the yaml file. With this, we can also add new steps to the workflow by providing the parameters required by the step.
353
+
354
+ \b
355
+ If both body and specific parameters are used, the latter takes precedence.
356
+
357
+ \b
358
+ 🧩 ***Input file schema(yaml):***<br/>
359
+ ```yaml
360
+ body (map | required: false):
361
+ name (string | required: false): Name of the worklfow.
362
+ tags (list(map) | required: false):
363
+ - name (string): Name of the tag.
364
+ triggers (list(map) | required: false):
365
+ - cron (string | required: false): A valid cron expression.
366
+ webhook (boolean | required: false): Should be true if webhook type trigger is to be used.
367
+ webhookPolicy (string | required: false): Policy of the webhook to be used. Should be "generate" or "preserve".
368
+ watchers (list(map) | required: false):
369
+ - events (map):
370
+ success (boolean | required: false): Whether to call event on success.
371
+ fail (boolean | required: false): Whether to call event on success.
372
+ runtimeExceeded (int | required: false): The runtime after which event is called.
373
+ user (string | required: false): User to be notified.
374
+ webhook (map | required: false):
375
+ name (string): Name of the webhook.
376
+ url (string): URL of the webhook.
377
+ payload (string): Webhook payload.
378
+ steps(map):
379
+ <stepName> (map): Dictionary containing the step configuration. Here the key is name of the step.
380
+ imageId (int): ID of the existing image.
381
+ imageVersionId: (int | required: false): ID of the existing image version.
382
+ type (string | required: false): Type of workflow step. Currently only standard type is supported.
383
+ command (string): Command to run when step is executed.
384
+ clearImageCache (boolean | required: false): Whether to clear image cache on workflow execution.
385
+ stepTimeout (int | required: false): Time after which the step timeouts.
386
+ parameters (map | required: false):
387
+ env (map | required: false): Key-Value pair where key is the name of the env.
388
+ secrets (list(str) | required: false): List of secret names to be passed.
389
+ parents (list(str) | required: false): List containing names of steps on which this step is dependent on.
390
+ repository (map | required: false):
391
+ branch (string): Branch of the repository containing the required files.
392
+ token (string | required: false): The token to be used to clone the repository.
393
+ url (string): URL of the repository.
394
+ resources (map | required: false):
395
+ instanceTypeId (int): ID of the instance type to be used in the step.
396
+ storage (string): Storage in GB. For example, "10GB".
397
+ ```
398
+
399
+ \b
400
+ 📝 ***Example usage:***
401
+ ```bash
402
+ peak workflows patch 9999 /path/to/file.yml -v /path/to/params.yml
403
+ ```
404
+
405
+ \b
406
+ 📝 ***Example usage for updating workflow by passing only required parameters:***
407
+ ```bash
408
+ peak workflows patch 9999 --name <workflow_name> --image-id <image-id> --version-id <image-version-id> --step-names <step-name-1>,<step-name-2>
409
+ ```
410
+
411
+ \b
412
+ 🆗 ***Response:***
413
+ ```js
414
+ {
415
+ "triggers": [
416
+ {
417
+ "webhook": "db88c21d-1add-45dd-a72e-8c6b83b68dee"
418
+ }
419
+ ]
420
+ "id": 9999,
421
+ }
422
+ ```
423
+ """
424
+ workflow_client: Workflow = ctx.obj["client"]
425
+ body: Dict[str, Any] = {}
426
+
427
+ if file:
428
+ body = helpers.template_handler(file=file, params_file=params_file, params=params)
429
+ body = helpers.remove_unknown_args(body, workflow_client.patch_workflow)
430
+ response: Dict[str, Any] = workflow_client.patch_workflow(
431
+ workflow_id=workflow_id,
432
+ body=body["body"] if body else {},
433
+ step_names=step_names,
434
+ name=name,
435
+ repository=repository,
436
+ branch=branch,
437
+ token=token,
438
+ image_id=image_id,
439
+ image_version_id=image_version_id,
440
+ command=command,
441
+ clear_image_cache=clear_image_cache,
442
+ step_timeout=step_timeout,
443
+ instance_type_id=instance_type_id,
444
+ storage=storage,
445
+ )
446
+ console.print(response)
447
+
448
+
449
+ @app.command("list", short_help="List workflows.")
450
+ def list_workflows(
451
+ ctx: typer.Context,
452
+ page_size: Optional[int] = args.PAGE_SIZE,
453
+ page_number: Optional[int] = args.PAGE_NUMBER,
454
+ workflow_status: Optional[List[str]] = _WORKFLOW_STATUS,
455
+ last_execution_status: Optional[List[str]] = _LAST_EXECUTION_STATUS,
456
+ last_modified_by: Optional[List[str]] = _LAST_MODIFIED_BY,
457
+ name: Optional[str] = _LIST_NAME,
458
+ ) -> None:
459
+ """***List*** all workflows that exist for the tenant.
460
+
461
+ \b
462
+ 📝 ***Example usage:***<br/>
463
+ ```bash
464
+ peak workflows list --page-size 10 --page-number 1 --workflow_status "Draft" --last_execution_status "Success" --last_modified_by "abc@peak.ai" --name "test"
465
+ ```
466
+
467
+ \b
468
+ 🆗 ***Response:***
469
+ ```
470
+ {
471
+ "pageCount": 1,
472
+ "pageNumber": 1,
473
+ "pageSize": 25,
474
+ "workflows": [...],
475
+ "workflowsCount": 1
476
+ }
477
+ ```
478
+
479
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Workflows/get-workflows)
480
+ """
481
+ workflow_client: Workflow = ctx.obj["client"]
482
+ response = workflow_client.list_workflows(
483
+ page_size=page_size,
484
+ page_number=page_number,
485
+ workflow_status=parse_list_of_strings(workflow_status),
486
+ last_execution_status=parse_list_of_strings(last_execution_status),
487
+ last_modified_by=parse_list_of_strings(last_modified_by),
488
+ name=name,
489
+ return_iterator=False,
490
+ )
491
+ console.print(response)
492
+
493
+
494
+ @app.command(short_help="Describe details of a workflow.")
495
+ def describe(ctx: typer.Context, workflow_id: int = _WORKFLOW_ID) -> None:
496
+ """***Describe*** details of a specific workflow. Workflows with only standard steps are supported.
497
+
498
+ \b
499
+ 📝 ***Example usage:***<br/>
500
+ ```bash
501
+ peak workflows describe 9999
502
+ ```
503
+
504
+ \b
505
+ 🆗 ***Response:***
506
+ ```
507
+ {
508
+ "id": 9999,
509
+ "name": "workflow-name",
510
+ "createdAt": "2020-01-01T18:00:00.000Z",
511
+ "updatedAt": "2020-01-01T18:00:00.000Z",
512
+ "status": "Available",
513
+ "steps": {
514
+ "step-name": {...}
515
+ },
516
+ "lastExecution": {...},
517
+ "triggers": [...],
518
+ "watchers": [...],
519
+ "tags": [...]
520
+ }
521
+ ```
522
+
523
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Workflows/describe-workflow)
524
+ """
525
+ workflow_client: Workflow = ctx.obj["client"]
526
+ response = workflow_client.describe_workflow(workflow_id=workflow_id)
527
+ console.print(response)
528
+
529
+
530
+ @app.command(short_help="Delete a workflow.")
531
+ def delete(ctx: typer.Context, workflow_id: int = _WORKFLOW_ID) -> None:
532
+ """***Delete*** a workflow.
533
+
534
+ \b
535
+ 📝 ***Example usage:***<br/>
536
+ ```bash
537
+ peak workflows delete 9999
538
+ ```
539
+
540
+ \b
541
+ 🆗 ***Response:***
542
+ ```json
543
+ {}
544
+ ```
545
+
546
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Workflows/delete-workflow)
547
+ """
548
+ workflow_client: Workflow = ctx.obj["client"]
549
+ response = workflow_client.delete_workflow(workflow_id=workflow_id)
550
+ console.print(response)
551
+
552
+
553
+ @app.command(short_help="Start a workflow run.")
554
+ def execute(
555
+ ctx: typer.Context,
556
+ workflow_id: int = _WORKFLOW_ID,
557
+ file: Annotated[Optional[str], args.TEMPLATE_PATH] = None,
558
+ params_file: str = args.TEMPLATE_PARAMS_FILE,
559
+ params: List[str] = args.TEMPLATE_PARAMS,
560
+ ) -> None:
561
+ """***Start*** a workflow run. This allows you to pass dynamic parameters to the workflow while running it.
562
+
563
+ \b
564
+ 🧩 ***Input file schema(yaml):***<br/>
565
+ ```yaml
566
+ body (map):
567
+ params (map | required: false):
568
+ global (map | required: false):
569
+ <keyName> (string | required: false): Key-Value pair. Key is the name of the param which and value is the value of the param.
570
+ stepWise (map | required: false):
571
+ <stepName> (map | required: false): Parameters to be passed to the step with name `stepName`.
572
+ <keyName> (string | required: false): Key-Value pair. Key is the name of the param which and value is the value of the param.
573
+ ```
574
+
575
+ \b
576
+ 📝 ***Example usage:***
577
+ ```bash
578
+ peak workflows execute 9999 /path/to/file.yml -v /path/to/params.yml
579
+ ```
580
+
581
+ \b
582
+ 🆗 ***Response:***
583
+ ```json
584
+ {
585
+ "executionId": "d6116a56-6b1d-41b4-a599-fb949f08863f"
586
+ }
587
+ ```
588
+
589
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Workflows/execute-workflow)
590
+ """
591
+ workflow_client: Workflow = ctx.obj["client"]
592
+
593
+ response: Dict[str, str] = {}
594
+
595
+ if file:
596
+ body: Dict[str, Any] = helpers.template_handler(file=file, params_file=params_file, params=params)
597
+ body = helpers.remove_unknown_args(body, workflow_client.execute_workflow)
598
+
599
+ response = workflow_client.execute_workflow(workflow_id=workflow_id, **body)
600
+ else:
601
+ response = workflow_client.execute_workflow(workflow_id=workflow_id)
602
+
603
+ console.print(response)
604
+
605
+
606
+ @app.command(short_help="List all available resources.")
607
+ def list_resources(ctx: typer.Context) -> None:
608
+ """***List*** all available resources that can be used in workflow steps.
609
+
610
+ \b
611
+ 📝 ***Example usage:***<br/>
612
+ ```bash
613
+ peak workflows list-resources
614
+ ```
615
+
616
+ \b
617
+ 🆗 ***Response:***
618
+ ```json
619
+ [
620
+ {
621
+ "cpu": 0.25,
622
+ "gpu": null,
623
+ "gpuMemory": null,
624
+ "id": 21,
625
+ "memory": 0.5
626
+ }
627
+ ]
628
+ ```
629
+
630
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Resources/get-resources)
631
+ """
632
+ workflow_client: Workflow = ctx.obj["client"]
633
+ response = workflow_client.list_resources()
634
+ console.print(response)
635
+
636
+
637
+ @app.command(short_help="List default resources.")
638
+ def list_default_resources(ctx: typer.Context) -> None:
639
+ """***List*** default resources for the workflows.
640
+
641
+ \b
642
+ 📝 ***Example usage:***<br/>
643
+ ```bash
644
+ peak workflows list-default-resources
645
+ ```
646
+
647
+ \b
648
+ 🆗 ***Response:***
649
+ ```json
650
+ {
651
+ "instanceTypeId": 21,
652
+ "storage": "10GB"
653
+ }
654
+ ```
655
+
656
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Resources/get-default-resources)
657
+ """
658
+ workflow_client: Workflow = ctx.obj["client"]
659
+ response = workflow_client.get_default_resource()
660
+ console.print(response)
661
+
662
+
663
+ @app.command(short_help="List executions for the given workflow.")
664
+ def list_executions(
665
+ ctx: typer.Context,
666
+ workflow_id: int = _WORKFLOW_ID,
667
+ date_from: Optional[str] = args.DATE_FROM,
668
+ date_to: Optional[str] = args.DATE_TO,
669
+ page_size: Optional[int] = args.PAGE_SIZE,
670
+ page_number: Optional[int] = args.PAGE_NUMBER,
671
+ ) -> None:
672
+ """***List*** executions for the given workflow.
673
+
674
+ \b
675
+ 📝 ***Example usage:***<br/>
676
+ ```bash
677
+ peak workflows list-executions 9999 --page-size 10 --page-number 1
678
+ ```
679
+
680
+ \b
681
+ 🆗 ***Response:***
682
+ ```
683
+ {
684
+ "executions": [...],
685
+ "pageSize": 25,
686
+ "pageNumber": 1,
687
+ "pageCount": 1,
688
+ "workflowId": 11876
689
+ }
690
+ ```
691
+
692
+ 🔗 [**API Documentation**](https://service.peak.ai/workflows/api-docs/index.htm#/Executions/get-workflow-executions)
693
+ """
694
+ workflow_client: Workflow = ctx.obj["client"]
695
+ response = workflow_client.list_executions(
696
+ workflow_id=workflow_id,
697
+ date_from=date_from,
698
+ date_to=date_to,
699
+ page_size=page_size,
700
+ page_number=page_number,
701
+ return_iterator=False,
702
+ )
703
+ console.print(response)