diff --git a/backend/infrahub/generators/tasks.py b/backend/infrahub/generators/tasks.py index ea269cc760..7cf0de738b 100644 --- a/backend/infrahub/generators/tasks.py +++ b/backend/infrahub/generators/tasks.py @@ -7,10 +7,12 @@ from prefect import flow, task from infrahub import lock -from infrahub.core.constants import GeneratorInstanceStatus +from infrahub.core.constants import GeneratorInstanceStatus, InfrahubKind from infrahub.generators.models import RequestGeneratorRun from infrahub.git.base import extract_repo_file_information from infrahub.git.repository import get_initialized_repo +from infrahub.message_bus import messages +from infrahub.message_bus.types import ProposedChangeGeneratorDefinition from infrahub.services import InfrahubServices, services @@ -103,3 +105,34 @@ async def _define_instance(model: RequestGeneratorRun, service: InfrahubServices ) await instance.save() return instance + + +@flow(name="generator-definition-run") +async def run(branch: str) -> None: + service = services.service + generators = await service.client.filters( + kind=InfrahubKind.GENERATORDEFINITION, prefetch_relationships=True, populate_store=True, branch=branch + ) + + generator_definitions = [ + ProposedChangeGeneratorDefinition( + definition_id=generator.id, + definition_name=generator.name.value, + class_name=generator.class_name.value, + file_path=generator.file_path.value, + query_name=generator.query.peer.name.value, + query_models=generator.query.peer.models.value, + repository_id=generator.repository.peer.id, + parameters=generator.parameters.value, + group_id=generator.targets.peer.id, + convert_query_response=generator.convert_query_response.value, + ) + for generator in generators + ] + + events = [ + messages.RequestGeneratorDefinitionRun(branch=branch, generator_definition=generator_definition) + for generator_definition in generator_definitions + ] + for event in events: + await service.send(message=event) diff --git a/backend/infrahub/message_bus/messages/__init__.py b/backend/infrahub/message_bus/messages/__init__.py index 7c4c9159e6..5bcd5524d0 100644 --- a/backend/infrahub/message_bus/messages/__init__.py +++ b/backend/infrahub/message_bus/messages/__init__.py @@ -41,7 +41,6 @@ from .schema_migration_path import SchemaMigrationPath, SchemaMigrationPathResponse from .schema_validator_path import SchemaValidatorPath, SchemaValidatorPathResponse from .send_echo_request import SendEchoRequest, SendEchoRequestResponse -from .trigger_generatordefinition_run import TriggerGeneratorDefinitionRun from .trigger_proposed_change_cancel import TriggerProposedChangeCancel from .trigger_webhook_actions import TriggerWebhookActions @@ -87,7 +86,6 @@ "request.repository.checks": RequestRepositoryChecks, "request.repository.user_checks": RequestRepositoryUserChecks, "send.echo.request": SendEchoRequest, - "trigger.generator_definition.run": TriggerGeneratorDefinitionRun, "trigger.proposed_change.cancel": TriggerProposedChangeCancel, "trigger.webhook.actions": TriggerWebhookActions, } diff --git a/backend/infrahub/message_bus/operations/__init__.py b/backend/infrahub/message_bus/operations/__init__.py index 28fefe17e9..ae6e0066be 100644 --- a/backend/infrahub/message_bus/operations/__init__.py +++ b/backend/infrahub/message_bus/operations/__init__.py @@ -61,7 +61,6 @@ "send.echo.request": send.echo.request, "schema.migration.path": schema.migration.path, "schema.validator.path": schema.validator.path, - "trigger.generator_definition.run": trigger.generator_definition.run, "trigger.proposed_change.cancel": trigger.proposed_change.cancel, "trigger.webhook.actions": trigger.webhook.actions, } diff --git a/backend/infrahub/message_bus/operations/event/branch.py b/backend/infrahub/message_bus/operations/event/branch.py index 976c9d70b0..9fb0535806 100644 --- a/backend/infrahub/message_bus/operations/event/branch.py +++ b/backend/infrahub/message_bus/operations/event/branch.py @@ -15,6 +15,7 @@ REQUEST_DIFF_REFRESH, REQUEST_DIFF_UPDATE, TRIGGER_ARTIFACT_DEFINITION_GENERATE, + TRIGGER_GENERATOR_DEFINITION_RUN, ) log = get_logger() @@ -56,7 +57,6 @@ async def merge(message: messages.EventBranchMerge, service: InfrahubServices) - events: List[InfrahubMessage] = [ messages.RefreshRegistryBranches(), - messages.TriggerGeneratorDefinitionRun(branch=message.target_branch), ] component_registry = get_component_registry() default_branch = registry.get_branch_from_registry() @@ -69,6 +69,11 @@ async def merge(message: messages.EventBranchMerge, service: InfrahubServices) - parameters={"branch": message.target_branch}, ) + await service.workflow.submit_workflow( + workflow=TRIGGER_GENERATOR_DEFINITION_RUN, + parameters={"branch": message.target_branch}, + ) + for diff_root in branch_diff_roots: if ( diff_root.base_branch_name != diff_root.diff_branch_name diff --git a/backend/infrahub/message_bus/operations/trigger/__init__.py b/backend/infrahub/message_bus/operations/trigger/__init__.py index f9c9de4ead..98ec7acc4a 100644 --- a/backend/infrahub/message_bus/operations/trigger/__init__.py +++ b/backend/infrahub/message_bus/operations/trigger/__init__.py @@ -1,3 +1,3 @@ -from . import generator_definition, proposed_change, webhook +from . import proposed_change, webhook -__all__ = ["generator_definition", "proposed_change", "webhook"] +__all__ = ["proposed_change", "webhook"] diff --git a/backend/infrahub/message_bus/operations/trigger/generator_definition.py b/backend/infrahub/message_bus/operations/trigger/generator_definition.py deleted file mode 100644 index b9044806ab..0000000000 --- a/backend/infrahub/message_bus/operations/trigger/generator_definition.py +++ /dev/null @@ -1,37 +0,0 @@ -from prefect import flow - -from infrahub.core.constants import InfrahubKind -from infrahub.message_bus import messages -from infrahub.message_bus.types import ProposedChangeGeneratorDefinition -from infrahub.services import InfrahubServices - - -@flow(name="generator-definition-run") -async def run(message: messages.TriggerGeneratorDefinitionRun, service: InfrahubServices) -> None: - generators = await service.client.filters( - kind=InfrahubKind.GENERATORDEFINITION, prefetch_relationships=True, populate_store=True, branch=message.branch - ) - - generator_definitions = [ - ProposedChangeGeneratorDefinition( - definition_id=generator.id, - definition_name=generator.name.value, - class_name=generator.class_name.value, - file_path=generator.file_path.value, - query_name=generator.query.peer.name.value, - query_models=generator.query.peer.models.value, - repository_id=generator.repository.peer.id, - parameters=generator.parameters.value, - group_id=generator.targets.peer.id, - convert_query_response=generator.convert_query_response.value, - ) - for generator in generators - ] - - events = [ - messages.RequestGeneratorDefinitionRun(branch=message.branch, generator_definition=generator_definition) - for generator_definition in generator_definitions - ] - for event in events: - event.assign_meta(parent=message) - await service.send(message=event) diff --git a/backend/infrahub/workflows/catalogue.py b/backend/infrahub/workflows/catalogue.py index 856f89a5f4..84449f05ec 100644 --- a/backend/infrahub/workflows/catalogue.py +++ b/backend/infrahub/workflows/catalogue.py @@ -62,6 +62,13 @@ function="generate_artifact_definition", ) +TRIGGER_GENERATOR_DEFINITION_RUN = WorkflowDefinition( + name="generator-definition-run", + type=WorkflowType.INTERNAL, + module="infrahub.git.tasks", + function="run_generator_definition", +) + IPAM_RECONCILIATION = WorkflowDefinition( name="ipam_reconciliation", type=WorkflowType.INTERNAL, @@ -160,4 +167,5 @@ REQUEST_GENERATOR_RUN, REQUEST_DIFF_UPDATE, REQUEST_DIFF_REFRESH, + TRIGGER_GENERATOR_DEFINITION_RUN, ] diff --git a/backend/tests/unit/message_bus/operations/event/test_branch.py b/backend/tests/unit/message_bus/operations/event/test_branch.py index 7644008caa..c0282094be 100644 --- a/backend/tests/unit/message_bus/operations/event/test_branch.py +++ b/backend/tests/unit/message_bus/operations/event/test_branch.py @@ -13,7 +13,12 @@ from infrahub.message_bus.operations.event.branch import delete, merge, rebased from infrahub.services import InfrahubServices, services from infrahub.services.adapters.workflow.local import WorkflowLocalExecution -from infrahub.workflows.catalogue import REQUEST_DIFF_REFRESH, REQUEST_DIFF_UPDATE, TRIGGER_ARTIFACT_DEFINITION_GENERATE +from infrahub.workflows.catalogue import ( + REQUEST_DIFF_REFRESH, + REQUEST_DIFF_UPDATE, + TRIGGER_ARTIFACT_DEFINITION_GENERATE, + TRIGGER_GENERATOR_DEFINITION_RUN, +) from tests.adapters.message_bus import BusRecorder @@ -101,6 +106,10 @@ async def test_merged(default_branch: Branch, init_service: InfrahubServices, pr expected_calls = [ call(workflow=TRIGGER_ARTIFACT_DEFINITION_GENERATE, parameters={"branch": message.target_branch}), + call( + workflow=TRIGGER_GENERATOR_DEFINITION_RUN, + parameters={"branch": target_branch_name}, + ), call( workflow=REQUEST_DIFF_UPDATE, parameters={"model": RequestDiffUpdate(branch_name=tracked_diff_roots[0].diff_branch_name)}, @@ -118,9 +127,8 @@ async def test_merged(default_branch: Branch, init_service: InfrahubServices, pr ) diff_repo.get_empty_roots.assert_awaited_once_with(base_branch_names=[target_branch_name]) - assert len(service.message_bus.messages) == 2 + assert len(service.message_bus.messages) == 1 assert service.message_bus.messages[0] == messages.RefreshRegistryBranches() - assert service.message_bus.messages[1] == messages.TriggerGeneratorDefinitionRun(branch=target_branch_name) async def test_rebased(default_branch: Branch, prefect_test_fixture): diff --git a/changelog/+permissions.added.md b/changelog/+permissions.added.md index 435a7b9e64..124353d260 100644 --- a/changelog/+permissions.added.md +++ b/changelog/+permissions.added.md @@ -1,4 +1,5 @@ New permissions system in UI: + - Implemented CRUD views for managing accounts, groups, roles, and permissions - Updated all components to support new permission system - Added dynamic message display according to user access levels diff --git a/changelog/new-layout.added.md b/changelog/new-layout.added.md index 831bb09de2..55c2558068 100644 --- a/changelog/new-layout.added.md +++ b/changelog/new-layout.added.md @@ -1,4 +1,5 @@ Reworked branch selector: + - Redesigned the UI - Added filter for branch - Improved accessibility & keyboard navigation diff --git a/docs/docs/reference/message-bus-events.mdx b/docs/docs/reference/message-bus-events.mdx index 41cf8bd9ca..808656693a 100644 --- a/docs/docs/reference/message-bus-events.mdx +++ b/docs/docs/reference/message-bus-events.mdx @@ -858,25 +858,6 @@ For more detailed explanations on how to use these events within Infrahub, see t - -### Trigger Generator Definition - - - -#### Event trigger.generator_definition.run - - -**Description**: Triggers all Generators to run on the desired branch. - -**Priority**: 3 - - -| Key | Description | Type | Default Value | -|-----|-------------|------|---------------| -| **meta** | Meta properties for the message | N/A | None | -| **branch** | The branch to run the Generators in | string | None | - - ### Trigger Proposed Change @@ -1806,26 +1787,6 @@ For more detailed explanations on how to use these events within Infrahub, see t - -### Trigger Generator Definition - - - -#### Event trigger.generator_definition.run - - -**Description**: Triggers all Generators to run on the desired branch. - -**Priority**: 3 - - - -| Key | Description | Type | Default Value | -|-----|-------------|------|---------------| -| **meta** | Meta properties for the message | N/A | None | -| **branch** | The branch to run the Generators in | string | None | - - ### Trigger Proposed Change