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
codemie_iac/resolver.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
"""Reference resolution within a Bundle context.
|
|
16
|
+
|
|
17
|
+
Resolves (kind, name) references to specific Documents within a Bundle.
|
|
18
|
+
No file I/O or platform calls — resolution happens only within the passed-in Bundle.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from .envelope import Bundle, Document
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ReferenceResolutionError(ValueError):
|
|
25
|
+
"""Raised when a reference cannot be uniquely resolved within a Bundle."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, kind: str, name: str, ambiguous: bool):
|
|
28
|
+
reason = "ambiguous" if ambiguous else "unresolvable"
|
|
29
|
+
super().__init__(
|
|
30
|
+
f"{reason} reference: no unique {kind} named {name!r} in bundle"
|
|
31
|
+
)
|
|
32
|
+
self.kind = kind
|
|
33
|
+
self.name = name
|
|
34
|
+
self.ambiguous = ambiguous
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ReferenceResolver:
|
|
38
|
+
"""Resolves (kind, name) references to Documents within a Bundle."""
|
|
39
|
+
|
|
40
|
+
def __init__(self, bundle: Bundle):
|
|
41
|
+
self._bundle = bundle
|
|
42
|
+
|
|
43
|
+
def resolve(self, kind: str, name: str) -> Document:
|
|
44
|
+
"""Resolve a reference to a unique Document.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
kind: The document kind (e.g., "integration", "skill")
|
|
48
|
+
name: The document name to match
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
The unique Document matching both kind and name
|
|
52
|
+
|
|
53
|
+
Raises:
|
|
54
|
+
ReferenceResolutionError: If zero or multiple matches are found
|
|
55
|
+
"""
|
|
56
|
+
matches = [
|
|
57
|
+
d for d in self._bundle if d.meta.kind == kind and d.meta.name == name
|
|
58
|
+
]
|
|
59
|
+
if len(matches) != 1:
|
|
60
|
+
raise ReferenceResolutionError(kind, name, ambiguous=len(matches) > 1)
|
|
61
|
+
return matches[0]
|
codemie_iac/schema.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
"""JSON Schema generation and offline validation for IaC documents."""
|
|
16
|
+
|
|
17
|
+
import jsonschema
|
|
18
|
+
from pydantic import TypeAdapter
|
|
19
|
+
|
|
20
|
+
from .envelope import Document, _SPEC_BY_KIND
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def document_json_schema() -> dict:
|
|
24
|
+
"""Return the JSON Schema for Document derived from the Pydantic model."""
|
|
25
|
+
return Document.model_json_schema()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class DocumentValidationError(ValueError):
|
|
29
|
+
"""Raised when a document fails JSON Schema validation.
|
|
30
|
+
|
|
31
|
+
``json_path``/``message`` describe the first violation found. jsonschema
|
|
32
|
+
can report more than one problem per document (CR-005); every violation
|
|
33
|
+
found during this call, formatted the same way, is available via
|
|
34
|
+
``errors`` so a caller does not have to fix-and-rerun to discover a
|
|
35
|
+
second, previously-hidden one.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(self, json_path: str, message: str, errors: list[str] | None = None):
|
|
39
|
+
all_errors = errors if errors is not None else [f"{json_path}: {message}"]
|
|
40
|
+
suffix = (
|
|
41
|
+
f" ({len(all_errors)} total validation errors)"
|
|
42
|
+
if len(all_errors) > 1
|
|
43
|
+
else ""
|
|
44
|
+
)
|
|
45
|
+
super().__init__(f"{json_path}: {message}{suffix}")
|
|
46
|
+
self.json_path = json_path
|
|
47
|
+
self.message = message
|
|
48
|
+
self.errors = all_errors
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _prefix_json_path(json_path: str, prefix: str) -> str:
|
|
52
|
+
"""Rewrite a jsonschema ``$``-rooted path (e.g. ``$.name``) under ``prefix``."""
|
|
53
|
+
if json_path == "$":
|
|
54
|
+
return f"$.{prefix}"
|
|
55
|
+
return f"$.{prefix}.{json_path[2:]}"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def validate_document(data: dict) -> None:
|
|
59
|
+
"""Validate a dictionary against the Document JSON Schema, fully offline.
|
|
60
|
+
|
|
61
|
+
First validates ``data`` against the overall ``Document`` schema (shared
|
|
62
|
+
structure: ``version``/``meta``/``spec`` as a six-member ``anyOf``).
|
|
63
|
+
When ``meta.kind`` is present and recognized, ``spec`` is additionally,
|
|
64
|
+
separately validated against that *specific* Spec class's own schema --
|
|
65
|
+
reusing the same ``_SPEC_BY_KIND`` mapping ``Document``'s own
|
|
66
|
+
kind-dispatch validator uses (CR-004). Without this second pass, a
|
|
67
|
+
``spec`` payload that happens to satisfy a looser *different* kind's
|
|
68
|
+
schema (e.g. a `skill` spec missing required fields that nonetheless
|
|
69
|
+
satisfies `CategorySpec`'s schema) would pass here while still being
|
|
70
|
+
rejected by ``Document.model_validate``/``from_yaml``, defeating the
|
|
71
|
+
offline pre-flight-check guarantee this function exists to provide.
|
|
72
|
+
|
|
73
|
+
Raises DocumentValidationError naming the first offending JSON path;
|
|
74
|
+
every violation found this call is available via the raised error's
|
|
75
|
+
``errors`` attribute.
|
|
76
|
+
"""
|
|
77
|
+
validator = jsonschema.Draft202012Validator(document_json_schema())
|
|
78
|
+
errors = list(validator.iter_errors(data))
|
|
79
|
+
if errors:
|
|
80
|
+
formatted = [f"{error.json_path}: {error.message}" for error in errors]
|
|
81
|
+
raise DocumentValidationError(
|
|
82
|
+
errors[0].json_path, errors[0].message, errors=formatted
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
if not isinstance(data, dict):
|
|
86
|
+
return
|
|
87
|
+
meta = data.get("meta")
|
|
88
|
+
kind = meta.get("kind") if isinstance(meta, dict) else None
|
|
89
|
+
spec_cls = _SPEC_BY_KIND.get(kind) if kind is not None else None
|
|
90
|
+
spec_data = data.get("spec")
|
|
91
|
+
if spec_cls is None or not isinstance(spec_data, dict):
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
spec_validator = jsonschema.Draft202012Validator(
|
|
95
|
+
TypeAdapter(spec_cls).json_schema()
|
|
96
|
+
)
|
|
97
|
+
spec_errors = list(spec_validator.iter_errors(spec_data))
|
|
98
|
+
if spec_errors:
|
|
99
|
+
formatted = [
|
|
100
|
+
f"{_prefix_json_path(error.json_path, 'spec')}: {error.message}"
|
|
101
|
+
for error in spec_errors
|
|
102
|
+
]
|
|
103
|
+
first = spec_errors[0]
|
|
104
|
+
raise DocumentValidationError(
|
|
105
|
+
_prefix_json_path(first.json_path, "spec"), first.message, errors=formatted
|
|
106
|
+
)
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
import yaml
|
|
16
|
+
from .envelope import Bundle, Document
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DocumentParseError(ValueError):
|
|
20
|
+
"""Raised when YAML text cannot even be parsed (invalid YAML syntax).
|
|
21
|
+
|
|
22
|
+
Keeps ``from_yaml``'s public error contract consistent with
|
|
23
|
+
``DocumentValidationError``/``ReferenceResolutionError`` -- a caller
|
|
24
|
+
should be able to catch one domain exception type for "this document
|
|
25
|
+
could not be read" rather than also needing to know about the
|
|
26
|
+
third-party ``yaml.YAMLError`` hierarchy (CR-006).
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def to_yaml(bundle: Bundle) -> str:
|
|
31
|
+
# Not `exclude_none=True`: several fields default to something other than
|
|
32
|
+
# `None` (e.g. WorkflowAssistant.limit_tool_output_tokens=10000,
|
|
33
|
+
# SkillSpec.visibility="project"). Dropping an explicit `None` there would
|
|
34
|
+
# have `from_yaml` reload it as that non-None default instead, breaking
|
|
35
|
+
# the documented `from_yaml(to_yaml(b)) == b` round trip and making a
|
|
36
|
+
# second dump of the reloaded bundle differ from the first.
|
|
37
|
+
docs = [doc.model_dump(mode="json") for doc in bundle]
|
|
38
|
+
return yaml.safe_dump_all(
|
|
39
|
+
docs,
|
|
40
|
+
sort_keys=False,
|
|
41
|
+
default_flow_style=False,
|
|
42
|
+
explicit_start=True,
|
|
43
|
+
allow_unicode=True,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def from_yaml(text: str) -> Bundle:
|
|
48
|
+
try:
|
|
49
|
+
raw_docs = list(yaml.safe_load_all(text))
|
|
50
|
+
except yaml.YAMLError as exc:
|
|
51
|
+
raise DocumentParseError(f"invalid YAML: {exc}") from exc
|
|
52
|
+
# A trailing "---" with nothing after it parses as one extra `None`
|
|
53
|
+
# entry at the very end -- a harmless artifact, not data loss. Drop
|
|
54
|
+
# only that one; any other empty sub-document (CR-002) is a truncated
|
|
55
|
+
# or malformed file and must not be silently discarded, the same
|
|
56
|
+
# "nothing silently dropped" intent AC6 already enforces for a field.
|
|
57
|
+
if raw_docs and raw_docs[-1] is None:
|
|
58
|
+
raw_docs = raw_docs[:-1]
|
|
59
|
+
for index, raw in enumerate(raw_docs):
|
|
60
|
+
if raw is None:
|
|
61
|
+
raise DocumentParseError(
|
|
62
|
+
f"empty document at position {index} (not the trailing one)"
|
|
63
|
+
)
|
|
64
|
+
return Bundle([Document.model_validate(raw) for raw in raw_docs])
|
|
@@ -0,0 +1,13 @@
|
|
|
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.
|