codemie-cdk-python 0.1.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.
- codemie_cdk_python-0.1.0.dist-info/METADATA +892 -0
- codemie_cdk_python-0.1.0.dist-info/RECORD +40 -0
- codemie_cdk_python-0.1.0.dist-info/WHEEL +4 -0
- codemie_cdk_python-0.1.0.dist-info/entry_points.txt +3 -0
- codemie_iac/__init__.py +49 -0
- codemie_iac/cli/__init__.py +17 -0
- codemie_iac/cli/__main__.py +24 -0
- codemie_iac/cli/commands/__init__.py +17 -0
- codemie_iac/cli/commands/apply.py +119 -0
- codemie_iac/cli/commands/plan.py +72 -0
- codemie_iac/cli/config_model.py +136 -0
- codemie_iac/cli/documents.py +59 -0
- codemie_iac/cli/env_file.py +62 -0
- codemie_iac/cli/exit_status.py +80 -0
- codemie_iac/cli/init_command.py +101 -0
- codemie_iac/cli/main.py +152 -0
- codemie_iac/cli/render.py +206 -0
- codemie_iac/cli/target_config.py +258 -0
- codemie_iac/credentials.py +99 -0
- codemie_iac/envelope.py +188 -0
- codemie_iac/plan_apply/__init__.py +70 -0
- codemie_iac/plan_apply/bulk_create.py +561 -0
- codemie_iac/plan_apply/credentials.py +306 -0
- codemie_iac/plan_apply/errors.py +223 -0
- codemie_iac/plan_apply/field_policy.py +188 -0
- codemie_iac/plan_apply/guards.py +221 -0
- codemie_iac/plan_apply/kinds.py +815 -0
- codemie_iac/plan_apply/lookup.py +313 -0
- codemie_iac/plan_apply/ordering.py +177 -0
- codemie_iac/plan_apply/single_apply.py +751 -0
- codemie_iac/resolver.py +61 -0
- codemie_iac/schema.py +106 -0
- codemie_iac/serializer.py +64 -0
- codemie_iac/specs/__init__.py +13 -0
- codemie_iac/specs/assistant.py +509 -0
- codemie_iac/specs/category.py +36 -0
- codemie_iac/specs/datasource.py +595 -0
- codemie_iac/specs/integration.py +103 -0
- codemie_iac/specs/skill.py +51 -0
- codemie_iac/specs/workflow.py +154 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
codemie_iac/__init__.py,sha256=GwEuu6Pgi7ij_EMwzjlf_RkXbmdDSXwJO3CVUZi0ovE,1615
|
|
2
|
+
codemie_iac/cli/__init__.py,sha256=d_xpqEt7QouXagJ1rwGXme6tH8oKoT0UC9U_ei6IE3Q,683
|
|
3
|
+
codemie_iac/cli/__main__.py,sha256=iIBu8EIl8ZHlfGnCMuE4XHyRKRgehxAq13E_WhyrEwg,740
|
|
4
|
+
codemie_iac/cli/commands/__init__.py,sha256=0bKCzrtXEclDRUsC8f5VHgtFZ2J9Zcv_04NRXelZlRw,640
|
|
5
|
+
codemie_iac/cli/commands/apply.py,sha256=1PDlPimFnkAjUAaPwyFyXpzgJ2X4or8ALXhZC2aq_2o,3719
|
|
6
|
+
codemie_iac/cli/commands/plan.py,sha256=bZENwU-8YyZVPzQDY03BikP6CBVwJ_2ZAWO2xZGyCKU,2605
|
|
7
|
+
codemie_iac/cli/config_model.py,sha256=RuATf5vQfuLwzjExfK2JmmNmVl7UE1_ae_o2Lr3Dl_M,4197
|
|
8
|
+
codemie_iac/cli/documents.py,sha256=qnSyjMe2WVsxpED6YcV-oe16JhqAW9BlP-h2ahNMAhg,2111
|
|
9
|
+
codemie_iac/cli/env_file.py,sha256=Wg-lb7vCTcN6HtLV2PRWLc4BnPVVEOReaBoat13CgiM,2037
|
|
10
|
+
codemie_iac/cli/exit_status.py,sha256=eDU4f9YtoQfCzqVWB8HG3Fb20Loxm4Yc-dJdnnM33sQ,2450
|
|
11
|
+
codemie_iac/cli/init_command.py,sha256=etf2oYihbRiBAW56CI4divjpMeQC4CySE6_UvW17frk,3252
|
|
12
|
+
codemie_iac/cli/main.py,sha256=a1NsQWjZ1WLQt8ywHp0qS7HJEgmrB9VfPI7cDhEP_go,5797
|
|
13
|
+
codemie_iac/cli/render.py,sha256=AgVRJCl-obCPJ6IhPlIF9ETNr6TWpe8FeB3sY3oDVPk,6764
|
|
14
|
+
codemie_iac/cli/target_config.py,sha256=HJgAyt9LsiaVgOjuJhN3J9Ptfe3Zq2sq2OV2G2xbpAE,9369
|
|
15
|
+
codemie_iac/credentials.py,sha256=uvROZACh-Sp98GOjY_lHM5TGkJ6gIhexyMXJmONAcWU,4631
|
|
16
|
+
codemie_iac/envelope.py,sha256=T4x1hV_2K6KCjbgoRloc_9a2RGj0sUEg9KKmrpnKBAI,7435
|
|
17
|
+
codemie_iac/plan_apply/__init__.py,sha256=LKt2hxat5OCRSXW9zsBCpz2C-BLuZQPYMz5F958PkeE,1852
|
|
18
|
+
codemie_iac/plan_apply/bulk_create.py,sha256=D4gRl_mY6hleNFRq6cPjptwm8OXP66A5IL4bTQZ8u1Q,19998
|
|
19
|
+
codemie_iac/plan_apply/credentials.py,sha256=cGB9UmlvrXZFNg4BBV-7vWDEJIWKM-vZsgupQZn0BTU,11159
|
|
20
|
+
codemie_iac/plan_apply/errors.py,sha256=--RgYunR_5oGvAHlyGRNqelHdizWg2b0d219flaVqkI,7503
|
|
21
|
+
codemie_iac/plan_apply/field_policy.py,sha256=iS50O35NWFPBL-PABDG1UFtn1HWPEn22SUtke-YDCYc,8184
|
|
22
|
+
codemie_iac/plan_apply/guards.py,sha256=Ejm40B1XPwUuSO4CkbJLiPZqYUeWvr3R7zR7Lvr3Viw,8388
|
|
23
|
+
codemie_iac/plan_apply/kinds.py,sha256=qebyTVwx_fSzSsX6EaqfCja6w5mQ3DuA1agP4tAchL4,30839
|
|
24
|
+
codemie_iac/plan_apply/lookup.py,sha256=psHKgMLHIaKIdS-_pMECMdzbH2kxqJYkiae-Xs2sIUY,11951
|
|
25
|
+
codemie_iac/plan_apply/ordering.py,sha256=YBPoSjSMC1YcBvQVhd4e9N4Nr9dS7okkJ65AGUQlHUE,6350
|
|
26
|
+
codemie_iac/plan_apply/single_apply.py,sha256=d_HzvAvs3hRdPIM9-GP1v8jcXFpFsh1o5CETKR7Gwnc,27861
|
|
27
|
+
codemie_iac/resolver.py,sha256=rncBpQ0-UPIY_X6qt5txBOttCcHJYaP91Z6M4qPbvwQ,2138
|
|
28
|
+
codemie_iac/schema.py,sha256=Pswh7UMlfVQn2fMcRxe1lu39G4fTVltkohTRKgcDZQw,4337
|
|
29
|
+
codemie_iac/serializer.py,sha256=KwLUlkFZ4Sp0xNlullm9BCZqqateSNwRmWOoSbt9QBM,2700
|
|
30
|
+
codemie_iac/specs/__init__.py,sha256=ufdnwla10roWz8Sr-GZPCXVhNwfrCKI8JBTWwIkwvgA,591
|
|
31
|
+
codemie_iac/specs/assistant.py,sha256=SQXy7y6mtT4kpl4ax8ckYazrLuW5vLGVuwzjnXNYp2U,20992
|
|
32
|
+
codemie_iac/specs/category.py,sha256=hiWdIzFBryPXW4RZLxZybxBfp2xJoMLMZmDcAU3S65k,1359
|
|
33
|
+
codemie_iac/specs/datasource.py,sha256=oUPNllLaBUNU1JI-Thx7t02V-vDNzmsnwjduOR02TGs,21155
|
|
34
|
+
codemie_iac/specs/integration.py,sha256=Fcp_OH_Uw-7X6a3aeS8qSLrTD6fy7Oc6x2xXPew1wUg,4154
|
|
35
|
+
codemie_iac/specs/skill.py,sha256=dw1n7ztqilxtMrjAi35H1tXDolTtfbITFJ3yeZ0trZ0,2043
|
|
36
|
+
codemie_iac/specs/workflow.py,sha256=97R_4SD2gkpoKOV1y72pzbmZMVQqBnzLWWmrExrLRMw,7689
|
|
37
|
+
codemie_cdk_python-0.1.0.dist-info/METADATA,sha256=jQo_WWEncqQ2M875Zbuf32WFsJjySny-zgwYuN6sbuo,43810
|
|
38
|
+
codemie_cdk_python-0.1.0.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
|
|
39
|
+
codemie_cdk_python-0.1.0.dist-info/entry_points.txt,sha256=zOUpiYyufKd-d6dBpkBcC_QmZ6eoktcYICYroxaw_bw,57
|
|
40
|
+
codemie_cdk_python-0.1.0.dist-info/RECORD,,
|
codemie_iac/__init__.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|
|
16
|
+
|
|
17
|
+
from .envelope import Document, Bundle, DocumentMeta, DocumentKind
|
|
18
|
+
from .specs.assistant import AssistantSpec
|
|
19
|
+
from .specs.datasource import DatasourceSpec
|
|
20
|
+
from .specs.integration import IntegrationSpec
|
|
21
|
+
from .specs.skill import SkillSpec
|
|
22
|
+
from .specs.category import CategorySpec
|
|
23
|
+
from .specs.workflow import WorkflowSpec
|
|
24
|
+
from .credentials import CredentialRef
|
|
25
|
+
from .resolver import ReferenceResolver, ReferenceResolutionError
|
|
26
|
+
from .serializer import to_yaml, from_yaml, DocumentParseError
|
|
27
|
+
from .schema import document_json_schema, validate_document, DocumentValidationError
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"Document",
|
|
31
|
+
"Bundle",
|
|
32
|
+
"DocumentMeta",
|
|
33
|
+
"DocumentKind",
|
|
34
|
+
"AssistantSpec",
|
|
35
|
+
"DatasourceSpec",
|
|
36
|
+
"IntegrationSpec",
|
|
37
|
+
"SkillSpec",
|
|
38
|
+
"CategorySpec",
|
|
39
|
+
"WorkflowSpec",
|
|
40
|
+
"CredentialRef",
|
|
41
|
+
"ReferenceResolver",
|
|
42
|
+
"ReferenceResolutionError",
|
|
43
|
+
"to_yaml",
|
|
44
|
+
"from_yaml",
|
|
45
|
+
"DocumentParseError",
|
|
46
|
+
"document_json_schema",
|
|
47
|
+
"validate_document",
|
|
48
|
+
"DocumentValidationError",
|
|
49
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Command-line interface for plan/apply of CodeMie documents."""
|
|
16
|
+
|
|
17
|
+
__all__: list[str] = []
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Allow ``python -m codemie_iac.cli``."""
|
|
16
|
+
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
from .main import main
|
|
20
|
+
|
|
21
|
+
__all__ = ["main"]
|
|
22
|
+
|
|
23
|
+
if __name__ == "__main__":
|
|
24
|
+
sys.exit(main())
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""CLI subcommands."""
|
|
16
|
+
|
|
17
|
+
__all__: list[str] = []
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""The ``apply`` command: create or update entities from YAML documents."""
|
|
16
|
+
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from collections.abc import Mapping
|
|
19
|
+
from typing import Any, TextIO
|
|
20
|
+
|
|
21
|
+
from ...plan_apply import BulkCreator, EnvCredentialResolver, SingleEntityPlanner
|
|
22
|
+
from ..documents import (
|
|
23
|
+
InvalidDocumentError,
|
|
24
|
+
read_bundle,
|
|
25
|
+
single_document,
|
|
26
|
+
)
|
|
27
|
+
from ..exit_status import ExitStatus, exit_status_for
|
|
28
|
+
from ..render import render_apply_result, render_bulk_report, render_error
|
|
29
|
+
from ..target_config import ConfigError
|
|
30
|
+
|
|
31
|
+
__all__ = ["apply_command"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _apply_directory(
|
|
35
|
+
path: Path,
|
|
36
|
+
entity_id: str | None,
|
|
37
|
+
json_output: bool,
|
|
38
|
+
project: str,
|
|
39
|
+
client: Any,
|
|
40
|
+
out: TextIO,
|
|
41
|
+
credentials: EnvCredentialResolver,
|
|
42
|
+
) -> ExitStatus:
|
|
43
|
+
if entity_id:
|
|
44
|
+
raise ConfigError("--id cannot be combined with a directory")
|
|
45
|
+
files = sorted(
|
|
46
|
+
file
|
|
47
|
+
for pattern in ("*.yaml", "*.yml")
|
|
48
|
+
for file in path.glob(pattern)
|
|
49
|
+
if file.is_file()
|
|
50
|
+
)
|
|
51
|
+
if not files:
|
|
52
|
+
raise InvalidDocumentError(f"no .yaml/.yml documents found in {path}")
|
|
53
|
+
documents = [document for file in files for document in read_bundle(file)]
|
|
54
|
+
report = BulkCreator(client, credentials=credentials).create_all(documents, project)
|
|
55
|
+
status = ExitStatus.APPLY_FAILED if report.failed else ExitStatus.SUCCESS
|
|
56
|
+
out.write(
|
|
57
|
+
render_bulk_report(
|
|
58
|
+
report,
|
|
59
|
+
json_output=json_output,
|
|
60
|
+
status=status,
|
|
61
|
+
secrets=credentials.revealed_values(),
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
return status
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _apply_file(
|
|
68
|
+
path: Path,
|
|
69
|
+
entity_id: str | None,
|
|
70
|
+
json_output: bool,
|
|
71
|
+
project: str,
|
|
72
|
+
client: Any,
|
|
73
|
+
out: TextIO,
|
|
74
|
+
credentials: EnvCredentialResolver,
|
|
75
|
+
) -> ExitStatus:
|
|
76
|
+
document = single_document(read_bundle(path))
|
|
77
|
+
result = SingleEntityPlanner(client, credentials=credentials).apply(
|
|
78
|
+
document, entity_id, project
|
|
79
|
+
)
|
|
80
|
+
out.write(
|
|
81
|
+
render_apply_result(
|
|
82
|
+
result,
|
|
83
|
+
json_output=json_output,
|
|
84
|
+
status=ExitStatus.SUCCESS,
|
|
85
|
+
secrets=credentials.revealed_values(),
|
|
86
|
+
)
|
|
87
|
+
)
|
|
88
|
+
return ExitStatus.SUCCESS
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def apply_command(
|
|
92
|
+
path: Path,
|
|
93
|
+
entity_id: str | None,
|
|
94
|
+
*,
|
|
95
|
+
json_output: bool,
|
|
96
|
+
project: str,
|
|
97
|
+
client: Any,
|
|
98
|
+
out: TextIO,
|
|
99
|
+
environ: Mapping[str, str] | None = None,
|
|
100
|
+
) -> ExitStatus:
|
|
101
|
+
"""Apply a file (create/update one entity) or a directory (bulk create).
|
|
102
|
+
|
|
103
|
+
``environ`` is what ``env:NAME`` credential references read (default: the process environment).
|
|
104
|
+
"""
|
|
105
|
+
credentials = EnvCredentialResolver(environ)
|
|
106
|
+
handler = _apply_directory if path.is_dir() else _apply_file
|
|
107
|
+
try:
|
|
108
|
+
return handler(path, entity_id, json_output, project, client, out, credentials)
|
|
109
|
+
except Exception as exc: # noqa: BLE001 - unmapped errors become APPLY_FAILED
|
|
110
|
+
status = exit_status_for(exc, default=ExitStatus.APPLY_FAILED)
|
|
111
|
+
out.write(
|
|
112
|
+
render_error(
|
|
113
|
+
exc,
|
|
114
|
+
json_output=json_output,
|
|
115
|
+
status=status,
|
|
116
|
+
secrets=credentials.revealed_values(),
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
return status
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""The ``plan`` command: diff one document against one live entity."""
|
|
16
|
+
|
|
17
|
+
from collections.abc import Mapping
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any, TextIO
|
|
20
|
+
|
|
21
|
+
from ...plan_apply import EnvCredentialResolver, Plan, SingleEntityPlanner
|
|
22
|
+
from ..documents import read_bundle, single_document
|
|
23
|
+
from ..exit_status import ExitStatus, exit_status_for
|
|
24
|
+
from ..render import render_error, render_plan
|
|
25
|
+
from ..target_config import ConfigError
|
|
26
|
+
|
|
27
|
+
__all__ = ["plan_command"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _plan_status(plan: Plan) -> ExitStatus:
|
|
31
|
+
return ExitStatus.CHANGES_PENDING if plan.differences else ExitStatus.NOTHING_TO_DO
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _compute_plan(
|
|
35
|
+
file: Path,
|
|
36
|
+
entity_id: str,
|
|
37
|
+
project: str,
|
|
38
|
+
client: Any,
|
|
39
|
+
environ: Mapping[str, str] | None,
|
|
40
|
+
) -> Plan:
|
|
41
|
+
if not entity_id:
|
|
42
|
+
raise ConfigError("plan requires --id of the entity to compare against")
|
|
43
|
+
document = single_document(read_bundle(file))
|
|
44
|
+
# Only ``is_resolvable`` is asked of the resolver; no value is ever read.
|
|
45
|
+
planner = SingleEntityPlanner(client, credentials=EnvCredentialResolver(environ))
|
|
46
|
+
return planner.plan(document, entity_id, project)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def plan_command(
|
|
50
|
+
file: Path,
|
|
51
|
+
entity_id: str | None,
|
|
52
|
+
*,
|
|
53
|
+
json_output: bool,
|
|
54
|
+
project: str,
|
|
55
|
+
client: Any,
|
|
56
|
+
out: TextIO,
|
|
57
|
+
environ: Mapping[str, str] | None = None,
|
|
58
|
+
) -> ExitStatus:
|
|
59
|
+
"""Write the plan of ``file`` against entity ``entity_id`` to ``out``.
|
|
60
|
+
|
|
61
|
+
``environ`` is what ``env:NAME`` references are checked against (default:
|
|
62
|
+
the process environment); credentials are never resolved while planning.
|
|
63
|
+
"""
|
|
64
|
+
try:
|
|
65
|
+
plan = _compute_plan(file, entity_id, project, client, environ)
|
|
66
|
+
except Exception as exc: # noqa: BLE001 - unmapped errors become APPLY_FAILED
|
|
67
|
+
status = exit_status_for(exc, default=ExitStatus.APPLY_FAILED)
|
|
68
|
+
out.write(render_error(exc, json_output=json_output, status=status))
|
|
69
|
+
return status
|
|
70
|
+
status = _plan_status(plan)
|
|
71
|
+
out.write(render_plan(plan, json_output=json_output, status=status))
|
|
72
|
+
return status
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Model of ``codemie.yaml``: known keys, unknown-key warnings, safe errors."""
|
|
16
|
+
|
|
17
|
+
from typing import Any, Mapping
|
|
18
|
+
|
|
19
|
+
from pydantic import BaseModel, ConfigDict, ValidationError, field_validator
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"ConfigError",
|
|
23
|
+
"CodemieConfig",
|
|
24
|
+
"EnvironmentSection",
|
|
25
|
+
"ENVIRONMENT_KEYS",
|
|
26
|
+
"load_config",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ConfigError(Exception):
|
|
31
|
+
"""Missing or invalid target configuration; the message never holds secrets."""
|
|
32
|
+
|
|
33
|
+
def __init__(self, message: str, warnings: tuple[str, ...] = ()) -> None:
|
|
34
|
+
super().__init__(message)
|
|
35
|
+
self.warnings = warnings
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class _Section(BaseModel):
|
|
39
|
+
model_config = ConfigDict(extra="ignore")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ProjectSection(_Section):
|
|
43
|
+
name: str = ""
|
|
44
|
+
description: Any = None
|
|
45
|
+
|
|
46
|
+
@field_validator("name", mode="before")
|
|
47
|
+
@classmethod
|
|
48
|
+
def _text(cls, value: Any) -> str:
|
|
49
|
+
return "" if value is None else str(value)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class EnvironmentSection(_Section):
|
|
53
|
+
codemie_api_url: str = ""
|
|
54
|
+
auth_server_url: str = ""
|
|
55
|
+
auth_realm_name: str = ""
|
|
56
|
+
client_id: str = ""
|
|
57
|
+
client_secret: str = ""
|
|
58
|
+
username: str = ""
|
|
59
|
+
password: str = ""
|
|
60
|
+
verify_ssl: bool = True
|
|
61
|
+
|
|
62
|
+
@field_validator(
|
|
63
|
+
"codemie_api_url",
|
|
64
|
+
"auth_server_url",
|
|
65
|
+
"auth_realm_name",
|
|
66
|
+
"client_id",
|
|
67
|
+
"client_secret",
|
|
68
|
+
"username",
|
|
69
|
+
"password",
|
|
70
|
+
mode="before",
|
|
71
|
+
)
|
|
72
|
+
@classmethod
|
|
73
|
+
def _text(cls, value: Any) -> str:
|
|
74
|
+
return "" if value is None else str(value)
|
|
75
|
+
|
|
76
|
+
@field_validator("verify_ssl", mode="before")
|
|
77
|
+
@classmethod
|
|
78
|
+
def _flag(cls, value: Any) -> bool:
|
|
79
|
+
if value is None or isinstance(value, bool):
|
|
80
|
+
return True if value is None else value
|
|
81
|
+
if isinstance(value, str):
|
|
82
|
+
text = value.strip().lower()
|
|
83
|
+
if text in ("", "true"):
|
|
84
|
+
return True
|
|
85
|
+
if text == "false":
|
|
86
|
+
return False
|
|
87
|
+
raise ValueError("expected true or false")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class CodemieConfig(_Section):
|
|
91
|
+
project: ProjectSection = ProjectSection()
|
|
92
|
+
environment: EnvironmentSection = EnvironmentSection()
|
|
93
|
+
# Node.js package keys: known, never inspected by the Python CLI.
|
|
94
|
+
version: Any = None
|
|
95
|
+
imported: Any = None
|
|
96
|
+
tool_definitions: Any = None
|
|
97
|
+
datasource_defaults: Any = None
|
|
98
|
+
resources: Any = None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
ENVIRONMENT_KEYS: tuple[str, ...] = tuple(EnvironmentSection.model_fields)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _unknown_paths(doc: Mapping[str, Any]) -> list[str]:
|
|
105
|
+
paths = [key for key in doc if key not in CodemieConfig.model_fields]
|
|
106
|
+
for section, model in (
|
|
107
|
+
("project", ProjectSection),
|
|
108
|
+
("environment", EnvironmentSection),
|
|
109
|
+
):
|
|
110
|
+
value = doc.get(section)
|
|
111
|
+
if isinstance(value, dict):
|
|
112
|
+
paths += [
|
|
113
|
+
f"{section}.{key}" for key in value if key not in model.model_fields
|
|
114
|
+
]
|
|
115
|
+
return [str(path) for path in paths]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _error_text(exc: ValidationError) -> str:
|
|
119
|
+
parts = [
|
|
120
|
+
f"{'.'.join(str(p) for p in err['loc'])} ({err['type']})"
|
|
121
|
+
for err in exc.errors(
|
|
122
|
+
include_input=False, include_context=False, include_url=False
|
|
123
|
+
)
|
|
124
|
+
]
|
|
125
|
+
return "codemie.yaml has invalid settings: " + ", ".join(parts)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def load_config(doc: Mapping[str, Any]) -> tuple[CodemieConfig, list[str]]:
|
|
129
|
+
"""Validate ``doc``; return the model and one warning per unknown key path."""
|
|
130
|
+
warnings = [
|
|
131
|
+
f"codemie.yaml: unknown key {path} is ignored" for path in _unknown_paths(doc)
|
|
132
|
+
]
|
|
133
|
+
try:
|
|
134
|
+
return CodemieConfig.model_validate(doc), warnings
|
|
135
|
+
except ValidationError as exc:
|
|
136
|
+
raise ConfigError(_error_text(exc), tuple(warnings)) from None
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Selecting the single document of a file for the single-entity commands."""
|
|
16
|
+
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
from .. import serializer
|
|
20
|
+
from ..envelope import Bundle, Document
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"InvalidDocumentError",
|
|
24
|
+
"read_bundle",
|
|
25
|
+
"single_document",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class InvalidDocumentError(Exception):
|
|
30
|
+
"""The file does not hold exactly one document (exit status 5)."""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def single_document(bundle: Bundle) -> Document:
|
|
34
|
+
"""Return the only document of ``bundle``; raise if there are 0 or >1."""
|
|
35
|
+
if len(bundle) != 1:
|
|
36
|
+
raise InvalidDocumentError(
|
|
37
|
+
f"expected exactly one document, found {len(bundle)}"
|
|
38
|
+
)
|
|
39
|
+
return bundle.root[0]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def read_bundle(path: Path) -> Bundle:
|
|
43
|
+
"""Parse the YAML file at ``path``; unreadable or non-UTF-8 files are invalid."""
|
|
44
|
+
try:
|
|
45
|
+
text = path.read_text(encoding="utf-8")
|
|
46
|
+
except (OSError, UnicodeDecodeError):
|
|
47
|
+
raise InvalidDocumentError(f"cannot read document file {path}") from None
|
|
48
|
+
try:
|
|
49
|
+
return serializer.from_yaml(text)
|
|
50
|
+
except serializer.DocumentParseError as exc:
|
|
51
|
+
# The parser's own message quotes the source line, which may hold a secret.
|
|
52
|
+
raise InvalidDocumentError(f"{path}: {_location(exc)}") from None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _location(exc: serializer.DocumentParseError) -> str:
|
|
56
|
+
mark = getattr(exc.__cause__, "problem_mark", None)
|
|
57
|
+
if mark is None:
|
|
58
|
+
return str(exc) # structural error (empty document): no source quoted
|
|
59
|
+
return f"invalid YAML at line {mark.line + 1}, column {mark.column + 1}"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Copyright 2026 EPAM Systems, Inc. ("EPAM")
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Minimal ``.env`` reader (no ``${}`` expansion, no new dependency)."""
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
from typing import Optional
|
|
19
|
+
|
|
20
|
+
__all__ = ["parse_env_text", "read_env_file"]
|
|
21
|
+
|
|
22
|
+
_KEY = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
|
23
|
+
_EXPORT = re.compile(r"^export\s+")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
_QUOTED = re.compile(r"""^(["'])(.*?)\1(?:\s+#.*)?$""")
|
|
27
|
+
_INLINE_COMMENT = re.compile(r"\s+#.*$")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _unquote(value: str) -> str:
|
|
31
|
+
"""Strip matching quotes (a trailing ``# comment`` after them is dropped)."""
|
|
32
|
+
quoted = _QUOTED.match(value)
|
|
33
|
+
if quoted:
|
|
34
|
+
return quoted.group(2)
|
|
35
|
+
return _INLINE_COMMENT.sub("", value)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _parse_line(raw: str) -> Optional[tuple[str, str]]:
|
|
39
|
+
line = raw.strip()
|
|
40
|
+
if not line or line.startswith("#") or "=" not in line:
|
|
41
|
+
return None
|
|
42
|
+
key, _, value = _EXPORT.sub("", line).partition("=")
|
|
43
|
+
key = key.strip()
|
|
44
|
+
if not _KEY.match(key):
|
|
45
|
+
return None
|
|
46
|
+
return key, _unquote(value.strip())
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def parse_env_text(text: str) -> dict[str, str]:
|
|
50
|
+
"""Parse ``KEY=VALUE`` lines; later duplicates win, bad lines are skipped."""
|
|
51
|
+
values: dict[str, str] = {}
|
|
52
|
+
for raw in text.splitlines():
|
|
53
|
+
parsed = _parse_line(raw)
|
|
54
|
+
if parsed:
|
|
55
|
+
values[parsed[0]] = parsed[1]
|
|
56
|
+
return values
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def read_env_file(path: str) -> dict[str, str]:
|
|
60
|
+
"""Read and parse ``path``; raises ``OSError`` / ``UnicodeDecodeError``."""
|
|
61
|
+
with open(path, encoding="utf-8") as handle:
|
|
62
|
+
return parse_env_text(handle.read())
|