infrahub-server 1.3.5__py3-none-any.whl → 1.4.0b0__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.
- infrahub/api/internal.py +5 -0
- infrahub/artifacts/tasks.py +17 -22
- infrahub/branch/merge_mutation_checker.py +38 -0
- infrahub/cli/__init__.py +2 -2
- infrahub/cli/context.py +7 -3
- infrahub/cli/db.py +5 -16
- infrahub/cli/upgrade.py +7 -29
- infrahub/computed_attribute/tasks.py +36 -46
- infrahub/config.py +53 -2
- infrahub/constants/environment.py +1 -0
- infrahub/core/attribute.py +9 -7
- infrahub/core/branch/tasks.py +43 -41
- infrahub/core/constants/__init__.py +20 -6
- infrahub/core/constants/infrahubkind.py +2 -0
- infrahub/core/diff/coordinator.py +3 -1
- infrahub/core/diff/repository/repository.py +0 -8
- infrahub/core/diff/tasks.py +11 -8
- infrahub/core/graph/__init__.py +1 -1
- infrahub/core/graph/index.py +1 -2
- infrahub/core/graph/schema.py +50 -29
- infrahub/core/initialization.py +62 -33
- infrahub/core/ipam/tasks.py +4 -3
- infrahub/core/merge.py +8 -10
- infrahub/core/migrations/graph/__init__.py +2 -0
- infrahub/core/migrations/graph/m035_drop_attr_value_index.py +45 -0
- infrahub/core/migrations/query/attribute_add.py +27 -2
- infrahub/core/migrations/schema/tasks.py +6 -5
- infrahub/core/node/proposed_change.py +43 -0
- infrahub/core/protocols.py +12 -0
- infrahub/core/query/attribute.py +32 -14
- infrahub/core/query/diff.py +11 -0
- infrahub/core/query/ipam.py +13 -7
- infrahub/core/query/node.py +51 -10
- infrahub/core/query/resource_manager.py +3 -3
- infrahub/core/schema/basenode_schema.py +8 -0
- infrahub/core/schema/definitions/core/__init__.py +10 -1
- infrahub/core/schema/definitions/core/ipam.py +28 -2
- infrahub/core/schema/definitions/core/propose_change.py +15 -0
- infrahub/core/schema/definitions/core/webhook.py +3 -0
- infrahub/core/schema/generic_schema.py +10 -0
- infrahub/core/schema/manager.py +10 -1
- infrahub/core/schema/node_schema.py +22 -17
- infrahub/core/schema/profile_schema.py +8 -0
- infrahub/core/schema/schema_branch.py +9 -5
- infrahub/core/schema/template_schema.py +8 -0
- infrahub/core/validators/checks_runner.py +5 -5
- infrahub/core/validators/tasks.py +6 -7
- infrahub/core/validators/uniqueness/checker.py +4 -2
- infrahub/core/validators/uniqueness/model.py +1 -0
- infrahub/core/validators/uniqueness/query.py +57 -7
- infrahub/database/__init__.py +2 -1
- infrahub/events/__init__.py +18 -0
- infrahub/events/constants.py +7 -0
- infrahub/events/generator.py +29 -2
- infrahub/events/proposed_change_action.py +181 -0
- infrahub/generators/tasks.py +24 -20
- infrahub/git/base.py +4 -7
- infrahub/git/integrator.py +21 -12
- infrahub/git/repository.py +15 -30
- infrahub/git/tasks.py +121 -106
- infrahub/graphql/field_extractor.py +69 -0
- infrahub/graphql/manager.py +15 -11
- infrahub/graphql/mutations/account.py +2 -2
- infrahub/graphql/mutations/action.py +8 -2
- infrahub/graphql/mutations/artifact_definition.py +4 -1
- infrahub/graphql/mutations/branch.py +10 -5
- infrahub/graphql/mutations/graphql_query.py +2 -1
- infrahub/graphql/mutations/main.py +14 -8
- infrahub/graphql/mutations/menu.py +2 -1
- infrahub/graphql/mutations/proposed_change.py +225 -8
- infrahub/graphql/mutations/relationship.py +5 -0
- infrahub/graphql/mutations/repository.py +2 -1
- infrahub/graphql/mutations/tasks.py +7 -9
- infrahub/graphql/mutations/webhook.py +4 -1
- infrahub/graphql/parser.py +15 -6
- infrahub/graphql/queries/__init__.py +10 -1
- infrahub/graphql/queries/account.py +3 -3
- infrahub/graphql/queries/branch.py +2 -2
- infrahub/graphql/queries/diff/tree.py +3 -3
- infrahub/graphql/queries/event.py +13 -3
- infrahub/graphql/queries/ipam.py +23 -1
- infrahub/graphql/queries/proposed_change.py +84 -0
- infrahub/graphql/queries/relationship.py +2 -2
- infrahub/graphql/queries/resource_manager.py +3 -3
- infrahub/graphql/queries/search.py +3 -2
- infrahub/graphql/queries/status.py +3 -2
- infrahub/graphql/queries/task.py +2 -2
- infrahub/graphql/resolvers/ipam.py +440 -0
- infrahub/graphql/resolvers/many_relationship.py +4 -3
- infrahub/graphql/resolvers/resolver.py +5 -5
- infrahub/graphql/resolvers/single_relationship.py +3 -2
- infrahub/graphql/schema.py +25 -5
- infrahub/graphql/types/__init__.py +2 -2
- infrahub/graphql/types/attribute.py +3 -3
- infrahub/graphql/types/event.py +60 -0
- infrahub/groups/tasks.py +6 -6
- infrahub/lock.py +3 -2
- infrahub/menu/generator.py +8 -0
- infrahub/message_bus/operations/__init__.py +9 -12
- infrahub/message_bus/operations/git/file.py +6 -5
- infrahub/message_bus/operations/git/repository.py +12 -20
- infrahub/message_bus/operations/refresh/registry.py +15 -9
- infrahub/message_bus/operations/send/echo.py +7 -4
- infrahub/message_bus/types.py +1 -0
- infrahub/permissions/globals.py +1 -4
- infrahub/permissions/manager.py +8 -5
- infrahub/pools/prefix.py +7 -5
- infrahub/prefect_server/app.py +31 -0
- infrahub/prefect_server/bootstrap.py +18 -0
- infrahub/proposed_change/action_checker.py +206 -0
- infrahub/proposed_change/approval_revoker.py +40 -0
- infrahub/proposed_change/branch_diff.py +3 -1
- infrahub/proposed_change/checker.py +45 -0
- infrahub/proposed_change/constants.py +32 -2
- infrahub/proposed_change/tasks.py +182 -150
- infrahub/py.typed +0 -0
- infrahub/server.py +29 -17
- infrahub/services/__init__.py +13 -28
- infrahub/services/adapters/cache/__init__.py +4 -0
- infrahub/services/adapters/cache/nats.py +2 -0
- infrahub/services/adapters/cache/redis.py +3 -0
- infrahub/services/adapters/message_bus/__init__.py +0 -2
- infrahub/services/adapters/message_bus/local.py +1 -2
- infrahub/services/adapters/message_bus/nats.py +6 -8
- infrahub/services/adapters/message_bus/rabbitmq.py +7 -9
- infrahub/services/adapters/workflow/__init__.py +1 -0
- infrahub/services/adapters/workflow/local.py +1 -8
- infrahub/services/component.py +2 -1
- infrahub/task_manager/event.py +52 -0
- infrahub/task_manager/models.py +9 -0
- infrahub/tasks/artifact.py +6 -7
- infrahub/tasks/check.py +4 -7
- infrahub/telemetry/tasks.py +15 -18
- infrahub/transformations/tasks.py +10 -6
- infrahub/trigger/tasks.py +4 -3
- infrahub/types.py +4 -0
- infrahub/validators/events.py +7 -7
- infrahub/validators/tasks.py +6 -7
- infrahub/webhook/models.py +45 -45
- infrahub/webhook/tasks.py +25 -24
- infrahub/workers/dependencies.py +143 -0
- infrahub/workers/infrahub_async.py +19 -43
- infrahub/workflows/catalogue.py +16 -2
- infrahub/workflows/initialization.py +5 -4
- infrahub/workflows/models.py +2 -0
- infrahub_sdk/client.py +6 -6
- infrahub_sdk/ctl/repository.py +51 -0
- infrahub_sdk/ctl/schema.py +9 -9
- infrahub_sdk/protocols.py +40 -6
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/METADATA +5 -4
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/RECORD +158 -144
- infrahub_testcontainers/container.py +17 -0
- infrahub_testcontainers/docker-compose-cluster.test.yml +56 -1
- infrahub_testcontainers/docker-compose.test.yml +56 -1
- infrahub_testcontainers/helpers.py +4 -1
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/WHEEL +0 -0
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/entry_points.txt +0 -0
infrahub/git/tasks.py
CHANGED
|
@@ -15,17 +15,18 @@ from prefect.logging import get_run_logger
|
|
|
15
15
|
from infrahub import lock
|
|
16
16
|
from infrahub.context import InfrahubContext
|
|
17
17
|
from infrahub.core.constants import InfrahubKind, RepositoryInternalStatus, ValidatorConclusion
|
|
18
|
+
from infrahub.core.manager import NodeManager
|
|
18
19
|
from infrahub.core.registry import registry
|
|
19
20
|
from infrahub.exceptions import CheckError, RepositoryError
|
|
20
21
|
from infrahub.message_bus import Meta, messages
|
|
21
|
-
from infrahub.services import
|
|
22
|
+
from infrahub.services.adapters.message_bus import InfrahubMessageBus
|
|
22
23
|
from infrahub.validators.tasks import start_validator
|
|
23
24
|
from infrahub.worker import WORKER_IDENTITY
|
|
25
|
+
from infrahub.workers.dependencies import get_client, get_database, get_event_service, get_message_bus, get_workflow
|
|
24
26
|
|
|
25
|
-
from ..core.manager import NodeManager
|
|
26
27
|
from ..core.timestamp import Timestamp
|
|
27
28
|
from ..core.validators.checks_runner import run_checks_and_update_validator
|
|
28
|
-
from ..log import get_log_data
|
|
29
|
+
from ..log import get_log_data, get_logger
|
|
29
30
|
from ..tasks.artifact import define_artifact
|
|
30
31
|
from ..workflows.catalogue import (
|
|
31
32
|
GIT_REPOSITORY_MERGE_CONFLICTS_CHECKS_RUN,
|
|
@@ -58,7 +59,7 @@ from .repository import InfrahubReadOnlyRepository, InfrahubRepository, get_init
|
|
|
58
59
|
name="git-repository-add-read-write",
|
|
59
60
|
flow_run_name="Adding repository {model.repository_name} in branch {model.infrahub_branch_name}",
|
|
60
61
|
)
|
|
61
|
-
async def add_git_repository(model: GitRepositoryAdd
|
|
62
|
+
async def add_git_repository(model: GitRepositoryAdd) -> None:
|
|
62
63
|
await add_tags(branches=[model.infrahub_branch_name], nodes=[model.repository_id])
|
|
63
64
|
|
|
64
65
|
async with lock.registry.get(name=model.repository_name, namespace="repository"):
|
|
@@ -66,11 +67,10 @@ async def add_git_repository(model: GitRepositoryAdd, service: InfrahubServices)
|
|
|
66
67
|
id=model.repository_id,
|
|
67
68
|
name=model.repository_name,
|
|
68
69
|
location=model.location,
|
|
69
|
-
client=
|
|
70
|
+
client=get_client(),
|
|
70
71
|
infrahub_branch_name=model.infrahub_branch_name,
|
|
71
72
|
internal_status=model.internal_status,
|
|
72
73
|
default_branch_name=model.default_branch_name,
|
|
73
|
-
service=service,
|
|
74
74
|
)
|
|
75
75
|
await repo.import_objects_from_files( # type: ignore[call-overload]
|
|
76
76
|
infrahub_branch_name=model.infrahub_branch_name, git_branch_name=model.default_branch_name
|
|
@@ -88,14 +88,15 @@ async def add_git_repository(model: GitRepositoryAdd, service: InfrahubServices)
|
|
|
88
88
|
infrahub_branch_name=model.infrahub_branch_name,
|
|
89
89
|
infrahub_branch_id=model.infrahub_branch_id,
|
|
90
90
|
)
|
|
91
|
-
await
|
|
91
|
+
message_bus = await get_message_bus()
|
|
92
|
+
await message_bus.send(message=notification)
|
|
92
93
|
|
|
93
94
|
|
|
94
95
|
@flow(
|
|
95
96
|
name="git-repository-add-read-only",
|
|
96
97
|
flow_run_name="Adding read only repository {model.repository_name} in branch {model.infrahub_branch_name}",
|
|
97
98
|
)
|
|
98
|
-
async def add_git_repository_read_only(model: GitRepositoryAddReadOnly
|
|
99
|
+
async def add_git_repository_read_only(model: GitRepositoryAddReadOnly) -> None:
|
|
99
100
|
await add_tags(branches=[model.infrahub_branch_name], nodes=[model.repository_id])
|
|
100
101
|
|
|
101
102
|
async with lock.registry.get(name=model.repository_name, namespace="repository"):
|
|
@@ -103,10 +104,9 @@ async def add_git_repository_read_only(model: GitRepositoryAddReadOnly, service:
|
|
|
103
104
|
id=model.repository_id,
|
|
104
105
|
name=model.repository_name,
|
|
105
106
|
location=model.location,
|
|
106
|
-
client=
|
|
107
|
+
client=get_client(),
|
|
107
108
|
ref=model.ref,
|
|
108
109
|
infrahub_branch_name=model.infrahub_branch_name,
|
|
109
|
-
service=service,
|
|
110
110
|
)
|
|
111
111
|
await repo.import_objects_from_files(infrahub_branch_name=model.infrahub_branch_name) # type: ignore[call-overload]
|
|
112
112
|
if model.internal_status == RepositoryInternalStatus.ACTIVE.value:
|
|
@@ -122,25 +122,29 @@ async def add_git_repository_read_only(model: GitRepositoryAddReadOnly, service:
|
|
|
122
122
|
infrahub_branch_name=model.infrahub_branch_name,
|
|
123
123
|
infrahub_branch_id=model.infrahub_branch_id,
|
|
124
124
|
)
|
|
125
|
-
await
|
|
125
|
+
message_bus = await get_message_bus()
|
|
126
|
+
await message_bus.send(message=notification)
|
|
126
127
|
|
|
127
128
|
|
|
128
129
|
@flow(name="git-repositories-create-branch", flow_run_name="Create branch '{branch}' in Git Repositories")
|
|
129
|
-
async def create_branch(branch: str, branch_id: str
|
|
130
|
+
async def create_branch(branch: str, branch_id: str) -> None:
|
|
130
131
|
"""Request to the creation of git branches in available repositories."""
|
|
131
132
|
await add_tags(branches=[branch])
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
|
|
134
|
+
client = get_client()
|
|
135
|
+
|
|
136
|
+
repositories: list[CoreRepository] = await client.filters(kind=CoreRepository)
|
|
137
|
+
batch = await client.create_batch()
|
|
134
138
|
for repository in repositories:
|
|
135
139
|
batch.add(
|
|
136
140
|
task=git_branch_create,
|
|
137
|
-
client=
|
|
141
|
+
client=client,
|
|
138
142
|
branch=branch,
|
|
139
143
|
branch_id=branch_id,
|
|
140
144
|
repository_name=repository.name.value,
|
|
141
145
|
repository_id=repository.id,
|
|
142
146
|
repository_location=repository.location.value,
|
|
143
|
-
|
|
147
|
+
message_bus=await get_message_bus(),
|
|
144
148
|
)
|
|
145
149
|
|
|
146
150
|
async for _, _ in batch.execute():
|
|
@@ -148,11 +152,13 @@ async def create_branch(branch: str, branch_id: str, service: InfrahubServices)
|
|
|
148
152
|
|
|
149
153
|
|
|
150
154
|
@flow(name="git_repositories_sync", flow_run_name="Sync Git Repositories")
|
|
151
|
-
async def sync_remote_repositories(
|
|
155
|
+
async def sync_remote_repositories() -> None:
|
|
152
156
|
log = get_run_logger()
|
|
153
157
|
|
|
154
|
-
|
|
155
|
-
|
|
158
|
+
client = get_client()
|
|
159
|
+
|
|
160
|
+
branches = await client.branch.all()
|
|
161
|
+
repositories = await client.get_list_repositories(branches=branches, kind=InfrahubKind.REPOSITORY)
|
|
156
162
|
|
|
157
163
|
for repo_name, repository_data in repositories.items():
|
|
158
164
|
active_internal_status = RepositoryInternalStatus.ACTIVE.value
|
|
@@ -168,26 +174,24 @@ async def sync_remote_repositories(service: InfrahubServices) -> None:
|
|
|
168
174
|
init_failed = False
|
|
169
175
|
try:
|
|
170
176
|
repo = await InfrahubRepository.init(
|
|
171
|
-
service=service,
|
|
172
177
|
id=repository_data.repository.id,
|
|
173
178
|
name=repository_data.repository.name.value,
|
|
174
179
|
location=repository_data.repository.location.value,
|
|
175
|
-
client=
|
|
180
|
+
client=client,
|
|
176
181
|
internal_status=active_internal_status,
|
|
177
182
|
default_branch_name=repository_data.repository.default_branch.value,
|
|
178
183
|
)
|
|
179
184
|
except RepositoryError as exc:
|
|
180
|
-
|
|
185
|
+
get_logger().error(str(exc))
|
|
181
186
|
init_failed = True
|
|
182
187
|
|
|
183
188
|
if init_failed:
|
|
184
189
|
try:
|
|
185
190
|
repo = await InfrahubRepository.new(
|
|
186
|
-
service=service,
|
|
187
191
|
id=repository_data.repository.id,
|
|
188
192
|
name=repository_data.repository.name.value,
|
|
189
193
|
location=repository_data.repository.location.value,
|
|
190
|
-
client=
|
|
194
|
+
client=client,
|
|
191
195
|
internal_status=active_internal_status,
|
|
192
196
|
default_branch_name=repository_data.repository.default_branch.value,
|
|
193
197
|
)
|
|
@@ -210,7 +214,8 @@ async def sync_remote_repositories(service: InfrahubServices) -> None:
|
|
|
210
214
|
infrahub_branch_name=infrahub_branch,
|
|
211
215
|
infrahub_branch_id=branches[infrahub_branch].id,
|
|
212
216
|
)
|
|
213
|
-
await
|
|
217
|
+
message_bus = await get_message_bus()
|
|
218
|
+
await message_bus.send(message=message)
|
|
214
219
|
except RepositoryError as exc:
|
|
215
220
|
log.info(exc.message)
|
|
216
221
|
|
|
@@ -227,11 +232,11 @@ async def git_branch_create(
|
|
|
227
232
|
repository_id: str,
|
|
228
233
|
repository_name: str,
|
|
229
234
|
repository_location: str,
|
|
230
|
-
|
|
235
|
+
message_bus: InfrahubMessageBus,
|
|
231
236
|
) -> None:
|
|
232
237
|
log = get_run_logger()
|
|
233
238
|
repo = await InfrahubRepository.init(
|
|
234
|
-
id=repository_id, name=repository_name, location=repository_location, client=client
|
|
239
|
+
id=repository_id, name=repository_name, location=repository_location, client=client
|
|
235
240
|
)
|
|
236
241
|
|
|
237
242
|
async with lock.registry.get(name=repository_name, namespace="repository"):
|
|
@@ -247,15 +252,15 @@ async def git_branch_create(
|
|
|
247
252
|
infrahub_branch_name=branch,
|
|
248
253
|
infrahub_branch_id=branch_id,
|
|
249
254
|
)
|
|
250
|
-
await
|
|
255
|
+
await message_bus.send(message=message)
|
|
251
256
|
log.debug("Sent message to all workers to fetch the latest version of the repository (RefreshGitFetch)")
|
|
252
257
|
|
|
253
258
|
|
|
254
259
|
@flow(name="artifact-definition-generate", flow_run_name="Generate all artifacts")
|
|
255
|
-
async def generate_artifact_definition(branch: str, context: InfrahubContext
|
|
260
|
+
async def generate_artifact_definition(branch: str, context: InfrahubContext) -> None:
|
|
256
261
|
await add_branch_tag(branch_name=branch)
|
|
257
262
|
|
|
258
|
-
artifact_definitions = await
|
|
263
|
+
artifact_definitions = await get_client().all(kind=CoreArtifactDefinition, branch=branch, include=["id"])
|
|
259
264
|
|
|
260
265
|
for artifact_definition in artifact_definitions:
|
|
261
266
|
model = RequestArtifactDefinitionGenerate(
|
|
@@ -263,24 +268,24 @@ async def generate_artifact_definition(branch: str, context: InfrahubContext, se
|
|
|
263
268
|
artifact_definition_id=artifact_definition.id,
|
|
264
269
|
artifact_definition_name=artifact_definition.name.value,
|
|
265
270
|
)
|
|
266
|
-
await
|
|
271
|
+
await get_workflow().submit_workflow(
|
|
267
272
|
workflow=REQUEST_ARTIFACT_DEFINITION_GENERATE, context=context, parameters={"model": model}
|
|
268
273
|
)
|
|
269
274
|
|
|
270
275
|
|
|
271
276
|
@flow(name="artifact-generate", flow_run_name="Generate artifact {model.artifact_name}")
|
|
272
|
-
async def generate_artifact(model: RequestArtifactGenerate
|
|
277
|
+
async def generate_artifact(model: RequestArtifactGenerate) -> None:
|
|
273
278
|
await add_tags(branches=[model.branch_name], nodes=[model.target_id])
|
|
274
279
|
log = get_run_logger()
|
|
275
280
|
repo = await get_initialized_repo(
|
|
281
|
+
client=get_client(),
|
|
276
282
|
repository_id=model.repository_id,
|
|
277
283
|
name=model.repository_name,
|
|
278
|
-
service=service,
|
|
279
284
|
repository_kind=model.repository_kind,
|
|
280
285
|
commit=model.commit,
|
|
281
286
|
)
|
|
282
287
|
|
|
283
|
-
artifact, artifact_created = await define_artifact(model=model
|
|
288
|
+
artifact, artifact_created = await define_artifact(model=model)
|
|
284
289
|
|
|
285
290
|
try:
|
|
286
291
|
result = await repo.render_artifact(artifact=artifact, artifact_created=artifact_created, message=model)
|
|
@@ -299,11 +304,13 @@ async def generate_artifact(model: RequestArtifactGenerate, service: InfrahubSer
|
|
|
299
304
|
flow_run_name="Trigger Generation of Artifacts for {model.artifact_definition_name}",
|
|
300
305
|
)
|
|
301
306
|
async def generate_request_artifact_definition(
|
|
302
|
-
model: RequestArtifactDefinitionGenerate, context: InfrahubContext
|
|
307
|
+
model: RequestArtifactDefinitionGenerate, context: InfrahubContext
|
|
303
308
|
) -> None:
|
|
304
309
|
await add_tags(branches=[model.branch])
|
|
305
310
|
|
|
306
|
-
|
|
311
|
+
client = get_client()
|
|
312
|
+
|
|
313
|
+
artifact_definition = await client.get(
|
|
307
314
|
kind=CoreArtifactDefinition, id=model.artifact_definition_id, branch=model.branch
|
|
308
315
|
)
|
|
309
316
|
|
|
@@ -312,7 +319,7 @@ async def generate_request_artifact_definition(
|
|
|
312
319
|
await group.members.fetch()
|
|
313
320
|
current_members = [member.id for member in group.members.peers]
|
|
314
321
|
|
|
315
|
-
existing_artifacts = await
|
|
322
|
+
existing_artifacts = await client.filters(
|
|
316
323
|
kind=CoreArtifact,
|
|
317
324
|
definition__ids=[model.artifact_definition_id],
|
|
318
325
|
include=["object"],
|
|
@@ -332,9 +339,9 @@ async def generate_request_artifact_definition(
|
|
|
332
339
|
await transform.query.fetch()
|
|
333
340
|
query = transform.query.peer
|
|
334
341
|
repository = transformation_repository.peer
|
|
335
|
-
branch = await
|
|
342
|
+
branch = await client.branch.get(branch_name=model.branch)
|
|
336
343
|
if branch.sync_with_git:
|
|
337
|
-
repository = await
|
|
344
|
+
repository = await client.get(
|
|
338
345
|
kind=InfrahubKind.GENERICREPOSITORY, id=repository.id, branch=model.branch, fragment=True
|
|
339
346
|
)
|
|
340
347
|
transform_location = ""
|
|
@@ -374,13 +381,13 @@ async def generate_request_artifact_definition(
|
|
|
374
381
|
context=context,
|
|
375
382
|
)
|
|
376
383
|
|
|
377
|
-
await
|
|
384
|
+
await get_workflow().submit_workflow(
|
|
378
385
|
workflow=REQUEST_ARTIFACT_GENERATE, context=context, parameters={"model": request_artifact_generate_model}
|
|
379
386
|
)
|
|
380
387
|
|
|
381
388
|
|
|
382
389
|
@flow(name="git-repository-pull-read-only", flow_run_name="Pull latest commit on {model.repository_name}")
|
|
383
|
-
async def pull_read_only(model: GitRepositoryPullReadOnly
|
|
390
|
+
async def pull_read_only(model: GitRepositoryPullReadOnly) -> None:
|
|
384
391
|
await add_tags(branches=[model.infrahub_branch_name], nodes=[model.repository_id])
|
|
385
392
|
log = get_run_logger()
|
|
386
393
|
|
|
@@ -394,10 +401,9 @@ async def pull_read_only(model: GitRepositoryPullReadOnly, service: InfrahubServ
|
|
|
394
401
|
id=model.repository_id,
|
|
395
402
|
name=model.repository_name,
|
|
396
403
|
location=model.location,
|
|
397
|
-
client=
|
|
404
|
+
client=get_client(),
|
|
398
405
|
ref=model.ref,
|
|
399
406
|
infrahub_branch_name=model.infrahub_branch_name,
|
|
400
|
-
service=service,
|
|
401
407
|
)
|
|
402
408
|
except RepositoryError:
|
|
403
409
|
init_failed = True
|
|
@@ -407,10 +413,9 @@ async def pull_read_only(model: GitRepositoryPullReadOnly, service: InfrahubServ
|
|
|
407
413
|
id=model.repository_id,
|
|
408
414
|
name=model.repository_name,
|
|
409
415
|
location=model.location,
|
|
410
|
-
client=
|
|
416
|
+
client=get_client(),
|
|
411
417
|
ref=model.ref,
|
|
412
418
|
infrahub_branch_name=model.infrahub_branch_name,
|
|
413
|
-
service=service,
|
|
414
419
|
)
|
|
415
420
|
|
|
416
421
|
await repo.import_objects_from_files(infrahub_branch_name=model.infrahub_branch_name, commit=model.commit) # type: ignore[call-overload]
|
|
@@ -426,29 +431,28 @@ async def pull_read_only(model: GitRepositoryPullReadOnly, service: InfrahubServ
|
|
|
426
431
|
infrahub_branch_name=model.infrahub_branch_name,
|
|
427
432
|
infrahub_branch_id=model.infrahub_branch_id,
|
|
428
433
|
)
|
|
429
|
-
await
|
|
434
|
+
message_bus = await get_message_bus()
|
|
435
|
+
await message_bus.send(message=message)
|
|
430
436
|
|
|
431
437
|
|
|
432
438
|
@flow(
|
|
433
439
|
name="git-repository-merge",
|
|
434
440
|
flow_run_name="Merge {model.source_branch} > {model.destination_branch} in git repository",
|
|
435
441
|
)
|
|
436
|
-
async def merge_git_repository(model: GitRepositoryMerge
|
|
442
|
+
async def merge_git_repository(model: GitRepositoryMerge) -> None:
|
|
437
443
|
await add_tags(branches=[model.source_branch, model.destination_branch], nodes=[model.repository_id])
|
|
438
444
|
|
|
445
|
+
client = get_client()
|
|
446
|
+
|
|
439
447
|
repo = await InfrahubRepository.init(
|
|
440
|
-
id=model.repository_id,
|
|
441
|
-
name=model.repository_name,
|
|
442
|
-
client=service.client,
|
|
443
|
-
default_branch_name=model.default_branch,
|
|
444
|
-
service=service,
|
|
448
|
+
id=model.repository_id, name=model.repository_name, client=client, default_branch_name=model.default_branch
|
|
445
449
|
)
|
|
446
450
|
|
|
447
451
|
if model.internal_status == RepositoryInternalStatus.STAGING.value:
|
|
448
|
-
repo_source = await
|
|
452
|
+
repo_source = await client.get(
|
|
449
453
|
kind=InfrahubKind.GENERICREPOSITORY, id=model.repository_id, branch=model.source_branch
|
|
450
454
|
)
|
|
451
|
-
repo_main = await
|
|
455
|
+
repo_main = await client.get(kind=InfrahubKind.GENERICREPOSITORY, id=model.repository_id)
|
|
452
456
|
repo_main.internal_status.value = RepositoryInternalStatus.ACTIVE.value
|
|
453
457
|
repo_main.sync_status.value = repo_source.sync_status.value
|
|
454
458
|
|
|
@@ -470,16 +474,20 @@ async def merge_git_repository(model: GitRepositoryMerge, service: InfrahubServi
|
|
|
470
474
|
infrahub_branch_name=model.destination_branch,
|
|
471
475
|
infrahub_branch_id=model.destination_branch_id,
|
|
472
476
|
)
|
|
473
|
-
await
|
|
477
|
+
message_bus = await get_message_bus()
|
|
478
|
+
await message_bus.send(message=message)
|
|
474
479
|
|
|
475
480
|
|
|
476
481
|
@flow(name="git-repository-import-object", flow_run_name="Import objects from git repository")
|
|
477
|
-
async def import_objects_from_git_repository(model: GitRepositoryImportObjects
|
|
482
|
+
async def import_objects_from_git_repository(model: GitRepositoryImportObjects) -> None:
|
|
478
483
|
await add_branch_tag(model.infrahub_branch_name)
|
|
484
|
+
|
|
485
|
+
client = get_client()
|
|
486
|
+
|
|
479
487
|
repo = await get_initialized_repo(
|
|
488
|
+
client=client,
|
|
480
489
|
repository_id=model.repository_id,
|
|
481
490
|
name=model.repository_name,
|
|
482
|
-
service=service,
|
|
483
491
|
repository_kind=model.repository_kind,
|
|
484
492
|
commit=model.commit,
|
|
485
493
|
)
|
|
@@ -491,13 +499,11 @@ async def import_objects_from_git_repository(model: GitRepositoryImportObjects,
|
|
|
491
499
|
flow_run_name="Collecting modifications between commits {model.first_commit} and {model.second_commit}",
|
|
492
500
|
persist_result=True,
|
|
493
501
|
)
|
|
494
|
-
async def git_repository_diff_names_only(
|
|
495
|
-
model: GitDiffNamesOnly, service: InfrahubServices
|
|
496
|
-
) -> GitDiffNamesOnlyResponse:
|
|
502
|
+
async def git_repository_diff_names_only(model: GitDiffNamesOnly) -> GitDiffNamesOnlyResponse:
|
|
497
503
|
repo = await get_initialized_repo(
|
|
504
|
+
client=get_client(),
|
|
498
505
|
repository_id=model.repository_id,
|
|
499
506
|
name=model.repository_name,
|
|
500
|
-
service=service,
|
|
501
507
|
repository_kind=model.repository_kind,
|
|
502
508
|
)
|
|
503
509
|
files_changed: list[str] = []
|
|
@@ -520,16 +526,14 @@ async def git_repository_diff_names_only(
|
|
|
520
526
|
name="git-repository-user-checks-definition-trigger",
|
|
521
527
|
flow_run_name="Trigger user defined checks for repository {model.repository_name}",
|
|
522
528
|
)
|
|
523
|
-
async def trigger_repository_user_checks_definitions(
|
|
524
|
-
model: UserCheckDefinitionData, context: InfrahubContext, service: InfrahubServices
|
|
525
|
-
) -> None:
|
|
529
|
+
async def trigger_repository_user_checks_definitions(model: UserCheckDefinitionData, context: InfrahubContext) -> None:
|
|
526
530
|
await add_tags(branches=[model.branch_name], nodes=[model.proposed_change])
|
|
531
|
+
|
|
527
532
|
log = get_run_logger()
|
|
533
|
+
client = get_client()
|
|
528
534
|
|
|
529
|
-
definition = await
|
|
530
|
-
|
|
531
|
-
)
|
|
532
|
-
proposed_change = await service.client.get(kind=InfrahubKind.PROPOSEDCHANGE, id=model.proposed_change)
|
|
535
|
+
definition = await client.get(kind=CoreCheckDefinition, id=model.check_definition_id, branch=model.branch_name)
|
|
536
|
+
proposed_change = await client.get(kind=InfrahubKind.PROPOSEDCHANGE, id=model.proposed_change)
|
|
533
537
|
validator_execution_id = str(UUIDT())
|
|
534
538
|
check_execution_ids: list[str] = []
|
|
535
539
|
await proposed_change.validations.fetch()
|
|
@@ -544,10 +548,10 @@ async def trigger_repository_user_checks_definitions(
|
|
|
544
548
|
and existing_validator.check_definition.id == model.check_definition_id
|
|
545
549
|
):
|
|
546
550
|
previous_validator = existing_validator
|
|
547
|
-
|
|
551
|
+
get_logger().info("Found the same validator", validator=previous_validator)
|
|
548
552
|
|
|
549
553
|
validator = await start_validator(
|
|
550
|
-
|
|
554
|
+
client=client,
|
|
551
555
|
validator=previous_validator,
|
|
552
556
|
validator_type=CoreUserValidator,
|
|
553
557
|
proposed_change=model.proposed_change,
|
|
@@ -613,18 +617,20 @@ async def trigger_repository_user_checks_definitions(
|
|
|
613
617
|
checks_in_execution = ",".join(check_execution_ids)
|
|
614
618
|
log.info(f"Checks in execution {checks_in_execution}")
|
|
615
619
|
|
|
620
|
+
workflow = get_workflow()
|
|
616
621
|
checks_coroutines = [
|
|
617
|
-
|
|
622
|
+
workflow.execute_workflow(
|
|
618
623
|
workflow=GIT_REPOSITORY_USER_CHECK_RUN, parameters={"model": model}, expected_return=ValidatorConclusion
|
|
619
624
|
)
|
|
620
625
|
for model in check_models
|
|
621
626
|
]
|
|
622
627
|
|
|
628
|
+
event_service = await get_event_service()
|
|
623
629
|
await run_checks_and_update_validator(
|
|
630
|
+
event_service=event_service,
|
|
624
631
|
checks=checks_coroutines,
|
|
625
632
|
validator=validator,
|
|
626
633
|
context=context,
|
|
627
|
-
service=service,
|
|
628
634
|
proposed_change_id=model.proposed_change,
|
|
629
635
|
)
|
|
630
636
|
|
|
@@ -633,19 +639,19 @@ async def trigger_repository_user_checks_definitions(
|
|
|
633
639
|
name="git-repository-trigger-user-checks",
|
|
634
640
|
flow_run_name="Evaluating user-defined checks on repository {model.repository_name}",
|
|
635
641
|
)
|
|
636
|
-
async def trigger_user_checks(
|
|
637
|
-
model: TriggerRepositoryUserChecks, service: InfrahubServices, context: InfrahubContext
|
|
638
|
-
) -> None:
|
|
642
|
+
async def trigger_user_checks(model: TriggerRepositoryUserChecks, context: InfrahubContext) -> None:
|
|
639
643
|
"""Request to start validation checks on a specific repository for User-defined checks."""
|
|
640
|
-
|
|
641
644
|
await add_tags(branches=[model.source_branch], nodes=[model.proposed_change])
|
|
645
|
+
|
|
642
646
|
log = get_run_logger()
|
|
647
|
+
client = get_client()
|
|
643
648
|
|
|
644
|
-
repository = await
|
|
649
|
+
repository = await client.get(
|
|
645
650
|
kind=InfrahubKind.GENERICREPOSITORY, id=model.repository_id, branch=model.source_branch, fragment=True
|
|
646
651
|
)
|
|
647
652
|
await repository.checks.fetch()
|
|
648
653
|
|
|
654
|
+
workflow = get_workflow()
|
|
649
655
|
for relationship in repository.checks.peers:
|
|
650
656
|
log.info("Adding check for user defined check")
|
|
651
657
|
check_definition = relationship.peer
|
|
@@ -660,7 +666,7 @@ async def trigger_user_checks(
|
|
|
660
666
|
proposed_change=model.proposed_change,
|
|
661
667
|
branch_diff=model.branch_diff,
|
|
662
668
|
)
|
|
663
|
-
await
|
|
669
|
+
await workflow.submit_workflow(
|
|
664
670
|
workflow=GIT_REPOSITORY_USER_CHECKS_DEFINITIONS_TRIGGER,
|
|
665
671
|
context=context,
|
|
666
672
|
parameters={"model": user_check_definition_model},
|
|
@@ -671,17 +677,15 @@ async def trigger_user_checks(
|
|
|
671
677
|
name="git-repository-trigger-internal-checks",
|
|
672
678
|
flow_run_name="Running repository checks for repository {model.repository}",
|
|
673
679
|
)
|
|
674
|
-
async def trigger_internal_checks(
|
|
675
|
-
model: TriggerRepositoryInternalChecks, service: InfrahubServices, context: InfrahubContext
|
|
676
|
-
) -> None:
|
|
680
|
+
async def trigger_internal_checks(model: TriggerRepositoryInternalChecks, context: InfrahubContext) -> None:
|
|
677
681
|
"""Request to start validation checks on a specific repository."""
|
|
678
682
|
await add_tags(branches=[model.source_branch], nodes=[model.proposed_change])
|
|
683
|
+
|
|
679
684
|
log = get_run_logger()
|
|
685
|
+
client = get_client()
|
|
680
686
|
|
|
681
|
-
repository = await
|
|
682
|
-
|
|
683
|
-
)
|
|
684
|
-
proposed_change = await service.client.get(kind=InfrahubKind.PROPOSEDCHANGE, id=model.proposed_change)
|
|
687
|
+
repository = await client.get(kind=InfrahubKind.GENERICREPOSITORY, id=model.repository, branch=model.source_branch)
|
|
688
|
+
proposed_change = await client.get(kind=InfrahubKind.PROPOSEDCHANGE, id=model.proposed_change)
|
|
685
689
|
|
|
686
690
|
validator_execution_id = str(UUIDT())
|
|
687
691
|
check_execution_ids: list[str] = []
|
|
@@ -701,14 +705,11 @@ async def trigger_internal_checks(
|
|
|
701
705
|
previous_validator = existing_validator
|
|
702
706
|
|
|
703
707
|
validator = await start_validator(
|
|
704
|
-
|
|
708
|
+
client=client,
|
|
705
709
|
validator=previous_validator,
|
|
706
710
|
validator_type=CoreRepositoryValidator,
|
|
707
711
|
proposed_change=model.proposed_change,
|
|
708
|
-
data={
|
|
709
|
-
"label": validator_name,
|
|
710
|
-
"repository": model.repository,
|
|
711
|
-
},
|
|
712
|
+
data={"label": validator_name, "repository": model.repository},
|
|
712
713
|
context=context,
|
|
713
714
|
)
|
|
714
715
|
|
|
@@ -728,17 +729,19 @@ async def trigger_internal_checks(
|
|
|
728
729
|
source_branch=model.source_branch,
|
|
729
730
|
target_branch=model.target_branch,
|
|
730
731
|
)
|
|
731
|
-
|
|
732
|
+
|
|
733
|
+
check_coroutine = get_workflow().execute_workflow(
|
|
732
734
|
workflow=GIT_REPOSITORY_MERGE_CONFLICTS_CHECKS_RUN,
|
|
733
735
|
parameters={"model": check_merge_conflict_model},
|
|
734
736
|
expected_return=ValidatorConclusion,
|
|
735
737
|
)
|
|
736
738
|
|
|
739
|
+
event_service = await get_event_service()
|
|
737
740
|
await run_checks_and_update_validator(
|
|
741
|
+
event_service=event_service,
|
|
738
742
|
checks=[check_coroutine],
|
|
739
743
|
validator=validator,
|
|
740
744
|
context=context,
|
|
741
|
-
service=service,
|
|
742
745
|
proposed_change_id=model.proposed_change,
|
|
743
746
|
)
|
|
744
747
|
|
|
@@ -747,17 +750,22 @@ async def trigger_internal_checks(
|
|
|
747
750
|
name="git-repository-check-merge-conflict",
|
|
748
751
|
flow_run_name="Check for merge conflicts between {model.source_branch} and {model.target_branch}",
|
|
749
752
|
)
|
|
750
|
-
async def run_check_merge_conflicts(
|
|
751
|
-
model: CheckRepositoryMergeConflicts, service: InfrahubServices
|
|
752
|
-
) -> ValidatorConclusion:
|
|
753
|
+
async def run_check_merge_conflicts(model: CheckRepositoryMergeConflicts) -> ValidatorConclusion:
|
|
753
754
|
"""Runs a check to see if there are merge conflicts between two branches."""
|
|
754
755
|
await add_tags(branches=[model.source_branch], nodes=[model.proposed_change])
|
|
755
756
|
|
|
757
|
+
client = get_client()
|
|
758
|
+
|
|
756
759
|
success_condition = "-"
|
|
757
|
-
validator = await
|
|
760
|
+
validator = await client.get(kind=InfrahubKind.REPOSITORYVALIDATOR, id=model.validator_id)
|
|
758
761
|
await validator.checks.fetch()
|
|
759
762
|
|
|
760
|
-
repo = await
|
|
763
|
+
repo = await get_initialized_repo(
|
|
764
|
+
client=client,
|
|
765
|
+
repository_id=model.repository_id,
|
|
766
|
+
name=model.repository_name,
|
|
767
|
+
repository_kind=InfrahubKind.REPOSITORY,
|
|
768
|
+
)
|
|
761
769
|
async with lock.registry.get(name=model.repository_name, namespace="repository"):
|
|
762
770
|
conflicts = await repo.get_conflicts(source_branch=model.source_branch, dest_branch=model.target_branch)
|
|
763
771
|
|
|
@@ -780,7 +788,7 @@ async def run_check_merge_conflicts(
|
|
|
780
788
|
await existing_checks[conflict_key].save()
|
|
781
789
|
existing_checks.pop(conflict_key)
|
|
782
790
|
else:
|
|
783
|
-
check = await
|
|
791
|
+
check = await client.create(
|
|
784
792
|
kind=InfrahubKind.FILECHECK,
|
|
785
793
|
data={
|
|
786
794
|
"name": conflict,
|
|
@@ -803,7 +811,7 @@ async def run_check_merge_conflicts(
|
|
|
803
811
|
|
|
804
812
|
else:
|
|
805
813
|
validator_conclusion = ValidatorConclusion.SUCCESS
|
|
806
|
-
check = await
|
|
814
|
+
check = await client.create(
|
|
807
815
|
kind=InfrahubKind.FILECHECK,
|
|
808
816
|
data={
|
|
809
817
|
"name": "Merge Conflict Check",
|
|
@@ -817,22 +825,29 @@ async def run_check_merge_conflicts(
|
|
|
817
825
|
)
|
|
818
826
|
await check.save()
|
|
819
827
|
|
|
820
|
-
|
|
828
|
+
database = await get_database()
|
|
829
|
+
async with database.start_session() as db:
|
|
821
830
|
await NodeManager.delete(db=db, nodes=list(existing_checks.values()))
|
|
822
831
|
|
|
823
832
|
return validator_conclusion
|
|
824
833
|
|
|
825
834
|
|
|
826
835
|
@flow(name="git-repository-run-user-check", flow_run_name="Execute user defined Check '{model.name}'")
|
|
827
|
-
async def run_user_check(model: UserCheckData
|
|
836
|
+
async def run_user_check(model: UserCheckData) -> ValidatorConclusion:
|
|
828
837
|
await add_tags(branches=[model.branch_name], nodes=[model.proposed_change])
|
|
838
|
+
|
|
829
839
|
log = get_run_logger()
|
|
840
|
+
client = get_client()
|
|
830
841
|
|
|
831
|
-
validator = await
|
|
842
|
+
validator = await client.get(kind=InfrahubKind.USERVALIDATOR, id=model.validator_id)
|
|
832
843
|
await validator.checks.fetch()
|
|
833
844
|
|
|
834
|
-
repo = await
|
|
835
|
-
|
|
845
|
+
repo = await get_initialized_repo(
|
|
846
|
+
client=client,
|
|
847
|
+
repository_id=model.repository_id,
|
|
848
|
+
name=model.repository_name,
|
|
849
|
+
repository_kind=InfrahubKind.REPOSITORY,
|
|
850
|
+
commit=model.commit,
|
|
836
851
|
)
|
|
837
852
|
conclusion = ValidatorConclusion.FAILURE
|
|
838
853
|
severity = "critical"
|
|
@@ -841,7 +856,7 @@ async def run_user_check(model: UserCheckData, service: InfrahubServices) -> Val
|
|
|
841
856
|
branch_name=model.branch_name,
|
|
842
857
|
location=model.file_path,
|
|
843
858
|
class_name=model.class_name,
|
|
844
|
-
client=
|
|
859
|
+
client=client,
|
|
845
860
|
commit=model.commit,
|
|
846
861
|
params=model.variables,
|
|
847
862
|
) # type: ignore[misc]
|
|
@@ -876,7 +891,7 @@ async def run_user_check(model: UserCheckData, service: InfrahubServices) -> Val
|
|
|
876
891
|
check.severity.value = severity
|
|
877
892
|
await check.save()
|
|
878
893
|
else:
|
|
879
|
-
check = await
|
|
894
|
+
check = await client.create(
|
|
880
895
|
kind=InfrahubKind.STANDARDCHECK,
|
|
881
896
|
data={
|
|
882
897
|
"name": model.name,
|