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/__init__.py
ADDED
@@ -0,0 +1,36 @@
|
|
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
|
+
"""This file is part of the peak-sdk framework.
|
22
|
+
|
23
|
+
Copyright © 2023 Peak AI
|
24
|
+
|
25
|
+
Unauthorized copying of this file, via any medium is strictly prohibited.
|
26
|
+
"""
|
27
|
+
from __future__ import annotations
|
28
|
+
|
29
|
+
from typing import List
|
30
|
+
|
31
|
+
from peak import press, resources
|
32
|
+
from peak.session import Session
|
33
|
+
|
34
|
+
from ._version import __version__
|
35
|
+
|
36
|
+
__all__: List[str] = ["Session", "press", "resources", "__version__"]
|
peak/_version.py
ADDED
@@ -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
|
+
__version__: str = "1.0.0"
|
peak/auth.py
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
"""Auth Module."""
|
22
|
+
raise NotImplementedError
|
peak/base_client.py
ADDED
@@ -0,0 +1,52 @@
|
|
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
|
+
"""Base client class."""
|
22
|
+
from __future__ import annotations
|
23
|
+
|
24
|
+
from typing import List, Optional
|
25
|
+
|
26
|
+
from peak.session import Session, _get_default_session
|
27
|
+
|
28
|
+
|
29
|
+
class BaseClient:
|
30
|
+
"""Base client class."""
|
31
|
+
|
32
|
+
session: Session
|
33
|
+
|
34
|
+
def __init__(self, session: Optional[Session] = None) -> None:
|
35
|
+
"""Assigns a session to the client. If no session is provided, a default session is used.
|
36
|
+
|
37
|
+
Args:
|
38
|
+
session (Optional[Session]): Session object of a tenant. Defaults to None.
|
39
|
+
|
40
|
+
Raises:
|
41
|
+
TypeError: If the session object is invalid.
|
42
|
+
"""
|
43
|
+
invalid_session_error = f"Invalid session object, expected Session but got {type(session)}"
|
44
|
+
if session is not None:
|
45
|
+
if not isinstance(session, Session):
|
46
|
+
raise TypeError(invalid_session_error)
|
47
|
+
self.session = session
|
48
|
+
else:
|
49
|
+
self.session = _get_default_session()
|
50
|
+
|
51
|
+
|
52
|
+
__all__: List[str] = ["BaseClient"]
|
peak/cli/__init_.py
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
+
#
|
peak/cli/args.py
ADDED
@@ -0,0 +1,84 @@
|
|
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
|
+
"""CLI arguments."""
|
22
|
+
import typer
|
23
|
+
from peak.cli.version import display_version
|
24
|
+
|
25
|
+
VERSION_OPTION = typer.Option(False, "--version", callback=display_version, is_eager=True)
|
26
|
+
|
27
|
+
TEMPLATE_PATH = typer.Argument(
|
28
|
+
...,
|
29
|
+
help="""
|
30
|
+
Path to the file that defines the body for this operation, supports both `yaml` file or a `jinja` template.
|
31
|
+
""",
|
32
|
+
)
|
33
|
+
|
34
|
+
TEMPLATE_PARAMS_FILE = typer.Option(
|
35
|
+
None,
|
36
|
+
"--params-file",
|
37
|
+
"-v",
|
38
|
+
help="Path to the `yaml` file containing the parameter values map for the template file.",
|
39
|
+
)
|
40
|
+
|
41
|
+
TEMPLATE_PARAMS = typer.Option(
|
42
|
+
None,
|
43
|
+
"--params",
|
44
|
+
"-p",
|
45
|
+
help="Parameters to be used with the template file. Overrides the parameters in the params file. Parameters should be in the format `key=value`.",
|
46
|
+
)
|
47
|
+
|
48
|
+
PAGE_NUMBER = typer.Option(None, help="The page number to retrieve.")
|
49
|
+
|
50
|
+
PAGE_SIZE = typer.Option(None, help="Number of entities to include per page.")
|
51
|
+
|
52
|
+
DATE_FROM = typer.Option(None, help="The date after which the entities should be included (in ISO format).")
|
53
|
+
|
54
|
+
DATE_TO = typer.Option(None, help="The date till which the entities should be included (in ISO format).")
|
55
|
+
|
56
|
+
IMAGE_ID = typer.Option(..., help="ID of the image to be used in this operation.")
|
57
|
+
|
58
|
+
VERSION_ID = typer.Option(..., help="ID of the version to be used in this operation.")
|
59
|
+
|
60
|
+
SPEC_ID = typer.Option(..., help="ID of the spec to be used in this operation.")
|
61
|
+
|
62
|
+
RELEASE_VERSION = typer.Option(..., help="Release version to be used in this operation.")
|
63
|
+
|
64
|
+
SORT_KEYS = typer.Option(
|
65
|
+
None,
|
66
|
+
help="A comma-separated list of fields to order results by, in the format \\<field\\>:\\<order\\>.",
|
67
|
+
)
|
68
|
+
|
69
|
+
STATUS_FILTER = typer.Option(None, help="A comma-separated list of statuses to filter entities.")
|
70
|
+
|
71
|
+
NAME_FILTER = typer.Option(None, help="Only return entities whose names begins with the query string.")
|
72
|
+
|
73
|
+
TITLE_FILTER = typer.Option(None, help="Only return entities whose title begins with the query string.")
|
74
|
+
|
75
|
+
SCOPES = typer.Option(None, help="A comma-separated list of scopes to only return entities of those scopes.")
|
76
|
+
|
77
|
+
FEATURED = typer.Option(None, "--featured", help="Whether to only return featured entities.")
|
78
|
+
|
79
|
+
KIND_FILTER = typer.Option(None, help="Only return entities with the kind specified.")
|
80
|
+
|
81
|
+
TERM_FILTER = typer.Option(
|
82
|
+
None,
|
83
|
+
help="Only return entities which contain the term in name, title, description or summary.",
|
84
|
+
)
|
peak/cli/cli.py
ADDED
@@ -0,0 +1,56 @@
|
|
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
|
+
"""CLI entrypoint."""
|
22
|
+
import sys
|
23
|
+
|
24
|
+
import peak.config
|
25
|
+
import typer
|
26
|
+
from peak.cli import args, helpers
|
27
|
+
from peak.cli.press import apps, blocks, deployments, specs
|
28
|
+
from peak.cli.resources import artifacts, images, webapps, workflows
|
29
|
+
from peak.constants import Sources
|
30
|
+
|
31
|
+
# Hack to not gray out texts after first paragraph
|
32
|
+
typer.rich_utils.STYLE_HELPTEXT = ""
|
33
|
+
|
34
|
+
typer_app = typer.Typer(rich_markup_mode="markdown", help="Create and Manage Peak Resources")
|
35
|
+
typer_app.add_typer(images.app, name="images")
|
36
|
+
typer_app.add_typer(artifacts.app, name="artifacts")
|
37
|
+
typer_app.add_typer(workflows.app, name="workflows")
|
38
|
+
typer_app.add_typer(webapps.app, name="webapps")
|
39
|
+
typer_app.add_typer(apps.app, name="apps")
|
40
|
+
typer_app.add_typer(blocks.app, name="blocks")
|
41
|
+
typer_app.add_typer(specs.app, name="specs")
|
42
|
+
typer_app.add_typer(deployments.app, name="deployments")
|
43
|
+
|
44
|
+
|
45
|
+
@typer_app.callback()
|
46
|
+
def main(ctx: typer.Context, version: bool = args.VERSION_OPTION) -> None: # noqa: ARG001
|
47
|
+
"""Add global version option and add client to context only if any command is invoked."""
|
48
|
+
peak.config.SOURCE = Sources.CLI
|
49
|
+
if "--help" not in sys.argv and ctx.invoked_subcommand:
|
50
|
+
ctx.obj = {
|
51
|
+
"client": helpers.get_client(ctx.invoked_subcommand),
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
if __name__ == "__main__":
|
56
|
+
typer_app()
|
peak/cli/helpers.py
ADDED
@@ -0,0 +1,187 @@
|
|
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
|
+
"""Helper functions for Peak `cli`."""
|
22
|
+
from __future__ import annotations
|
23
|
+
|
24
|
+
import inspect
|
25
|
+
from pathlib import Path
|
26
|
+
from types import ModuleType
|
27
|
+
from typing import Any, Callable, Dict, List, Optional
|
28
|
+
|
29
|
+
import yaml
|
30
|
+
from peak import base_client, press, resources
|
31
|
+
from peak.exceptions import BadParameterException
|
32
|
+
from peak.template import load_template
|
33
|
+
from rich.console import Console
|
34
|
+
|
35
|
+
console = Console()
|
36
|
+
|
37
|
+
|
38
|
+
def parse_params(params: Optional[List[str]]) -> Dict[str, str]:
|
39
|
+
"""Parse parameters into key-value pairs.
|
40
|
+
|
41
|
+
Args:
|
42
|
+
params (Optional[List[str]]): List of key-value pairs
|
43
|
+
|
44
|
+
Returns:
|
45
|
+
Dict[str, str]: Dictionary of key-value pairs
|
46
|
+
|
47
|
+
Raises:
|
48
|
+
BadParameterException: If a value is invalid
|
49
|
+
|
50
|
+
>>> params = ["foo=1", "bar=2"]
|
51
|
+
>>> vals = parse_params(params)
|
52
|
+
>>> vals
|
53
|
+
{'foo': '1', 'bar': '2'}
|
54
|
+
|
55
|
+
Raises an error if a value is invalid
|
56
|
+
>>> parse_params(["bar==foo"]) #doctest: +IGNORE_EXCEPTION_DETAIL
|
57
|
+
Traceback (most recent call last):
|
58
|
+
...
|
59
|
+
BadParameterException: Unable to parse: bar==foo
|
60
|
+
"""
|
61
|
+
if params is None:
|
62
|
+
return {}
|
63
|
+
|
64
|
+
_to_pass: Dict[str, Any] = {}
|
65
|
+
for keyval in params:
|
66
|
+
if keyval.count("=") != 1:
|
67
|
+
raise BadParameterException(keyval)
|
68
|
+
s: List[str] = keyval.split("=", 1) # split on first '='
|
69
|
+
_to_pass[s[0]] = s[-1]
|
70
|
+
return _to_pass
|
71
|
+
|
72
|
+
|
73
|
+
def template_handler(
|
74
|
+
file: str,
|
75
|
+
params_file: Optional[str] = None,
|
76
|
+
params: Optional[List[str]] = None,
|
77
|
+
) -> Dict[str, Any]:
|
78
|
+
"""Loads and returns the rendered template.
|
79
|
+
|
80
|
+
Args:
|
81
|
+
file (str): Path to the template file.
|
82
|
+
params_file (Optional[str]): Path to the params map file.
|
83
|
+
params (Optional[List[str]]): List of params to override.
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
Dict[str, Any]: Rendered template with values substituted.
|
87
|
+
"""
|
88
|
+
params_dict: Dict[str, Any] = {}
|
89
|
+
if params_file:
|
90
|
+
with Path(params_file).open("r") as f:
|
91
|
+
params_dict = yaml.safe_load(f.read())
|
92
|
+
|
93
|
+
params_dict = {**params_dict, **parse_params(params)}
|
94
|
+
|
95
|
+
return load_template(file, params_dict)
|
96
|
+
|
97
|
+
|
98
|
+
def remove_unknown_args(args: Dict[str, Any], func: Callable[..., Any]) -> Dict[str, Any]:
|
99
|
+
"""Filters keys from dictionary which are not accepted by the function.
|
100
|
+
|
101
|
+
Args:
|
102
|
+
args (Dict[str, Any]): dictionary to filter
|
103
|
+
func (Callable): function to filter for
|
104
|
+
|
105
|
+
Returns:
|
106
|
+
Dict[str, Any]: filtered dictionary
|
107
|
+
"""
|
108
|
+
func_params = inspect.signature(func).parameters
|
109
|
+
return {k: v for k, v in args.items() if k in func_params}
|
110
|
+
|
111
|
+
|
112
|
+
def get_updated_artifacts(
|
113
|
+
body: Dict[str, Any],
|
114
|
+
artifact_path: str | None,
|
115
|
+
artifact_ignore_files: List[str] | None,
|
116
|
+
) -> Dict[str, Any]:
|
117
|
+
"""Returns updated artifacts by replacing artifact path and ignore files by the ones provided via cli args.
|
118
|
+
|
119
|
+
Args:
|
120
|
+
body (Dict[str, Any]): Dictionary containing request body generated from user provided yaml file
|
121
|
+
artifact_path (str | None): Path to the artifact.
|
122
|
+
artifact_ignore_files (List[str] | None): Ignore files to use when creating artifact.
|
123
|
+
|
124
|
+
Returns:
|
125
|
+
Dict[str, Any]: Dictionary containing updated artifacts
|
126
|
+
"""
|
127
|
+
artifact: Dict[str, Any] = {}
|
128
|
+
|
129
|
+
if artifact_path:
|
130
|
+
artifact["path"] = artifact_path
|
131
|
+
elif "artifact" in body and "path" in body["artifact"]:
|
132
|
+
artifact["path"] = body["artifact"]["path"]
|
133
|
+
|
134
|
+
if artifact_ignore_files:
|
135
|
+
artifact["ignore_files"] = artifact_ignore_files
|
136
|
+
elif "artifact" in body and "ignore_files" in body["artifact"]:
|
137
|
+
artifact["ignore_files"] = body["artifact"]["ignore_files"]
|
138
|
+
|
139
|
+
return artifact
|
140
|
+
|
141
|
+
|
142
|
+
def parse_build_arguments(build_arguments: List[str]) -> List[Dict[str, str]]:
|
143
|
+
"""Parses build arguments provided via cli args to the format {name: arg1, value: value1}.
|
144
|
+
|
145
|
+
Args:
|
146
|
+
build_arguments (List[str]): List of build arguments provided via cli args
|
147
|
+
|
148
|
+
Returns:
|
149
|
+
List[Dict[str, str]]: List of build arguments in the required format
|
150
|
+
|
151
|
+
Raises:
|
152
|
+
BadParameterException: If a value is invalid
|
153
|
+
"""
|
154
|
+
parsed_build_arguments: List[Dict[str, str]] = []
|
155
|
+
for build_argument in build_arguments:
|
156
|
+
try:
|
157
|
+
key, value = build_argument.split("=", 1)
|
158
|
+
except ValueError as err:
|
159
|
+
raise BadParameterException(
|
160
|
+
build_argument,
|
161
|
+
message="Invalid build argument format. It should in the --build-arguments arg1=value1 format",
|
162
|
+
) from err
|
163
|
+
key, value = build_argument.split("=", 1)
|
164
|
+
parsed_build_arguments.append({"name": key, "value": value})
|
165
|
+
return parsed_build_arguments
|
166
|
+
|
167
|
+
|
168
|
+
def get_client(command: str) -> base_client.BaseClient:
|
169
|
+
"""Create a client for the invoked command.
|
170
|
+
|
171
|
+
Args:
|
172
|
+
command (str): Invoked CLI command
|
173
|
+
|
174
|
+
Returns:
|
175
|
+
BaseClient: client class for the invoked command
|
176
|
+
"""
|
177
|
+
command_client_map: Dict[str, ModuleType] = {
|
178
|
+
"apps": press.apps,
|
179
|
+
"blocks": press.blocks,
|
180
|
+
"specs": press.specs,
|
181
|
+
"deployments": press.deployments,
|
182
|
+
"artifacts": resources.artifacts,
|
183
|
+
"images": resources.images,
|
184
|
+
"workflows": resources.workflows,
|
185
|
+
"webapps": resources.webapps,
|
186
|
+
}
|
187
|
+
return command_client_map[command].get_client() # type: ignore[no-any-return]
|
@@ -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
|
+
"""CLI modules for Press resources."""
|
@@ -0,0 +1,40 @@
|
|
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 Module."""
|
22
|
+
import typer
|
23
|
+
from peak.cli.press.apps import deployments, specs
|
24
|
+
|
25
|
+
app = typer.Typer(
|
26
|
+
help="Create and manage App specs and deployments.",
|
27
|
+
short_help="Create and manage App specs and deployments.",
|
28
|
+
)
|
29
|
+
app.add_typer(
|
30
|
+
specs.app,
|
31
|
+
name="specs",
|
32
|
+
help="Create and manage App specs which are blueprint for Peak Apps.",
|
33
|
+
short_help="Create and manage App Specs.",
|
34
|
+
)
|
35
|
+
app.add_typer(
|
36
|
+
deployments.app,
|
37
|
+
name="deployments",
|
38
|
+
help="Create and manage App deployments which are the actual instance of the App.",
|
39
|
+
short_help="Create and manage App Deployments.",
|
40
|
+
)
|