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.
- codemie_cdk_python-0.1.0rc0.dist-info/METADATA +840 -0
- codemie_cdk_python-0.1.0rc0.dist-info/RECORD +39 -0
- codemie_cdk_python-0.1.0rc0.dist-info/WHEEL +4 -0
- codemie_cdk_python-0.1.0rc0.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/documents.py +59 -0
- codemie_iac/cli/env_file.py +62 -0
- codemie_iac/cli/exit_status.py +80 -0
- codemie_iac/cli/main.py +118 -0
- codemie_iac/cli/render.py +206 -0
- codemie_iac/cli/target_config.py +230 -0
- codemie_iac/cli/token_client.py +42 -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 +185 -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,595 @@
|
|
|
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
|
+
"""Spec that narrows the ``codemie_sdk.models.datasource`` request classes
|
|
16
|
+
(subclasses of ``BaseDataSourceRequest``, plus the provider request) for IaC
|
|
17
|
+
documents.
|
|
18
|
+
|
|
19
|
+
Datasources authenticate via a referenced integration (``setting_id``, a
|
|
20
|
+
plain string naming/identifying an integration) rather than an inline
|
|
21
|
+
secret. Two places carry secrets and narrow them to ``env:`` references: the
|
|
22
|
+
SharePoint ``access_token`` (a ``CredentialRef``; the OAuth token is transient
|
|
23
|
+
and the platform never returns it) and the free-form
|
|
24
|
+
``ProviderDatasourceSpec.settings`` map. For ``settings``, the values the
|
|
25
|
+
platform provider schema marks secret must be ``env:`` references, enforced
|
|
26
|
+
authoritatively by credential scanning (``plan_apply.credentials.SECRET_FIELDS``)
|
|
27
|
+
at plan/apply; here only a best-effort name heuristic rejects literals under
|
|
28
|
+
secret-looking setting names.
|
|
29
|
+
``DatasourceSpec`` is a ``type``-discriminated union over the thirteen
|
|
30
|
+
per-kind ``*DatasourceSpec`` classes below.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
import re
|
|
34
|
+
from collections.abc import Callable, Iterator
|
|
35
|
+
from itertools import pairwise
|
|
36
|
+
from typing import Annotated, Any, Literal, Union
|
|
37
|
+
|
|
38
|
+
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
|
39
|
+
|
|
40
|
+
from codemie_sdk.models.datasource import (
|
|
41
|
+
AzureDevOpsWikiDataSourceRequest,
|
|
42
|
+
AzureDevOpsWorkItemDataSourceRequest,
|
|
43
|
+
BaseDataSourceRequest,
|
|
44
|
+
CodeDataSourceRequest,
|
|
45
|
+
ConfluenceDataSourceRequest,
|
|
46
|
+
FileDataSourceRequest,
|
|
47
|
+
GitFaqDataSourceRequest,
|
|
48
|
+
GoogleDataSourceRequest,
|
|
49
|
+
JiraDataSourceRequest,
|
|
50
|
+
ProviderDataSourceRequest,
|
|
51
|
+
SharePointDataSourceRequest,
|
|
52
|
+
SvnDataSourceRequest,
|
|
53
|
+
XrayDataSourceRequest,
|
|
54
|
+
XWikiDataSourceRequest,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
from ..credentials import CredentialRef
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _base_kwargs(request: BaseDataSourceRequest) -> dict:
|
|
61
|
+
"""Fields every ``*DatasourceSpec`` shares with its ``*DataSourceRequest``."""
|
|
62
|
+
return {
|
|
63
|
+
"name": request.name,
|
|
64
|
+
"project_name": request.project_name,
|
|
65
|
+
"description": request.description,
|
|
66
|
+
"shared_with_project": request.shared_with_project,
|
|
67
|
+
"setting_id": request.setting_id,
|
|
68
|
+
"cron_expression": request.cron_expression,
|
|
69
|
+
"timezone": request.timezone,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class _DatasourceSpecBase(BaseModel):
|
|
74
|
+
"""Shared fields from ``BaseDataSourceRequest``."""
|
|
75
|
+
|
|
76
|
+
model_config = ConfigDict(extra="forbid")
|
|
77
|
+
|
|
78
|
+
name: str
|
|
79
|
+
project_name: str | None = None
|
|
80
|
+
description: str
|
|
81
|
+
shared_with_project: bool = False
|
|
82
|
+
setting_id: str | None = None
|
|
83
|
+
cron_expression: str | None = None
|
|
84
|
+
timezone: str | None = None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class CodeDatasourceSpec(_DatasourceSpecBase):
|
|
88
|
+
"""Narrows ``CodeDataSourceRequest`` (type=``code``)."""
|
|
89
|
+
|
|
90
|
+
type: Literal["code"] = "code"
|
|
91
|
+
# link, branch and index_type are required by the platform (as for svn).
|
|
92
|
+
link: str = Field(..., min_length=1, max_length=1000)
|
|
93
|
+
branch: str = Field(..., min_length=1, max_length=1000)
|
|
94
|
+
index_type: Literal["code", "summary", "chunk-summary"]
|
|
95
|
+
files_filter: str | None = ""
|
|
96
|
+
embeddings_model: str | None = None
|
|
97
|
+
summarization_model: str | None = None
|
|
98
|
+
prompt: str | None = None
|
|
99
|
+
docs_generation: bool = False
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def from_entity(cls, request: CodeDataSourceRequest) -> "CodeDatasourceSpec":
|
|
103
|
+
return cls(
|
|
104
|
+
**_base_kwargs(request),
|
|
105
|
+
link=request.link,
|
|
106
|
+
branch=request.branch,
|
|
107
|
+
index_type=getattr(request.index_type, "value", request.index_type),
|
|
108
|
+
files_filter=request.files_filter,
|
|
109
|
+
embeddings_model=request.embeddings_model,
|
|
110
|
+
summarization_model=request.summarization_model,
|
|
111
|
+
prompt=request.prompt,
|
|
112
|
+
docs_generation=request.docs_generation,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class GitFaqDatasourceSpec(_DatasourceSpecBase):
|
|
117
|
+
"""Narrows ``GitFaqDataSourceRequest`` (type=``knowledge_base_git_faq``)."""
|
|
118
|
+
|
|
119
|
+
type: Literal["knowledge_base_git_faq"] = "knowledge_base_git_faq"
|
|
120
|
+
link: str | None = None
|
|
121
|
+
branch: str | None = None
|
|
122
|
+
files_filter: str | None = None
|
|
123
|
+
embedding_model: str | None = None
|
|
124
|
+
|
|
125
|
+
@classmethod
|
|
126
|
+
def from_entity(cls, request: GitFaqDataSourceRequest) -> "GitFaqDatasourceSpec":
|
|
127
|
+
return cls(
|
|
128
|
+
**_base_kwargs(request),
|
|
129
|
+
link=request.link,
|
|
130
|
+
branch=request.branch,
|
|
131
|
+
files_filter=request.files_filter,
|
|
132
|
+
embedding_model=request.embedding_model,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class JiraDatasourceSpec(_DatasourceSpecBase):
|
|
137
|
+
"""Narrows ``JiraDataSourceRequest`` (type=``knowledge_base_jira``)."""
|
|
138
|
+
|
|
139
|
+
type: Literal["knowledge_base_jira"] = "knowledge_base_jira"
|
|
140
|
+
jql: str | None = None
|
|
141
|
+
custom_fields: list[str] | None = None
|
|
142
|
+
|
|
143
|
+
@classmethod
|
|
144
|
+
def from_entity(cls, request: JiraDataSourceRequest) -> "JiraDatasourceSpec":
|
|
145
|
+
return cls(
|
|
146
|
+
**_base_kwargs(request),
|
|
147
|
+
jql=request.jql,
|
|
148
|
+
custom_fields=request.custom_fields,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class ConfluenceDatasourceSpec(_DatasourceSpecBase):
|
|
153
|
+
"""Narrows ``ConfluenceDataSourceRequest`` (type=``knowledge_base_confluence``)."""
|
|
154
|
+
|
|
155
|
+
type: Literal["knowledge_base_confluence"] = "knowledge_base_confluence"
|
|
156
|
+
cql: str | None = None
|
|
157
|
+
include_restricted_content: bool | None = None
|
|
158
|
+
include_archived_content: bool | None = None
|
|
159
|
+
include_attachments: bool | None = None
|
|
160
|
+
include_comments: bool | None = None
|
|
161
|
+
keep_markdown_format: bool | None = None
|
|
162
|
+
keep_newlines: bool | None = None
|
|
163
|
+
max_pages: int | None = None
|
|
164
|
+
pages_per_request: int | None = None
|
|
165
|
+
|
|
166
|
+
@classmethod
|
|
167
|
+
def from_entity(
|
|
168
|
+
cls, request: ConfluenceDataSourceRequest
|
|
169
|
+
) -> "ConfluenceDatasourceSpec":
|
|
170
|
+
return cls(
|
|
171
|
+
**_base_kwargs(request),
|
|
172
|
+
cql=request.cql,
|
|
173
|
+
include_restricted_content=request.include_restricted_content,
|
|
174
|
+
include_archived_content=request.include_archived_content,
|
|
175
|
+
include_attachments=request.include_attachments,
|
|
176
|
+
include_comments=request.include_comments,
|
|
177
|
+
keep_markdown_format=request.keep_markdown_format,
|
|
178
|
+
keep_newlines=request.keep_newlines,
|
|
179
|
+
max_pages=request.max_pages,
|
|
180
|
+
pages_per_request=request.pages_per_request,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class GoogleDatasourceSpec(_DatasourceSpecBase):
|
|
185
|
+
"""Narrows ``GoogleDataSourceRequest`` (type=``llm_routing_google``)."""
|
|
186
|
+
|
|
187
|
+
type: Literal["llm_routing_google"] = "llm_routing_google"
|
|
188
|
+
google_doc: str | None = None
|
|
189
|
+
|
|
190
|
+
@classmethod
|
|
191
|
+
def from_entity(cls, request: GoogleDataSourceRequest) -> "GoogleDatasourceSpec":
|
|
192
|
+
return cls(**_base_kwargs(request), google_doc=request.google_doc)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class FileDatasourceSpec(_DatasourceSpecBase):
|
|
196
|
+
"""Narrows ``FileDataSourceRequest`` (type=``knowledge_base_file``).
|
|
197
|
+
|
|
198
|
+
No extra fields beyond the base.
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
type: Literal["knowledge_base_file"] = "knowledge_base_file"
|
|
202
|
+
|
|
203
|
+
@classmethod
|
|
204
|
+
def from_entity(cls, request: FileDataSourceRequest) -> "FileDatasourceSpec":
|
|
205
|
+
return cls(**_base_kwargs(request))
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class AzureDevOpsWikiDatasourceSpec(_DatasourceSpecBase):
|
|
209
|
+
"""Narrows ``AzureDevOpsWikiDataSourceRequest`` (type=``knowledge_base_azure_devops_wiki``)."""
|
|
210
|
+
|
|
211
|
+
type: Literal["knowledge_base_azure_devops_wiki"] = (
|
|
212
|
+
"knowledge_base_azure_devops_wiki"
|
|
213
|
+
)
|
|
214
|
+
wiki_query: str | None = None
|
|
215
|
+
organization: str | None = None
|
|
216
|
+
project: str | None = None
|
|
217
|
+
wiki_name: str | None = None
|
|
218
|
+
|
|
219
|
+
@classmethod
|
|
220
|
+
def from_entity(
|
|
221
|
+
cls, request: AzureDevOpsWikiDataSourceRequest
|
|
222
|
+
) -> "AzureDevOpsWikiDatasourceSpec":
|
|
223
|
+
return cls(
|
|
224
|
+
**_base_kwargs(request),
|
|
225
|
+
wiki_query=request.wiki_query,
|
|
226
|
+
organization=request.organization,
|
|
227
|
+
project=request.project,
|
|
228
|
+
wiki_name=request.wiki_name,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
class AzureDevOpsWorkItemDatasourceSpec(_DatasourceSpecBase):
|
|
233
|
+
"""Narrows ``AzureDevOpsWorkItemDataSourceRequest`` (type=``knowledge_base_azure_devops_work_item``)."""
|
|
234
|
+
|
|
235
|
+
type: Literal["knowledge_base_azure_devops_work_item"] = (
|
|
236
|
+
"knowledge_base_azure_devops_work_item"
|
|
237
|
+
)
|
|
238
|
+
wiql_query: str | None = None
|
|
239
|
+
organization: str | None = None
|
|
240
|
+
project: str | None = None
|
|
241
|
+
|
|
242
|
+
@classmethod
|
|
243
|
+
def from_entity(
|
|
244
|
+
cls, request: AzureDevOpsWorkItemDataSourceRequest
|
|
245
|
+
) -> "AzureDevOpsWorkItemDatasourceSpec":
|
|
246
|
+
return cls(
|
|
247
|
+
**_base_kwargs(request),
|
|
248
|
+
wiql_query=request.wiql_query,
|
|
249
|
+
organization=request.organization,
|
|
250
|
+
project=request.project,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
class XWikiDatasourceSpec(_DatasourceSpecBase):
|
|
255
|
+
"""Narrows ``XWikiDataSourceRequest`` (type=``knowledge_base_xwiki``)."""
|
|
256
|
+
|
|
257
|
+
type: Literal["knowledge_base_xwiki"] = "knowledge_base_xwiki"
|
|
258
|
+
space: str | None = None
|
|
259
|
+
wiki: str | None = None
|
|
260
|
+
|
|
261
|
+
@classmethod
|
|
262
|
+
def from_entity(cls, request: XWikiDataSourceRequest) -> "XWikiDatasourceSpec":
|
|
263
|
+
return cls(**_base_kwargs(request), space=request.space, wiki=request.wiki)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
class SvnDatasourceSpec(_DatasourceSpecBase):
|
|
267
|
+
"""Narrows ``SvnDataSourceRequest`` (type=``svn``)."""
|
|
268
|
+
|
|
269
|
+
type: Literal["svn"] = "svn"
|
|
270
|
+
link: str = Field(..., min_length=1, max_length=1000)
|
|
271
|
+
branch: str | None = Field(None, min_length=1, max_length=1000)
|
|
272
|
+
index_type: Literal["code", "summary", "chunk-summary"] = "code"
|
|
273
|
+
files_filter: str | None = None
|
|
274
|
+
embeddings_model: str | None = None
|
|
275
|
+
prompt: str | None = None
|
|
276
|
+
docs_generation: bool | None = None
|
|
277
|
+
|
|
278
|
+
@classmethod
|
|
279
|
+
def from_entity(cls, request: SvnDataSourceRequest) -> "SvnDatasourceSpec":
|
|
280
|
+
return cls(
|
|
281
|
+
**_base_kwargs(request),
|
|
282
|
+
link=request.link,
|
|
283
|
+
branch=request.branch,
|
|
284
|
+
index_type=request.index_type.value,
|
|
285
|
+
files_filter=request.files_filter,
|
|
286
|
+
embeddings_model=request.embeddings_model,
|
|
287
|
+
prompt=request.prompt,
|
|
288
|
+
docs_generation=request.docs_generation,
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class SharepointDatasourceSpec(_DatasourceSpecBase):
|
|
293
|
+
"""Narrows ``SharePointDataSourceRequest`` (type=``knowledge_base_sharepoint``).
|
|
294
|
+
|
|
295
|
+
``access_token`` (needed by the ``oauth_*`` auth types, never stored by the
|
|
296
|
+
platform) narrows to a ``CredentialRef``: it is read from the environment
|
|
297
|
+
when writing and is not part of the live state. It is optional in the
|
|
298
|
+
document: an exported OAuth document carries none, and the SDK requires it
|
|
299
|
+
only on create and on an update that reindexes.
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
type: Literal["knowledge_base_sharepoint"] = "knowledge_base_sharepoint"
|
|
303
|
+
site_url: str = Field(..., pattern=r"^https://\S+$", max_length=1000)
|
|
304
|
+
include_pages: bool | None = None
|
|
305
|
+
include_documents: bool | None = None
|
|
306
|
+
include_lists: bool | None = None
|
|
307
|
+
max_file_size_mb: int | None = Field(None, ge=1, le=500)
|
|
308
|
+
files_filter: str | None = None
|
|
309
|
+
auth_type: Literal["integration", "oauth_codemie", "oauth_custom"] | None = None
|
|
310
|
+
oauth_client_id: str | None = None
|
|
311
|
+
oauth_tenant_id: str | None = None
|
|
312
|
+
access_token: CredentialRef | None = None
|
|
313
|
+
embedding_model: str | None = None
|
|
314
|
+
|
|
315
|
+
@field_validator("access_token", mode="before")
|
|
316
|
+
@classmethod
|
|
317
|
+
def _token_is_a_reference(cls, value: Any) -> Any:
|
|
318
|
+
# Checked here, not by ``CredentialRef``, whose error text echoes the value.
|
|
319
|
+
if isinstance(value, str) and not _is_env_reference(value):
|
|
320
|
+
raise ValueError("access_token must be an env: reference, not a literal")
|
|
321
|
+
return value
|
|
322
|
+
|
|
323
|
+
@classmethod
|
|
324
|
+
def from_entity(
|
|
325
|
+
cls, request: SharePointDataSourceRequest
|
|
326
|
+
) -> "SharepointDatasourceSpec":
|
|
327
|
+
return cls(
|
|
328
|
+
**_base_kwargs(request),
|
|
329
|
+
site_url=request.site_url,
|
|
330
|
+
include_pages=request.include_pages,
|
|
331
|
+
include_documents=request.include_documents,
|
|
332
|
+
include_lists=request.include_lists,
|
|
333
|
+
max_file_size_mb=request.max_file_size_mb,
|
|
334
|
+
files_filter=request.files_filter,
|
|
335
|
+
auth_type=request.auth_type,
|
|
336
|
+
oauth_client_id=request.oauth_client_id,
|
|
337
|
+
oauth_tenant_id=request.oauth_tenant_id,
|
|
338
|
+
access_token=(
|
|
339
|
+
CredentialRef.from_entity(request.name, "access_token")
|
|
340
|
+
if request.access_token
|
|
341
|
+
else None
|
|
342
|
+
),
|
|
343
|
+
embedding_model=request.embedding_model,
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
class XrayDatasourceSpec(_DatasourceSpecBase):
|
|
348
|
+
"""Narrows ``XrayDataSourceRequest`` (type=``knowledge_base_xray``)."""
|
|
349
|
+
|
|
350
|
+
type: Literal["knowledge_base_xray"] = "knowledge_base_xray"
|
|
351
|
+
jql: str = Field(..., min_length=1)
|
|
352
|
+
embedding_model: str | None = None
|
|
353
|
+
|
|
354
|
+
@classmethod
|
|
355
|
+
def from_entity(cls, request: XrayDataSourceRequest) -> "XrayDatasourceSpec":
|
|
356
|
+
return cls(
|
|
357
|
+
**_base_kwargs(request),
|
|
358
|
+
jql=request.jql,
|
|
359
|
+
embedding_model=request.embedding_model,
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
#: Document-level fields that must not be smuggled in through ``settings``.
|
|
364
|
+
RESERVED_PROVIDER_SETTINGS = frozenset(
|
|
365
|
+
{"name", "project_name", "setting_id", "description", "project_space_visible"}
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
# Name heuristic for secret-looking provider settings. Mirrors the backend
|
|
369
|
+
# exporter's ``iac_export/exporters/datasource/provider.py`` (RESERVED_PROVIDER_SETTINGS,
|
|
370
|
+
# _SECRET_TOKENS, _looks_secret): change both together; ``tests/test_specs_datasource.py``
|
|
371
|
+
# pins the shared vectors. Names are matched whole-token on purpose, so short
|
|
372
|
+
# words such as ``key`` or ``pass`` (``primary_key``, ``bypass``) are not flagged.
|
|
373
|
+
# Best effort and offline
|
|
374
|
+
# only: the platform provider schema, consulted at plan/apply before any write
|
|
375
|
+
# (``plan_apply.credentials``), is the authoritative gate and also catches
|
|
376
|
+
# secrets stored under names this list does not recognise.
|
|
377
|
+
_SECRET_TOKENS = frozenset(
|
|
378
|
+
{
|
|
379
|
+
"password",
|
|
380
|
+
"passwd",
|
|
381
|
+
"secret",
|
|
382
|
+
"token",
|
|
383
|
+
"apikey",
|
|
384
|
+
"credential",
|
|
385
|
+
"credentials",
|
|
386
|
+
"passphrase",
|
|
387
|
+
}
|
|
388
|
+
)
|
|
389
|
+
_SECRET_TOKEN_PAIRS = frozenset(
|
|
390
|
+
{
|
|
391
|
+
("api", "key"),
|
|
392
|
+
("private", "key"),
|
|
393
|
+
("access", "key"),
|
|
394
|
+
("secret", "key"),
|
|
395
|
+
("auth", "key"),
|
|
396
|
+
("client", "secret"),
|
|
397
|
+
}
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def _key_tokens(key: str) -> list[str]:
|
|
402
|
+
"""Lower-case tokens of ``key``, split on non-alphanumerics and camelCase."""
|
|
403
|
+
spaced = re.sub(r"([a-z0-9])([A-Z])", r"\1 \2", key)
|
|
404
|
+
spaced = re.sub(r"([A-Z]+)([A-Z][a-z])", r"\1 \2", spaced)
|
|
405
|
+
return [t.lower() for t in re.split(r"[^A-Za-z0-9]+", spaced) if t]
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def _looks_secret(key: Any) -> bool:
|
|
409
|
+
"""Whether the setting name looks like a secret (whole-token match)."""
|
|
410
|
+
tokens = _key_tokens(str(key))
|
|
411
|
+
return any(t in _SECRET_TOKENS for t in tokens) or any(
|
|
412
|
+
pair in _SECRET_TOKEN_PAIRS for pair in pairwise(tokens)
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def _is_env_reference(value: str) -> bool:
|
|
417
|
+
try:
|
|
418
|
+
CredentialRef(value)
|
|
419
|
+
except ValueError:
|
|
420
|
+
return False
|
|
421
|
+
return True
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def _malformed_reference_paths(value: Any, path: str) -> Iterator[str]:
|
|
425
|
+
"""Paths of string leaves that start with ``env:`` (any case, leading
|
|
426
|
+
blanks allowed) yet are not a valid reference."""
|
|
427
|
+
if isinstance(value, dict):
|
|
428
|
+
for key, item in value.items():
|
|
429
|
+
yield from _malformed_reference_paths(item, f"{path}.{key}")
|
|
430
|
+
elif isinstance(value, (list, tuple)):
|
|
431
|
+
for index, item in enumerate(value):
|
|
432
|
+
yield from _malformed_reference_paths(item, f"{path}[{index}]")
|
|
433
|
+
elif (
|
|
434
|
+
isinstance(value, str)
|
|
435
|
+
and value.lstrip().lower().startswith("env:")
|
|
436
|
+
and not _is_env_reference(value)
|
|
437
|
+
):
|
|
438
|
+
yield path
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
#: Names that hold a secret in an MCP ``auth_config``. Matched whole: the
|
|
442
|
+
#: backend's required fields (``token_url``, ``token_delivery``,
|
|
443
|
+
#: ``saml_credential_attribute``) hold no secret, which the name heuristic
|
|
444
|
+
#: above would flag.
|
|
445
|
+
AUTH_CONFIG_SECRET_KEYS = frozenset(
|
|
446
|
+
{
|
|
447
|
+
"client_secret",
|
|
448
|
+
"clientsecret",
|
|
449
|
+
"refresh_token",
|
|
450
|
+
"access_token",
|
|
451
|
+
"id_token",
|
|
452
|
+
"password",
|
|
453
|
+
"secret",
|
|
454
|
+
"token",
|
|
455
|
+
"api_key",
|
|
456
|
+
"apikey",
|
|
457
|
+
"private_key",
|
|
458
|
+
"sp_private_key",
|
|
459
|
+
}
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def _is_auth_config_secret(key: Any) -> bool:
|
|
464
|
+
return str(key).lower() in AUTH_CONFIG_SECRET_KEYS
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def _literal_secret_paths(
|
|
468
|
+
value: Any,
|
|
469
|
+
path: str,
|
|
470
|
+
under_secret: bool = False,
|
|
471
|
+
is_secret: Callable[[Any], bool] = _looks_secret,
|
|
472
|
+
) -> Iterator[str]:
|
|
473
|
+
"""Paths of non-empty, non-reference string leaves under a secret-named key
|
|
474
|
+
(``is_secret`` decides which names count)."""
|
|
475
|
+
if isinstance(value, dict):
|
|
476
|
+
for key, item in value.items():
|
|
477
|
+
yield from _literal_secret_paths(
|
|
478
|
+
item,
|
|
479
|
+
f"{path}.{key}",
|
|
480
|
+
under_secret or is_secret(key),
|
|
481
|
+
is_secret,
|
|
482
|
+
)
|
|
483
|
+
elif isinstance(value, (list, tuple)):
|
|
484
|
+
for index, item in enumerate(value):
|
|
485
|
+
yield from _literal_secret_paths(
|
|
486
|
+
item, f"{path}[{index}]", under_secret, is_secret
|
|
487
|
+
)
|
|
488
|
+
elif (
|
|
489
|
+
under_secret
|
|
490
|
+
and isinstance(value, str)
|
|
491
|
+
and value
|
|
492
|
+
and not _is_env_reference(value)
|
|
493
|
+
):
|
|
494
|
+
yield path
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
class ProviderDatasourceSpec(_DatasourceSpecBase):
|
|
498
|
+
"""Narrows ``ProviderDataSourceRequest`` (type=``provider``).
|
|
499
|
+
|
|
500
|
+
``settings`` is free-form; which entries are secret is decided by the
|
|
501
|
+
platform provider schema (see ``plan_apply.credentials``).
|
|
502
|
+
"""
|
|
503
|
+
|
|
504
|
+
type: Literal["provider"] = "provider"
|
|
505
|
+
provider_name: str
|
|
506
|
+
toolkit_id: str
|
|
507
|
+
settings: dict[str, Any] = {}
|
|
508
|
+
|
|
509
|
+
# Keeps pydantic from echoing ``settings`` (and any literal secret in it)
|
|
510
|
+
# in validation error text.
|
|
511
|
+
model_config = ConfigDict(extra="forbid", hide_input_in_errors=True)
|
|
512
|
+
|
|
513
|
+
@field_validator("settings")
|
|
514
|
+
@classmethod
|
|
515
|
+
def _no_reserved_settings(cls, value: dict[str, Any]) -> dict[str, Any]:
|
|
516
|
+
clash = sorted(set(value) & RESERVED_PROVIDER_SETTINGS)
|
|
517
|
+
if clash:
|
|
518
|
+
raise ValueError(
|
|
519
|
+
f"settings must not contain reserved document keys: {', '.join(clash)}"
|
|
520
|
+
)
|
|
521
|
+
return value
|
|
522
|
+
|
|
523
|
+
@model_validator(mode="after")
|
|
524
|
+
def _no_setting_id(self) -> "ProviderDatasourceSpec":
|
|
525
|
+
if self.setting_id is not None:
|
|
526
|
+
raise ValueError(
|
|
527
|
+
f"datasource {self.name!r}: setting_id is not supported for "
|
|
528
|
+
"provider datasources; the platform does not store it"
|
|
529
|
+
)
|
|
530
|
+
return self
|
|
531
|
+
|
|
532
|
+
@model_validator(mode="after")
|
|
533
|
+
def _no_schedule(self) -> "ProviderDatasourceSpec":
|
|
534
|
+
if self.cron_expression is not None or self.timezone is not None:
|
|
535
|
+
raise ValueError(
|
|
536
|
+
f"datasource {self.name!r}: cron_expression and timezone are not "
|
|
537
|
+
"supported for provider datasources; the platform takes no schedule"
|
|
538
|
+
)
|
|
539
|
+
return self
|
|
540
|
+
|
|
541
|
+
@model_validator(mode="after")
|
|
542
|
+
def _no_malformed_references(self) -> "ProviderDatasourceSpec":
|
|
543
|
+
paths = list(_malformed_reference_paths(self.settings, "settings"))
|
|
544
|
+
if paths:
|
|
545
|
+
raise ValueError(
|
|
546
|
+
f"datasource {self.name!r}: {', '.join(paths)} starts with 'env:' "
|
|
547
|
+
"but is not a valid reference (env:NAME, letters, digits and "
|
|
548
|
+
"underscores only); the platform would receive it as literal text"
|
|
549
|
+
)
|
|
550
|
+
return self
|
|
551
|
+
|
|
552
|
+
@model_validator(mode="after")
|
|
553
|
+
def _no_literal_secret_settings(self) -> "ProviderDatasourceSpec":
|
|
554
|
+
paths = list(_literal_secret_paths(self.settings, "settings"))
|
|
555
|
+
if paths:
|
|
556
|
+
raise ValueError(
|
|
557
|
+
f"datasource {self.name!r}: secret-looking setting(s) "
|
|
558
|
+
f"{', '.join(paths)} must be env: references, not literal values"
|
|
559
|
+
)
|
|
560
|
+
return self
|
|
561
|
+
|
|
562
|
+
@classmethod
|
|
563
|
+
def from_entity(
|
|
564
|
+
cls,
|
|
565
|
+
request: ProviderDataSourceRequest,
|
|
566
|
+
) -> "ProviderDatasourceSpec":
|
|
567
|
+
return cls(
|
|
568
|
+
name=request.name,
|
|
569
|
+
project_name=request.project_name,
|
|
570
|
+
description=request.description,
|
|
571
|
+
shared_with_project=request.project_space_visible,
|
|
572
|
+
provider_name=request.provider_name,
|
|
573
|
+
toolkit_id=request.toolkit_id,
|
|
574
|
+
settings=dict(request.settings),
|
|
575
|
+
)
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
DatasourceSpec = Annotated[
|
|
579
|
+
Union[
|
|
580
|
+
CodeDatasourceSpec,
|
|
581
|
+
GitFaqDatasourceSpec,
|
|
582
|
+
JiraDatasourceSpec,
|
|
583
|
+
ConfluenceDatasourceSpec,
|
|
584
|
+
GoogleDatasourceSpec,
|
|
585
|
+
FileDatasourceSpec,
|
|
586
|
+
AzureDevOpsWikiDatasourceSpec,
|
|
587
|
+
AzureDevOpsWorkItemDatasourceSpec,
|
|
588
|
+
XWikiDatasourceSpec,
|
|
589
|
+
SvnDatasourceSpec,
|
|
590
|
+
SharepointDatasourceSpec,
|
|
591
|
+
XrayDatasourceSpec,
|
|
592
|
+
ProviderDatasourceSpec,
|
|
593
|
+
],
|
|
594
|
+
Field(discriminator="type"),
|
|
595
|
+
]
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
"""Spec that narrows ``codemie_sdk.models.integration.Integration`` for IaC documents.
|
|
16
|
+
|
|
17
|
+
Drops the platform-assigned fields (``id``, ``date``, ``update_date``,
|
|
18
|
+
``user_id``) and replaces ``credential_values`` with a list of
|
|
19
|
+
``CredentialRefEntry`` so no secret value can ever be embedded in a document.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
23
|
+
|
|
24
|
+
from codemie_sdk.models.integration import CredentialTypes, Integration, IntegrationType
|
|
25
|
+
|
|
26
|
+
from ..credentials import CredentialRef
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CredentialRefEntry(BaseModel):
|
|
30
|
+
"""A single credential field, pointing at a secret by reference only."""
|
|
31
|
+
|
|
32
|
+
model_config = ConfigDict(extra="forbid")
|
|
33
|
+
|
|
34
|
+
key: str
|
|
35
|
+
ref: CredentialRef
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class IntegrationSpec(BaseModel):
|
|
39
|
+
"""Narrowed, secret-free view of ``Integration``."""
|
|
40
|
+
|
|
41
|
+
model_config = ConfigDict(extra="forbid")
|
|
42
|
+
|
|
43
|
+
project_name: str | None = None
|
|
44
|
+
alias: str | None = None
|
|
45
|
+
default: bool = False
|
|
46
|
+
is_global: bool | None = False
|
|
47
|
+
credential_type: CredentialTypes
|
|
48
|
+
credential_values: list[CredentialRefEntry]
|
|
49
|
+
setting_type: IntegrationType = Field(default=IntegrationType.USER)
|
|
50
|
+
|
|
51
|
+
@model_validator(mode="after")
|
|
52
|
+
def _check_unique_credential_keys(self) -> "IntegrationSpec":
|
|
53
|
+
"""Reject duplicate ``key`` values across ``credential_values`` (CR-010).
|
|
54
|
+
|
|
55
|
+
Without this, two entries with the same ``key`` but different
|
|
56
|
+
``ref``s are accepted silently, leaving which ``CredentialRefEntry``
|
|
57
|
+
a downstream consumer resolves for that key ambiguous.
|
|
58
|
+
"""
|
|
59
|
+
keys = [entry.key for entry in self.credential_values]
|
|
60
|
+
seen: set[str] = set()
|
|
61
|
+
duplicates = {key for key in keys if key in seen or seen.add(key)}
|
|
62
|
+
if duplicates:
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f"credential_values has duplicate key(s): {sorted(duplicates)!r}"
|
|
65
|
+
)
|
|
66
|
+
return self
|
|
67
|
+
|
|
68
|
+
@classmethod
|
|
69
|
+
def from_entity(cls, integration: Integration) -> "IntegrationSpec":
|
|
70
|
+
"""Narrow a live ``Integration``, never reading any credential value.
|
|
71
|
+
|
|
72
|
+
Uses ``integration.alias`` as the identifier fed to
|
|
73
|
+
``CredentialRef.from_entity`` for every credential key. An
|
|
74
|
+
alias-less integration with credentials to narrow is rejected
|
|
75
|
+
(CR-006) rather than falling back to a shared literal: two
|
|
76
|
+
different alias-less integrations would otherwise collide onto the
|
|
77
|
+
identical ``CredentialRef``, silently pointing two real secrets at
|
|
78
|
+
the same environment variable. An alias-less integration with no
|
|
79
|
+
credentials to narrow has no identifier to collide over, so it is
|
|
80
|
+
left alone.
|
|
81
|
+
"""
|
|
82
|
+
if integration.alias is None and integration.credential_values:
|
|
83
|
+
raise ValueError(
|
|
84
|
+
"IntegrationSpec.from_entity requires an alias to derive "
|
|
85
|
+
"CredentialRefs for a non-empty credential_values; got "
|
|
86
|
+
"alias=None"
|
|
87
|
+
)
|
|
88
|
+
identifier = integration.alias or "integration"
|
|
89
|
+
return cls(
|
|
90
|
+
project_name=integration.project_name,
|
|
91
|
+
alias=integration.alias,
|
|
92
|
+
default=integration.default,
|
|
93
|
+
is_global=integration.is_global,
|
|
94
|
+
credential_type=integration.credential_type,
|
|
95
|
+
credential_values=[
|
|
96
|
+
CredentialRefEntry(
|
|
97
|
+
key=cred.key,
|
|
98
|
+
ref=CredentialRef.from_entity(identifier, cred.key),
|
|
99
|
+
)
|
|
100
|
+
for cred in integration.credential_values
|
|
101
|
+
],
|
|
102
|
+
setting_type=integration.setting_type,
|
|
103
|
+
)
|