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,188 @@
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
+ """Document envelope types shared by all IaC document kinds.
16
+
17
+ ``DocumentMeta`` carries the document's ``kind``/``name`` discriminator,
18
+ ``Document`` wraps a concrete ``*Spec`` payload with that metadata, and
19
+ ``Bundle`` is an ordered collection of ``Document`` instances (potentially
20
+ mixing different ``kind``s) that round-trips through ``model_dump``.
21
+ """
22
+
23
+ from enum import Enum
24
+ from typing import Any, Union, get_args, get_origin
25
+
26
+ from pydantic import BaseModel, ConfigDict, RootModel, TypeAdapter, model_validator
27
+
28
+ from .specs.assistant import AssistantSpec
29
+ from .specs.category import CategorySpec
30
+ from .specs.datasource import DatasourceSpec
31
+ from .specs.integration import IntegrationSpec
32
+ from .specs.skill import SkillSpec
33
+ from .specs.workflow import WorkflowSpec
34
+
35
+
36
+ class DocumentKind(str, Enum):
37
+ """The closed set of resource kinds a ``Document`` can hold.
38
+
39
+ Unlike ``*Spec.type`` (e.g. ``DatasourceSpec``'s nine-way discriminator),
40
+ this is not a pydantic discriminated-union tag -- ``Document._dispatch_spec``
41
+ below looks ``meta.kind`` up in ``_SPEC_BY_KIND`` manually, before pydantic's
42
+ own union resolution ever runs (see that method's docstring for why). So
43
+ there is no discriminated-union convention pulling this towards ``Literal``;
44
+ it is just a fixed vocabulary, which is what ``Enum`` is for.
45
+ """
46
+
47
+ ASSISTANT = "assistant"
48
+ DATASOURCE = "datasource"
49
+ INTEGRATION = "integration"
50
+ SKILL = "skill"
51
+ CATEGORY = "category"
52
+ WORKFLOW = "workflow"
53
+
54
+
55
+ _SPEC_BY_KIND = {
56
+ DocumentKind.ASSISTANT: AssistantSpec,
57
+ DocumentKind.DATASOURCE: DatasourceSpec,
58
+ DocumentKind.INTEGRATION: IntegrationSpec,
59
+ DocumentKind.SKILL: SkillSpec,
60
+ DocumentKind.CATEGORY: CategorySpec,
61
+ DocumentKind.WORKFLOW: WorkflowSpec,
62
+ }
63
+
64
+
65
+ def _spec_classes(spec_type) -> tuple[type, ...]:
66
+ """Concrete spec classes behind a ``_SPEC_BY_KIND`` entry.
67
+
68
+ ``isinstance`` rejects a subscripted generic, and ``DatasourceSpec`` is an
69
+ ``Annotated[Union[...]]`` of per-type specs, so unwrap it into the plain
70
+ member classes. A plain class unwraps to itself.
71
+ """
72
+ if get_origin(spec_type) is Union:
73
+ return tuple(
74
+ cls for member in get_args(spec_type) for cls in _spec_classes(member)
75
+ )
76
+ args = get_args(spec_type)
77
+ if args: # Annotated[X, ...] -> its first argument is the wrapped type
78
+ return _spec_classes(args[0])
79
+ return (spec_type,)
80
+
81
+
82
+ # Validation errors must never echo input values: a datasource document can
83
+ # carry a literal secret that the offline name check rejects.
84
+ _HIDE_INPUT = ConfigDict(hide_input_in_errors=True)
85
+
86
+
87
+ def _spec_adapter(spec_cls: Any) -> TypeAdapter:
88
+ """Adapter for ``spec_cls``; unions (not plain models) accept a config."""
89
+ if isinstance(spec_cls, type):
90
+ return TypeAdapter(spec_cls)
91
+ return TypeAdapter(spec_cls, config=_HIDE_INPUT)
92
+
93
+
94
+ class DocumentMeta(BaseModel):
95
+ """Discriminator metadata attached to every ``Document``."""
96
+
97
+ model_config = ConfigDict(extra="forbid")
98
+
99
+ kind: DocumentKind
100
+ name: str
101
+
102
+
103
+ class Document(BaseModel):
104
+ """A single IaC document: version, metadata, and a kind-specific spec.
105
+
106
+ ``meta.kind`` is the real discriminator for ``spec`` -- several Spec
107
+ classes share field names (e.g. ``name``/``description``), so letting
108
+ pydantic's own union resolution try each member in turn could silently
109
+ pick the wrong one, or surface an unhelpful "no match in union" error
110
+ instead of naming the actual offending field. The before-validator below
111
+ uses ``meta.kind`` to select and pre-validate the correct Spec class
112
+ before pydantic's union logic ever runs, so an unknown field inside
113
+ ``spec`` is reported by that Spec's own ``extra="forbid"`` validation
114
+ (naming the field) rather than by the union as a whole.
115
+ """
116
+
117
+ model_config = ConfigDict(extra="forbid", hide_input_in_errors=True)
118
+
119
+ version: str
120
+ meta: DocumentMeta
121
+ spec: (
122
+ AssistantSpec
123
+ | DatasourceSpec
124
+ | IntegrationSpec
125
+ | SkillSpec
126
+ | CategorySpec
127
+ | WorkflowSpec
128
+ )
129
+
130
+ @model_validator(mode="before")
131
+ @classmethod
132
+ def _dispatch_spec(cls, data):
133
+ if isinstance(data, dict) and isinstance(data.get("spec"), dict):
134
+ # CR-003: `meta` can be present but not a dict (e.g. a malformed
135
+ # hand-edited document with `meta: "oops"`) -- `.get("kind")` on
136
+ # a non-dict truthy value raises an uncaught AttributeError
137
+ # instead of letting normal field validation report a clean
138
+ # ValidationError naming `meta`. Guard explicitly instead.
139
+ meta = data.get("meta")
140
+ kind = meta.get("kind") if isinstance(meta, dict) else None
141
+ # `kind` is still caller-controlled, untyped data at this point
142
+ # (e.g. `meta: {kind: ["x"]}`) -- `dict.get` on an unhashable
143
+ # value raises a raw TypeError instead of a clean ValidationError
144
+ # naming `meta.kind`, which normal field validation produces once
145
+ # this before-validator steps aside and lets it run.
146
+ try:
147
+ spec_cls = _SPEC_BY_KIND.get(kind)
148
+ except TypeError:
149
+ spec_cls = None
150
+ if spec_cls is not None:
151
+ data = {
152
+ **data,
153
+ "spec": _spec_adapter(spec_cls).validate_python(data["spec"]),
154
+ }
155
+ return data
156
+
157
+ @model_validator(mode="after")
158
+ def _check_spec_matches_kind(self) -> "Document":
159
+ """Reject a `spec` whose type doesn't match `meta.kind`.
160
+
161
+ `_dispatch_spec` above only resolves `spec`'s type when it arrives as
162
+ a raw dict (the YAML-loading path). A `Document` built from model
163
+ instances skips that dispatch entirely, and pydantic's union
164
+ resolution accepts a value that's already an instance of one of the
165
+ union's members as-is -- so `Document(meta=DocumentMeta(kind="skill",
166
+ ...), spec=CategorySpec(...))` would otherwise validate with a
167
+ `spec` that doesn't match its own `meta.kind`, and `to_yaml` would
168
+ write a kind/body mismatch that `from_yaml` then rejects.
169
+ """
170
+ expected = _SPEC_BY_KIND[self.meta.kind]
171
+ classes = _spec_classes(expected)
172
+ if not isinstance(self.spec, classes):
173
+ names = " | ".join(cls.__name__ for cls in classes)
174
+ raise ValueError(
175
+ f"meta.kind={self.meta.kind.value!r} requires spec to be a "
176
+ f"{names}, got {type(self.spec).__name__}"
177
+ )
178
+ return self
179
+
180
+
181
+ class Bundle(RootModel[list[Document]]):
182
+ """An ordered collection of ``Document`` instances, possibly mixed-kind."""
183
+
184
+ def __iter__(self):
185
+ return iter(self.root)
186
+
187
+ def __len__(self):
188
+ return len(self.root)
@@ -0,0 +1,70 @@
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
+ from .bulk_create import (
16
+ BulkCreator,
17
+ BulkCreateReport,
18
+ CreatedEntity,
19
+ FailedEntity,
20
+ )
21
+ from .credentials import EnvCredentialResolver, SecretValue
22
+ from .errors import (
23
+ ApplyError,
24
+ FieldError,
25
+ PlatformRejectionError,
26
+ UnresolvableCredentialError,
27
+ UnresolvedReferenceError,
28
+ )
29
+ from .field_policy import FIELD_POLICIES, FieldPolicy
30
+ from .guards import guard_datasource_identity, guard_supported
31
+ from .kinds import ADAPTERS, KindAdapter, adapter_for
32
+ from .lookup import NameLookup
33
+ from .ordering import DependencyGraph
34
+ from .single_apply import (
35
+ ApplyResult,
36
+ CannotCompare,
37
+ Difference,
38
+ Plan,
39
+ SingleEntityPlanner,
40
+ diff,
41
+ )
42
+
43
+ __all__ = [
44
+ "ADAPTERS",
45
+ "FIELD_POLICIES",
46
+ "ApplyError",
47
+ "ApplyResult",
48
+ "BulkCreateReport",
49
+ "BulkCreator",
50
+ "CannotCompare",
51
+ "CreatedEntity",
52
+ "DependencyGraph",
53
+ "Difference",
54
+ "EnvCredentialResolver",
55
+ "FailedEntity",
56
+ "FieldError",
57
+ "FieldPolicy",
58
+ "KindAdapter",
59
+ "NameLookup",
60
+ "Plan",
61
+ "PlatformRejectionError",
62
+ "SecretValue",
63
+ "SingleEntityPlanner",
64
+ "UnresolvableCredentialError",
65
+ "UnresolvedReferenceError",
66
+ "adapter_for",
67
+ "diff",
68
+ "guard_datasource_identity",
69
+ "guard_supported",
70
+ ]