codemie-cdk-python 0.1.0rc0__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 (39) hide show
  1. codemie_cdk_python-0.1.0rc0.dist-info/METADATA +840 -0
  2. codemie_cdk_python-0.1.0rc0.dist-info/RECORD +39 -0
  3. codemie_cdk_python-0.1.0rc0.dist-info/WHEEL +4 -0
  4. codemie_cdk_python-0.1.0rc0.dist-info/entry_points.txt +3 -0
  5. codemie_iac/__init__.py +49 -0
  6. codemie_iac/cli/__init__.py +17 -0
  7. codemie_iac/cli/__main__.py +24 -0
  8. codemie_iac/cli/commands/__init__.py +17 -0
  9. codemie_iac/cli/commands/apply.py +119 -0
  10. codemie_iac/cli/commands/plan.py +72 -0
  11. codemie_iac/cli/documents.py +59 -0
  12. codemie_iac/cli/env_file.py +62 -0
  13. codemie_iac/cli/exit_status.py +80 -0
  14. codemie_iac/cli/main.py +118 -0
  15. codemie_iac/cli/render.py +206 -0
  16. codemie_iac/cli/target_config.py +230 -0
  17. codemie_iac/cli/token_client.py +42 -0
  18. codemie_iac/credentials.py +99 -0
  19. codemie_iac/envelope.py +188 -0
  20. codemie_iac/plan_apply/__init__.py +70 -0
  21. codemie_iac/plan_apply/bulk_create.py +561 -0
  22. codemie_iac/plan_apply/credentials.py +306 -0
  23. codemie_iac/plan_apply/errors.py +223 -0
  24. codemie_iac/plan_apply/field_policy.py +185 -0
  25. codemie_iac/plan_apply/guards.py +221 -0
  26. codemie_iac/plan_apply/kinds.py +815 -0
  27. codemie_iac/plan_apply/lookup.py +313 -0
  28. codemie_iac/plan_apply/ordering.py +177 -0
  29. codemie_iac/plan_apply/single_apply.py +751 -0
  30. codemie_iac/resolver.py +61 -0
  31. codemie_iac/schema.py +106 -0
  32. codemie_iac/serializer.py +64 -0
  33. codemie_iac/specs/__init__.py +13 -0
  34. codemie_iac/specs/assistant.py +509 -0
  35. codemie_iac/specs/category.py +36 -0
  36. codemie_iac/specs/datasource.py +595 -0
  37. codemie_iac/specs/integration.py +103 -0
  38. codemie_iac/specs/skill.py +51 -0
  39. codemie_iac/specs/workflow.py +154 -0
@@ -0,0 +1,39 @@
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/documents.py,sha256=qnSyjMe2WVsxpED6YcV-oe16JhqAW9BlP-h2ahNMAhg,2111
8
+ codemie_iac/cli/env_file.py,sha256=Wg-lb7vCTcN6HtLV2PRWLc4BnPVVEOReaBoat13CgiM,2037
9
+ codemie_iac/cli/exit_status.py,sha256=eDU4f9YtoQfCzqVWB8HG3Fb20Loxm4Yc-dJdnnM33sQ,2450
10
+ codemie_iac/cli/main.py,sha256=e6KaWdDQFcaKO0zL8h9K6wrXeCp8tXO26Nh8Jo_PAHE,4454
11
+ codemie_iac/cli/render.py,sha256=AgVRJCl-obCPJ6IhPlIF9ETNr6TWpe8FeB3sY3oDVPk,6764
12
+ codemie_iac/cli/target_config.py,sha256=7WYZ3LtTLoXa1dpF8ZVFsVai7HKEyrERYjk9ZqRJL5I,8303
13
+ codemie_iac/cli/token_client.py,sha256=fAmoz6nd9DkaXOHvfL5Crub-3aF67AiSsyRbe-Mzgk8,1966
14
+ codemie_iac/credentials.py,sha256=uvROZACh-Sp98GOjY_lHM5TGkJ6gIhexyMXJmONAcWU,4631
15
+ codemie_iac/envelope.py,sha256=T4x1hV_2K6KCjbgoRloc_9a2RGj0sUEg9KKmrpnKBAI,7435
16
+ codemie_iac/plan_apply/__init__.py,sha256=LKt2hxat5OCRSXW9zsBCpz2C-BLuZQPYMz5F958PkeE,1852
17
+ codemie_iac/plan_apply/bulk_create.py,sha256=D4gRl_mY6hleNFRq6cPjptwm8OXP66A5IL4bTQZ8u1Q,19998
18
+ codemie_iac/plan_apply/credentials.py,sha256=cGB9UmlvrXZFNg4BBV-7vWDEJIWKM-vZsgupQZn0BTU,11159
19
+ codemie_iac/plan_apply/errors.py,sha256=--RgYunR_5oGvAHlyGRNqelHdizWg2b0d219flaVqkI,7503
20
+ codemie_iac/plan_apply/field_policy.py,sha256=LFl3_LIsowbIfPN7eJEL9RcegBG0K9JiANG-xiy1JKc,7973
21
+ codemie_iac/plan_apply/guards.py,sha256=Ejm40B1XPwUuSO4CkbJLiPZqYUeWvr3R7zR7Lvr3Viw,8388
22
+ codemie_iac/plan_apply/kinds.py,sha256=qebyTVwx_fSzSsX6EaqfCja6w5mQ3DuA1agP4tAchL4,30839
23
+ codemie_iac/plan_apply/lookup.py,sha256=psHKgMLHIaKIdS-_pMECMdzbH2kxqJYkiae-Xs2sIUY,11951
24
+ codemie_iac/plan_apply/ordering.py,sha256=YBPoSjSMC1YcBvQVhd4e9N4Nr9dS7okkJ65AGUQlHUE,6350
25
+ codemie_iac/plan_apply/single_apply.py,sha256=d_HzvAvs3hRdPIM9-GP1v8jcXFpFsh1o5CETKR7Gwnc,27861
26
+ codemie_iac/resolver.py,sha256=rncBpQ0-UPIY_X6qt5txBOttCcHJYaP91Z6M4qPbvwQ,2138
27
+ codemie_iac/schema.py,sha256=Pswh7UMlfVQn2fMcRxe1lu39G4fTVltkohTRKgcDZQw,4337
28
+ codemie_iac/serializer.py,sha256=KwLUlkFZ4Sp0xNlullm9BCZqqateSNwRmWOoSbt9QBM,2700
29
+ codemie_iac/specs/__init__.py,sha256=ufdnwla10roWz8Sr-GZPCXVhNwfrCKI8JBTWwIkwvgA,591
30
+ codemie_iac/specs/assistant.py,sha256=SQXy7y6mtT4kpl4ax8ckYazrLuW5vLGVuwzjnXNYp2U,20992
31
+ codemie_iac/specs/category.py,sha256=hiWdIzFBryPXW4RZLxZybxBfp2xJoMLMZmDcAU3S65k,1359
32
+ codemie_iac/specs/datasource.py,sha256=oUPNllLaBUNU1JI-Thx7t02V-vDNzmsnwjduOR02TGs,21155
33
+ codemie_iac/specs/integration.py,sha256=Fcp_OH_Uw-7X6a3aeS8qSLrTD6fy7Oc6x2xXPew1wUg,4154
34
+ codemie_iac/specs/skill.py,sha256=dw1n7ztqilxtMrjAi35H1tXDolTtfbITFJ3yeZ0trZ0,2043
35
+ codemie_iac/specs/workflow.py,sha256=97R_4SD2gkpoKOV1y72pzbmZMVQqBnzLWWmrExrLRMw,7689
36
+ codemie_cdk_python-0.1.0rc0.dist-info/METADATA,sha256=4usB-i-UnfsQAuen-zb4zdD3AXDU1ZQwIPOClGk2aqk,40850
37
+ codemie_cdk_python-0.1.0rc0.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
38
+ codemie_cdk_python-0.1.0rc0.dist-info/entry_points.txt,sha256=zOUpiYyufKd-d6dBpkBcC_QmZ6eoktcYICYroxaw_bw,57
39
+ codemie_cdk_python-0.1.0rc0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.5.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ codemie-iac=codemie_iac.cli.main:main
3
+
@@ -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,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())
@@ -0,0 +1,80 @@
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
+ """Process exit statuses of the plan/apply CLI and the exception mapping."""
16
+
17
+ from enum import IntEnum
18
+
19
+ from pydantic import ValidationError
20
+
21
+ from ..plan_apply.errors import (
22
+ ApplyError,
23
+ PlatformRejectionError,
24
+ UnresolvableCredentialError,
25
+ UnresolvedReferenceError,
26
+ )
27
+ from ..resolver import ReferenceResolutionError
28
+ from ..schema import DocumentValidationError
29
+ from ..serializer import DocumentParseError
30
+ from .documents import InvalidDocumentError
31
+ from .target_config import ConfigError
32
+
33
+ __all__ = ["ExitStatus", "exit_status_for"]
34
+
35
+
36
+ class ExitStatus(IntEnum):
37
+ """Exit codes; ``NOTHING_TO_DO`` is an alias of ``SUCCESS``."""
38
+
39
+ SUCCESS = 0
40
+ NOTHING_TO_DO = 0
41
+ CHANGES_PENDING = 1
42
+ APPLY_FAILED = 2
43
+ UNRESOLVED_INPUT = 3
44
+ CONFIG_ERROR = 4
45
+ INVALID_DOCUMENT = 5
46
+
47
+
48
+ #: Checked in order: subclasses of ``ApplyError`` precede ``ApplyError``
49
+ #: itself, which the guards raise for unsupported or inconsistent documents.
50
+ _MAPPING: tuple[tuple[tuple[type[BaseException], ...], ExitStatus], ...] = (
51
+ ((ConfigError,), ExitStatus.CONFIG_ERROR),
52
+ (
53
+ (UnresolvedReferenceError, UnresolvableCredentialError),
54
+ ExitStatus.UNRESOLVED_INPUT,
55
+ ),
56
+ ((PlatformRejectionError,), ExitStatus.APPLY_FAILED),
57
+ (
58
+ (
59
+ ApplyError,
60
+ DocumentParseError,
61
+ DocumentValidationError,
62
+ ValidationError,
63
+ ReferenceResolutionError,
64
+ InvalidDocumentError,
65
+ ),
66
+ ExitStatus.INVALID_DOCUMENT,
67
+ ),
68
+ )
69
+
70
+
71
+ def exit_status_for(
72
+ exc: BaseException, default: ExitStatus | None = None
73
+ ) -> ExitStatus:
74
+ """Return the exit status for ``exc``; ``default`` if unknown, else raise it."""
75
+ for types, status in _MAPPING:
76
+ if isinstance(exc, types):
77
+ return status
78
+ if default is None:
79
+ raise exc
80
+ return default
@@ -0,0 +1,118 @@
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
+ """Entrypoint of the ``codemie-iac`` command line."""
16
+
17
+ import argparse
18
+ import sys
19
+ from pathlib import Path
20
+ from typing import Any, Callable, Optional, Sequence
21
+
22
+ from .commands.apply import apply_command
23
+ from .commands.plan import plan_command
24
+ from .exit_status import ExitStatus
25
+ from .render import render_error
26
+ from .target_config import ConfigError, TargetConfig
27
+
28
+ __all__ = ["main"]
29
+
30
+
31
+ def _add_plan(sub: argparse.ArgumentParser) -> None:
32
+ sub.add_argument("file", type=Path, help="document file to compare")
33
+ sub.add_argument("--id", dest="entity_id", default=None, help="entity id")
34
+
35
+
36
+ def _add_apply(sub: argparse.ArgumentParser) -> None:
37
+ sub.add_argument("path", type=Path, help="document file or directory")
38
+ sub.add_argument("--id", dest="entity_id", default=None, help="entity id")
39
+
40
+
41
+ def _run_plan(args: argparse.Namespace, **context: Any) -> ExitStatus:
42
+ return plan_command(args.file, args.entity_id, **context)
43
+
44
+
45
+ def _run_apply(args: argparse.Namespace, **context: Any) -> ExitStatus:
46
+ return apply_command(args.path, args.entity_id, **context)
47
+
48
+
49
+ # name -> (help, argument registrar, runner); extend to add commands.
50
+ _COMMANDS: dict[str, tuple[str, Callable, Callable]] = {
51
+ "plan": ("Show the diff against a live entity", _add_plan, _run_plan),
52
+ "apply": ("Apply documents to the platform", _add_apply, _run_apply),
53
+ }
54
+
55
+
56
+ def _build_parser() -> argparse.ArgumentParser:
57
+ parser = argparse.ArgumentParser(prog="codemie-iac")
58
+ parser.add_argument("--project", default=None, help="target project")
59
+ parser.add_argument("-c", "--config", default=None, help="codemie.yaml path")
60
+ parser.add_argument("--env-file", default=None, help=".env path")
61
+ subparsers = parser.add_subparsers(dest="command", required=True)
62
+ for name, (help_text, register, _) in _COMMANDS.items():
63
+ sub = subparsers.add_parser(name, help=help_text)
64
+ register(sub)
65
+ sub.add_argument("--json", action="store_true", help="JSON output")
66
+ return parser
67
+
68
+
69
+ def _parse(argv: Optional[Sequence[str]]) -> Optional[argparse.Namespace]:
70
+ try:
71
+ return _build_parser().parse_args(argv)
72
+ except SystemExit as exc:
73
+ if exc.code in (0, None):
74
+ raise
75
+ raise SystemExit(int(ExitStatus.CONFIG_ERROR)) from None
76
+
77
+
78
+ def _fail(exc: Exception, args: argparse.Namespace, status: ExitStatus) -> ExitStatus:
79
+ sys.stdout.write(render_error(exc, json_output=args.json, status=status))
80
+ return status
81
+
82
+
83
+ def _check_usage(args: argparse.Namespace) -> None:
84
+ """Reject bad argument combinations before any network call is made."""
85
+ if args.command == "plan" and not args.entity_id:
86
+ raise ConfigError("plan requires --id of the entity to compare against")
87
+ if args.command == "apply" and args.entity_id and args.path.is_dir():
88
+ raise ConfigError("--id cannot be combined with a directory")
89
+
90
+
91
+ def _dispatch(args: argparse.Namespace) -> ExitStatus:
92
+ try:
93
+ _check_usage(args)
94
+ target = TargetConfig.resolve(args.project, args.config, env_file=args.env_file)
95
+ client = target.build_client()
96
+ except Exception as exc: # noqa: BLE001 - rendered by type name only
97
+ return _fail(exc, args, ExitStatus.CONFIG_ERROR)
98
+ runner = _COMMANDS[args.command][2]
99
+ try:
100
+ return runner(
101
+ args,
102
+ json_output=args.json,
103
+ project=target.project,
104
+ environ=target.environment,
105
+ client=client,
106
+ out=sys.stdout,
107
+ )
108
+ except Exception as exc: # noqa: BLE001 - rendered by type name only
109
+ return _fail(exc, args, ExitStatus.APPLY_FAILED)
110
+
111
+
112
+ def main(argv: Optional[Sequence[str]] = None) -> int:
113
+ """Run the CLI and return the process exit code."""
114
+ try:
115
+ args = _parse(argv)
116
+ except SystemExit as exc:
117
+ return int(exc.code or 0)
118
+ return int(_dispatch(args))