peak-sdk 1.2.1__py3-none-any.whl → 1.4.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 CHANGED
@@ -20,7 +20,7 @@
20
20
  #
21
21
  """This file is part of the peak-sdk framework.
22
22
 
23
- Copyright © 2023 Peak AI
23
+ Copyright © 2024 Peak AI
24
24
 
25
25
  Unauthorized copying of this file, via any medium is strictly prohibited.
26
26
  """
peak/_metadata.py CHANGED
@@ -241,6 +241,37 @@ command_metadata: Dict[str, Any] = {
241
241
  "subheader_key": "webappsCount",
242
242
  },
243
243
  },
244
+ "list_services": {
245
+ "table_params": {
246
+ "output_keys": {
247
+ "id": {
248
+ "label": "ID",
249
+ },
250
+ "name": {
251
+ "label": "Name",
252
+ },
253
+ "serviceType": {
254
+ "label": "Service Type",
255
+ },
256
+ "status": {
257
+ "label": "Status",
258
+ },
259
+ "updatedBy": {
260
+ "label": "Updated By",
261
+ },
262
+ "updatedAt": {
263
+ "label": "Updated At (UTC)",
264
+ },
265
+ "tags": {
266
+ "label": "Tags",
267
+ "parser": tag_parser,
268
+ },
269
+ },
270
+ "title": "Services",
271
+ "data_key": "services",
272
+ "subheader_key": "servicesCount",
273
+ },
274
+ },
244
275
  "list_artifacts": {
245
276
  "table_params": {
246
277
  "output_keys": {
@@ -637,6 +668,18 @@ command_metadata: Dict[str, Any] = {
637
668
  "create_or_update_webapp": {
638
669
  "request_body_yaml_path": "sample_yaml/resources/webapps/create_or_update_webapp.yaml",
639
670
  },
671
+ "create_service": {
672
+ "request_body_yaml_path": "sample_yaml/resources/services/create_service.yaml",
673
+ },
674
+ "update_service": {
675
+ "request_body_yaml_path": "sample_yaml/resources/services/update_service.yaml",
676
+ },
677
+ "create_or_update_service": {
678
+ "request_body_yaml_path": "sample_yaml/resources/services/create_or_update_service.yaml",
679
+ },
680
+ "test_service": {
681
+ "request_body_yaml_path": "sample_yaml/resources/services/test_service.yaml",
682
+ },
640
683
  "create_app_spec": {
641
684
  "request_body_yaml_path": "sample_yaml/press/apps/specs/create_app_spec.yaml",
642
685
  },
peak/_version.py CHANGED
@@ -18,4 +18,4 @@
18
18
  # # You should have received a copy of the APACHE LICENSE, VERSION 2.0
19
19
  # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
20
  #
21
- __version__: str = "1.2.1"
21
+ __version__: str = "1.4.0"
peak/cli/args.py CHANGED
@@ -33,6 +33,15 @@ TEMPLATE_PATH = typer.Argument(
33
33
  """,
34
34
  )
35
35
 
36
+ TEMPLATE_DESCRIPTION_FILE = typer.Option(
37
+ None,
38
+ "--desc-file",
39
+ "-d",
40
+ help="""
41
+ Path to the file that defines the description for this operation, supports `md`, and `txt` files only.
42
+ """,
43
+ )
44
+
36
45
  TEMPLATE_PARAMS_FILE = typer.Option(
37
46
  None,
38
47
  "--params-file",
peak/cli/cli.py CHANGED
@@ -25,7 +25,7 @@ import peak.config
25
25
  import typer
26
26
  from peak.cli import args, helpers
27
27
  from peak.cli.press import apps, blocks, deployments, specs
28
- from peak.cli.resources import artifacts, images, tenants, webapps, workflows
28
+ from peak.cli.resources import artifacts, images, services, tenants, webapps, workflows
29
29
  from peak.constants import Sources
30
30
  from peak.output import Writer
31
31
 
@@ -37,6 +37,7 @@ typer_app.add_typer(images.app, name="images")
37
37
  typer_app.add_typer(artifacts.app, name="artifacts")
38
38
  typer_app.add_typer(workflows.app, name="workflows")
39
39
  typer_app.add_typer(webapps.app, name="webapps")
40
+ typer_app.add_typer(services.app, name="services")
40
41
  typer_app.add_typer(tenants.app, name="tenants")
41
42
  typer_app.add_typer(apps.app, name="apps")
42
43
  typer_app.add_typer(blocks.app, name="blocks")
peak/cli/helpers.py CHANGED
@@ -71,29 +71,52 @@ def parse_params(params: Optional[List[str]]) -> Dict[str, str]:
71
71
  return _to_pass
72
72
 
73
73
 
74
+ def check_file_extension(file_path: str) -> None:
75
+ """Checks if the file has a .txt or .md extension.
76
+
77
+ Args:
78
+ file_path (str): Path to the file to check.
79
+
80
+ Raises:
81
+ ValueError: If the file extension is not .txt or .md.
82
+ """
83
+ file_type = Path(file_path).suffix
84
+ if file_type not in [".txt", ".md"]:
85
+ msg = f"Unsupported file type: `{file_type}` Only .txt and .md files are supported."
86
+ raise ValueError(msg)
87
+
88
+
74
89
  def template_handler(
75
90
  file: str,
76
91
  params_file: Optional[str] = None,
77
92
  params: Optional[List[str]] = None,
93
+ description_file: Optional[str] = None,
78
94
  ) -> Dict[str, Any]:
79
95
  """Loads and returns the rendered template.
80
96
 
81
97
  Args:
82
98
  file (str): Path to the template file.
83
99
  params_file (Optional[str]): Path to the params map file.
100
+ description_file: (Optional[str]): Path to the description markdown/text file
84
101
  params (Optional[List[str]]): List of params to override.
85
102
 
86
103
  Returns:
87
104
  Dict[str, Any]: Rendered template with values substituted.
88
105
  """
89
106
  params_dict: Dict[str, Any] = {}
107
+ description: str = ""
90
108
  if params_file:
91
109
  with Path(params_file).open("r") as f:
92
110
  params_dict = yaml.safe_load(f.read())
93
111
 
112
+ if description_file:
113
+ check_file_extension(description_file)
114
+ with Path(description_file).open("r") as f:
115
+ description = f.read()
116
+
94
117
  params_dict = remove_none_values({**params_dict, **parse_params(params)})
95
118
 
96
- return load_template(file, params_dict)
119
+ return load_template(file, params_dict, description)
97
120
 
98
121
 
99
122
  def remove_unknown_args(args: Dict[str, Any], func: Callable[..., Any]) -> Dict[str, Any]:
@@ -166,6 +189,31 @@ def parse_build_arguments(build_arguments: List[str]) -> List[Dict[str, str]]:
166
189
  return parsed_build_arguments
167
190
 
168
191
 
192
+ def parse_envs(env: List[str]) -> Dict[str, str]:
193
+ """Parses envs provided via cli args to the format {arg1: value1}.
194
+
195
+ Args:
196
+ env (List[str]): List of envs provided via cli args.
197
+
198
+ Returns:
199
+ Dict[str, str]: Envs in the required format.
200
+
201
+ Raises:
202
+ BadParameterException: If a value is invalid.
203
+ """
204
+ parsed_envs: Dict[str, str] = {}
205
+ for env_arg in env:
206
+ try:
207
+ key, value = env_arg.split("=", 1)
208
+ except ValueError as err:
209
+ raise BadParameterException(
210
+ env_arg,
211
+ message="Invalid env format. It should in the --env arg1=value1 format",
212
+ ) from err
213
+ parsed_envs[key] = value
214
+ return parsed_envs
215
+
216
+
169
217
  def format_logs(logs: List[Dict[str, Any]]) -> str:
170
218
  """Formats logs into a readable format.
171
219
 
@@ -200,6 +248,7 @@ def get_client(command: str) -> base_client.BaseClient:
200
248
  "artifacts": resources.artifacts,
201
249
  "images": resources.images,
202
250
  "workflows": resources.workflows,
251
+ "services": resources.services,
203
252
  "webapps": resources.webapps,
204
253
  "tenants": resources.tenants,
205
254
  }
@@ -19,6 +19,8 @@
19
19
  # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
20
  #
21
21
  """Peak apps deployments commands."""
22
+ from __future__ import annotations
23
+
22
24
  from typing import Dict, List, Optional
23
25
 
24
26
  import typer
@@ -39,6 +41,7 @@ _DEPLOYMENT_ID = typer.Argument(..., help="ID of the App deployment to be used i
39
41
  def create(
40
42
  ctx: typer.Context,
41
43
  file: str = args.TEMPLATE_PATH,
44
+ description_file: Optional[str] = args.TEMPLATE_DESCRIPTION_FILE,
42
45
  params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
43
46
  params: Optional[List[str]] = args.TEMPLATE_PARAMS,
44
47
  dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
@@ -92,7 +95,7 @@ def create(
92
95
  app_client: App = ctx.obj["client"]
93
96
  writer: Writer = ctx.obj["writer"]
94
97
 
95
- body = helpers.template_handler(file, params_file, params)
98
+ body = helpers.template_handler(file, params_file, params, description_file)
96
99
  body = helpers.remove_unknown_args(body, app_client.create_deployment)
97
100
 
98
101
  with writer.pager():
@@ -222,6 +225,7 @@ def update_metadata(
222
225
  ctx: typer.Context,
223
226
  deployment_id: str = _DEPLOYMENT_ID,
224
227
  file: str = args.TEMPLATE_PATH,
228
+ description_file: Optional[str] = args.TEMPLATE_DESCRIPTION_FILE,
225
229
  params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
226
230
  params: Optional[List[str]] = args.TEMPLATE_PARAMS,
227
231
  dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
@@ -268,7 +272,7 @@ def update_metadata(
268
272
  app_client = ctx.obj["client"]
269
273
  writer: Writer = ctx.obj["writer"]
270
274
 
271
- body = helpers.template_handler(file, params_file, params)
275
+ body = helpers.template_handler(file, params_file, params, description_file)
272
276
  body = helpers.remove_unknown_args(body, app_client.update_deployment_metadata)
273
277
 
274
278
  with writer.pager():
@@ -39,6 +39,7 @@ _SPEC_ID = typer.Argument(..., help="ID of the App spec to be used in this opera
39
39
  def create(
40
40
  ctx: typer.Context,
41
41
  file: str = args.TEMPLATE_PATH,
42
+ description_file: Optional[str] = args.TEMPLATE_DESCRIPTION_FILE,
42
43
  params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
43
44
  params: Optional[List[str]] = args.TEMPLATE_PARAMS,
44
45
  dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
@@ -94,7 +95,7 @@ def create(
94
95
  app_client: App = ctx.obj["client"]
95
96
  writer: Writer = ctx.obj["writer"]
96
97
 
97
- body = helpers.template_handler(file, params_file, params)
98
+ body = helpers.template_handler(file, params_file, params, description_file)
98
99
  body = helpers.remove_unknown_args(body, app_client.create_spec)
99
100
 
100
101
  with writer.pager():
@@ -199,6 +200,7 @@ def update_metadata(
199
200
  ctx: typer.Context,
200
201
  spec_id: str = _SPEC_ID,
201
202
  file: str = args.TEMPLATE_PATH,
203
+ description_file: Optional[str] = args.TEMPLATE_DESCRIPTION_FILE,
202
204
  params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
203
205
  params: Optional[List[str]] = args.TEMPLATE_PARAMS,
204
206
  dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
@@ -251,7 +253,7 @@ def update_metadata(
251
253
  app_client: App = ctx.obj["client"]
252
254
  writer: Writer = ctx.obj["writer"]
253
255
 
254
- data = helpers.template_handler(file, params_file, params)
256
+ data = helpers.template_handler(file, params_file, params, description_file)
255
257
  data = helpers.remove_unknown_args(data, app_client.update_spec_metadata)
256
258
 
257
259
  with writer.pager():
@@ -19,6 +19,8 @@
19
19
  # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
20
  #
21
21
  """Peak blocks deployments commands."""
22
+ from __future__ import annotations
23
+
22
24
  from typing import Dict, List, Optional
23
25
 
24
26
  import typer
@@ -37,12 +39,17 @@ _FALLBACK_PARAMS_FILE = typer.Option(
37
39
  None,
38
40
  help="File containing parameters to be used when deployment id is not present",
39
41
  )
42
+ _FALLBACK_DETAILS_FILE = typer.Option(
43
+ None,
44
+ help="File containing details to be used when deployment id is not present",
45
+ )
40
46
 
41
47
 
42
48
  @app.command(short_help="Create a Block deployment.", options_metavar="create_block_deployment")
43
49
  def create(
44
50
  ctx: typer.Context,
45
51
  file: str = args.TEMPLATE_PATH,
52
+ description_file: Optional[str] = args.TEMPLATE_DESCRIPTION_FILE,
46
53
  params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
47
54
  params: Optional[List[str]] = args.TEMPLATE_PARAMS,
48
55
  dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
@@ -95,7 +102,7 @@ def create(
95
102
  blocks_client: Block = ctx.obj["client"]
96
103
  writer: Writer = ctx.obj["writer"]
97
104
 
98
- body = helpers.template_handler(file, params_file, params)
105
+ body = helpers.template_handler(file, params_file, params, description_file)
99
106
  body = helpers.remove_unknown_args(body, blocks_client.create_deployment)
100
107
 
101
108
  with writer.pager():
@@ -200,6 +207,7 @@ def update_metadata(
200
207
  ctx: typer.Context,
201
208
  deployment_id: str = _DEPLOYMENT_ID,
202
209
  file: str = args.TEMPLATE_PATH,
210
+ description_file: Optional[str] = args.TEMPLATE_DESCRIPTION_FILE,
203
211
  params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
204
212
  params: Optional[List[str]] = args.TEMPLATE_PARAMS,
205
213
  dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
@@ -246,7 +254,7 @@ def update_metadata(
246
254
  blocks_client: Block = ctx.obj["client"]
247
255
  writer: Writer = ctx.obj["writer"]
248
256
 
249
- body = helpers.template_handler(file, params_file, params)
257
+ body = helpers.template_handler(file, params_file, params, description_file)
250
258
  body = helpers.remove_unknown_args(body, blocks_client.update_deployment_metadata)
251
259
 
252
260
  with writer.pager():
@@ -515,3 +523,36 @@ def patch_parameters(
515
523
  with writer.pager():
516
524
  response = blocks_client.patch_parameters(deployment_id, **body)
517
525
  writer.write(response)
526
+
527
+
528
+ @app.command(short_help="Get the info for related blocks within an app.", options_metavar="get_related_block_details")
529
+ def get_related_block_details(
530
+ ctx: typer.Context,
531
+ deployment_id: Optional[str] = _DEPLOYMENT_ID_OPTION,
532
+ fallback_details_file: Optional[str] = _FALLBACK_DETAILS_FILE,
533
+ paging: Optional[bool] = PAGING, # noqa: ARG001
534
+ output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES, # noqa: ARG001
535
+ ) -> None:
536
+ """***Get*** the info for related blocks within an app.
537
+
538
+ \b
539
+ 📝 ***Example usage:***<br/>
540
+ ```bash
541
+ peak blocks deployments get_related_block_details --deployment-id=<deployment-id> --fallback-details-file=<path/to/fallback/details/file>
542
+ ```
543
+
544
+ \b
545
+ 🆗 ***Response:***
546
+ ```
547
+ {...}
548
+ ```
549
+ """
550
+ blocks_client: Block = ctx.obj["client"]
551
+ writer: Writer = ctx.obj["writer"]
552
+
553
+ with writer.pager():
554
+ response = blocks_client.get_related_block_details(
555
+ deployment_id=deployment_id,
556
+ fallback_details_file=fallback_details_file,
557
+ )
558
+ writer.write(response)
@@ -93,6 +93,7 @@ def list_block_specs(
93
93
  def create(
94
94
  ctx: typer.Context,
95
95
  file: str = args.TEMPLATE_PATH,
96
+ description_file: Optional[str] = args.TEMPLATE_DESCRIPTION_FILE,
96
97
  params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
97
98
  params: Optional[List[str]] = args.TEMPLATE_PARAMS,
98
99
  dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
@@ -164,7 +165,6 @@ def create(
164
165
  - cron (string | required: false): A valid cron expression.
165
166
  webhook (boolean | required: false): Should be true if webhook type trigger is to be used.
166
167
  webhookId (string | required: false): ID of the webhook.
167
- webhookPolicy (string | required: false): Policy of the webhook to be used. Should be one of "generate" or "preserve". It is "generate" by default.
168
168
  watchers (list(map) | required: false):
169
169
  - events (map):
170
170
  success (boolean | required: false): Whether to call event on success.
@@ -222,7 +222,7 @@ def create(
222
222
  block_client: Block = ctx.obj["client"]
223
223
  writer: Writer = ctx.obj["writer"]
224
224
 
225
- body = helpers.template_handler(file, params_file, params)
225
+ body = helpers.template_handler(file, params_file, params, description_file)
226
226
  body = helpers.remove_unknown_args(body, block_client.create_spec)
227
227
 
228
228
  with writer.pager():
@@ -274,6 +274,7 @@ def update_metadata(
274
274
  ctx: typer.Context,
275
275
  spec_id: str = _SPEC_ID,
276
276
  file: str = args.TEMPLATE_PATH,
277
+ description_file: Optional[str] = args.TEMPLATE_DESCRIPTION_FILE,
277
278
  params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
278
279
  params: Optional[List[str]] = args.TEMPLATE_PARAMS,
279
280
  dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
@@ -323,7 +324,7 @@ def update_metadata(
323
324
 
324
325
  🔗 [**API Documentation**](https://press.peak.ai/api-docs/index.htm#/Block%20Specs/patch_v1_blocks_specs__specId_)
325
326
  """
326
- body = helpers.template_handler(file, params_file, params)
327
+ body = helpers.template_handler(file, params_file, params, description_file)
327
328
  writer: Writer = ctx.obj["writer"]
328
329
 
329
330
  block_client: Block = ctx.obj["client"]
@@ -428,7 +429,6 @@ def create_release(
428
429
  cron (string | required: false): A valid cron expression.
429
430
  webhook (boolean | required: false): Should be true if webhook type trigger is to be used.
430
431
  webhookId (string | required: false): ID of the webhook.
431
- webhookPolicy (string | required: false): Policy of the webhook to be used. Should be one of "generate" or "preserve". It is "generate" by default.
432
432
  watchers (list(map) | required: false):
433
433
  - events (map):
434
434
  success (boolean | required: false): Whether to call event on success.