infrahub-server 1.1.6__py3-none-any.whl → 1.2.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.
- infrahub/api/artifact.py +16 -4
- infrahub/api/dependencies.py +8 -0
- infrahub/api/oauth2.py +0 -1
- infrahub/api/oidc.py +0 -1
- infrahub/api/query.py +18 -7
- infrahub/api/schema.py +32 -6
- infrahub/api/transformation.py +12 -5
- infrahub/{message_bus/messages/check_artifact_create.py → artifacts/models.py} +2 -4
- infrahub/{message_bus/operations/check/artifact.py → artifacts/tasks.py} +26 -25
- infrahub/cli/__init__.py +0 -2
- infrahub/cli/db.py +6 -7
- infrahub/cli/events.py +8 -3
- infrahub/cli/git_agent.py +9 -7
- infrahub/cli/tasks.py +4 -6
- infrahub/computed_attribute/tasks.py +63 -17
- infrahub/computed_attribute/triggers.py +90 -0
- infrahub/config.py +1 -1
- infrahub/context.py +39 -0
- infrahub/core/account.py +5 -8
- infrahub/core/attribute.py +53 -21
- infrahub/core/branch/models.py +4 -4
- infrahub/core/branch/tasks.py +89 -130
- infrahub/core/changelog/__init__.py +0 -0
- infrahub/core/changelog/diff.py +232 -0
- infrahub/core/changelog/models.py +488 -0
- infrahub/core/constants/__init__.py +19 -2
- infrahub/core/constants/infrahubkind.py +1 -0
- infrahub/core/diff/combiner.py +12 -8
- infrahub/core/diff/coordinator.py +49 -70
- infrahub/core/diff/data_check_synchronizer.py +86 -7
- infrahub/core/diff/enricher/aggregated.py +3 -3
- infrahub/core/diff/enricher/cardinality_one.py +2 -7
- infrahub/core/diff/enricher/hierarchy.py +5 -3
- infrahub/core/diff/enricher/labels.py +14 -4
- infrahub/core/diff/enricher/path_identifier.py +3 -9
- infrahub/core/diff/enricher/summary_counts.py +3 -1
- infrahub/core/diff/merger/merger.py +8 -4
- infrahub/core/diff/model/path.py +47 -29
- infrahub/core/diff/query/all_conflicts.py +6 -3
- infrahub/core/diff/query/artifact.py +1 -1
- infrahub/core/diff/query/delete_query.py +1 -1
- infrahub/core/diff/query/diff_get.py +3 -2
- infrahub/core/diff/query/diff_summary.py +1 -1
- infrahub/core/diff/query/field_specifiers.py +3 -1
- infrahub/core/diff/query/field_summary.py +3 -2
- infrahub/core/diff/query/filters.py +12 -1
- infrahub/core/diff/query/get_conflict_query.py +1 -1
- infrahub/core/diff/query/has_conflicts_query.py +6 -3
- infrahub/core/diff/query/merge.py +3 -3
- infrahub/core/diff/query/{drop_tracking_id.py → merge_tracking_id.py} +4 -4
- infrahub/core/diff/query/roots_metadata.py +9 -2
- infrahub/core/diff/query/save.py +151 -66
- infrahub/core/diff/query/summary_counts_enricher.py +220 -0
- infrahub/core/diff/query/time_range_query.py +3 -2
- infrahub/core/diff/query/update_conflict_query.py +1 -1
- infrahub/core/diff/query_parser.py +49 -24
- infrahub/core/diff/repository/deserializer.py +24 -25
- infrahub/core/diff/repository/repository.py +76 -20
- infrahub/core/diff/tasks.py +9 -8
- infrahub/core/enums.py +1 -1
- infrahub/core/integrity/object_conflict/conflict_recorder.py +1 -1
- infrahub/core/ipam/reconciler.py +1 -1
- infrahub/core/ipam/tasks.py +2 -3
- infrahub/core/manager.py +18 -13
- infrahub/core/merge.py +5 -2
- infrahub/core/migrations/graph/m001_add_version_to_graph.py +1 -1
- infrahub/core/migrations/graph/m002_attribute_is_default.py +2 -2
- infrahub/core/migrations/graph/m003_relationship_parent_optional.py +2 -2
- infrahub/core/migrations/graph/m004_add_attr_documentation.py +1 -1
- infrahub/core/migrations/graph/m005_add_rel_read_only.py +1 -1
- infrahub/core/migrations/graph/m006_add_rel_on_delete.py +1 -1
- infrahub/core/migrations/graph/m007_add_rel_allow_override.py +1 -1
- infrahub/core/migrations/graph/m008_add_human_friendly_id.py +1 -1
- infrahub/core/migrations/graph/m009_add_generate_profile_attr.py +1 -1
- infrahub/core/migrations/graph/m010_add_generate_profile_attr_generic.py +1 -1
- infrahub/core/migrations/graph/m011_remove_profile_relationship_schema.py +2 -2
- infrahub/core/migrations/graph/m012_convert_account_generic.py +12 -23
- infrahub/core/migrations/graph/m013_convert_git_password_credential.py +7 -11
- infrahub/core/migrations/graph/m014_remove_index_attr_value.py +2 -2
- infrahub/core/migrations/graph/m015_diff_format_update.py +1 -1
- infrahub/core/migrations/graph/m016_diff_delete_bug_fix.py +1 -1
- infrahub/core/migrations/graph/m017_add_core_profile.py +1 -1
- infrahub/core/migrations/graph/m018_uniqueness_nulls.py +2 -2
- infrahub/core/migrations/query/attribute_add.py +1 -1
- infrahub/core/migrations/query/attribute_rename.py +1 -1
- infrahub/core/migrations/query/delete_element_in_schema.py +1 -1
- infrahub/core/migrations/query/node_duplicate.py +1 -1
- infrahub/core/migrations/query/relationship_duplicate.py +1 -1
- infrahub/core/migrations/query/schema_attribute_update.py +1 -1
- infrahub/core/migrations/schema/node_attribute_remove.py +1 -1
- infrahub/core/migrations/schema/node_remove.py +1 -1
- infrahub/core/migrations/schema/tasks.py +5 -5
- infrahub/core/migrations/shared.py +4 -4
- infrahub/core/models.py +7 -8
- infrahub/core/node/__init__.py +161 -40
- infrahub/core/node/base.py +1 -1
- infrahub/core/node/constraints/grouped_uniqueness.py +9 -2
- infrahub/core/node/delete_validator.py +4 -4
- infrahub/core/node/ipam.py +13 -8
- infrahub/core/node/permissions.py +4 -0
- infrahub/core/node/resource_manager/ip_prefix_pool.py +8 -5
- infrahub/core/node/standard.py +3 -5
- infrahub/core/property.py +1 -1
- infrahub/core/protocols.py +4 -0
- infrahub/core/protocols_base.py +4 -2
- infrahub/core/query/__init__.py +2 -5
- infrahub/core/query/attribute.py +9 -9
- infrahub/core/query/branch.py +5 -5
- infrahub/core/query/delete.py +1 -1
- infrahub/core/query/diff.py +45 -7
- infrahub/core/query/ipam.py +4 -4
- infrahub/core/query/node.py +19 -14
- infrahub/core/query/relationship.py +10 -11
- infrahub/core/query/resource_manager.py +13 -11
- infrahub/core/query/standard_node.py +6 -6
- infrahub/core/query/task.py +3 -3
- infrahub/core/query/task_log.py +1 -1
- infrahub/core/query/utils.py +5 -5
- infrahub/core/registry.py +0 -2
- infrahub/core/relationship/constraints/count.py +1 -1
- infrahub/core/relationship/constraints/peer_kind.py +1 -1
- infrahub/core/relationship/model.py +66 -26
- infrahub/core/schema/__init__.py +6 -4
- infrahub/core/schema/basenode_schema.py +1 -3
- infrahub/core/schema/definitions/core.py +14 -2
- infrahub/core/schema/definitions/internal.py +16 -0
- infrahub/core/schema/generated/genericnode_schema.py +5 -0
- infrahub/core/schema/generated/node_schema.py +5 -0
- infrahub/core/schema/generic_schema.py +5 -1
- infrahub/core/schema/manager.py +45 -42
- infrahub/core/schema/node_schema.py +4 -0
- infrahub/core/schema/profile_schema.py +4 -0
- infrahub/core/schema/relationship_schema.py +2 -2
- infrahub/core/schema/schema_branch.py +248 -14
- infrahub/core/schema/template_schema.py +36 -0
- infrahub/core/task/user_task.py +7 -5
- infrahub/core/timestamp.py +1 -1
- infrahub/core/utils.py +3 -2
- infrahub/core/validators/attribute/choices.py +1 -1
- infrahub/core/validators/attribute/enum.py +1 -1
- infrahub/core/validators/attribute/kind.py +1 -1
- infrahub/core/validators/attribute/length.py +1 -1
- infrahub/core/validators/attribute/optional.py +1 -1
- infrahub/core/validators/attribute/regex.py +1 -1
- infrahub/core/validators/attribute/unique.py +1 -1
- infrahub/core/validators/checks_runner.py +37 -0
- infrahub/core/validators/node/generate_profile.py +1 -1
- infrahub/core/validators/node/hierarchy.py +1 -1
- infrahub/core/validators/query.py +1 -1
- infrahub/core/validators/relationship/count.py +1 -1
- infrahub/core/validators/relationship/optional.py +1 -1
- infrahub/core/validators/relationship/peer.py +1 -1
- infrahub/core/validators/tasks.py +8 -6
- infrahub/core/validators/uniqueness/query.py +20 -17
- infrahub/database/__init__.py +15 -2
- infrahub/database/memgraph.py +1 -1
- infrahub/dependencies/builder/constraint/grouped/node_runner.py +0 -2
- infrahub/dependencies/builder/diff/combiner.py +1 -1
- infrahub/dependencies/builder/diff/conflicts_enricher.py +1 -1
- infrahub/dependencies/builder/diff/coordinator.py +0 -2
- infrahub/dependencies/builder/diff/deserializer.py +1 -1
- infrahub/dependencies/builder/diff/enricher/summary_counts.py +1 -1
- infrahub/events/branch_action.py +47 -21
- infrahub/events/group_action.py +73 -0
- infrahub/events/models.py +159 -51
- infrahub/events/node_action.py +74 -8
- infrahub/events/repository_action.py +8 -8
- infrahub/events/schema_action.py +21 -8
- infrahub/generators/tasks.py +12 -13
- infrahub/git/base.py +3 -5
- infrahub/git/constants.py +0 -1
- infrahub/git/integrator.py +36 -35
- infrahub/git/repository.py +7 -8
- infrahub/git/tasks.py +43 -107
- infrahub/git_credential/helper.py +2 -3
- infrahub/graphql/analyzer.py +572 -11
- infrahub/graphql/app.py +34 -26
- infrahub/graphql/auth/query_permission_checker/anonymous_checker.py +5 -5
- infrahub/graphql/auth/query_permission_checker/default_branch_checker.py +4 -4
- infrahub/graphql/auth/query_permission_checker/merge_operation_checker.py +4 -4
- infrahub/graphql/auth/query_permission_checker/object_permission_checker.py +28 -35
- infrahub/graphql/auth/query_permission_checker/super_admin_checker.py +5 -5
- infrahub/graphql/enums.py +1 -1
- infrahub/graphql/initialization.py +5 -1
- infrahub/graphql/loaders/node.py +2 -2
- infrahub/graphql/manager.py +59 -54
- infrahub/graphql/mutations/account.py +20 -13
- infrahub/graphql/mutations/artifact_definition.py +16 -12
- infrahub/graphql/mutations/branch.py +61 -40
- infrahub/graphql/mutations/computed_attribute.py +19 -13
- infrahub/graphql/mutations/diff.py +37 -9
- infrahub/graphql/mutations/diff_conflict.py +9 -8
- infrahub/graphql/mutations/graphql_query.py +19 -11
- infrahub/graphql/mutations/ipam.py +21 -19
- infrahub/graphql/mutations/main.py +197 -44
- infrahub/graphql/mutations/menu.py +8 -8
- infrahub/graphql/mutations/proposed_change.py +36 -28
- infrahub/graphql/mutations/relationship.py +302 -105
- infrahub/graphql/mutations/repository.py +41 -35
- infrahub/graphql/mutations/resource_manager.py +26 -26
- infrahub/graphql/mutations/schema.py +51 -33
- infrahub/graphql/mutations/tasks.py +16 -10
- infrahub/graphql/parser.py +1 -1
- infrahub/graphql/permissions.py +6 -4
- infrahub/graphql/queries/account.py +22 -18
- infrahub/graphql/queries/branch.py +6 -4
- infrahub/graphql/queries/diff/tree.py +48 -42
- infrahub/graphql/queries/event.py +112 -0
- infrahub/graphql/queries/internal.py +3 -3
- infrahub/graphql/queries/ipam.py +23 -18
- infrahub/graphql/queries/relationship.py +11 -10
- infrahub/graphql/queries/resource_manager.py +43 -27
- infrahub/graphql/queries/search.py +9 -8
- infrahub/graphql/queries/status.py +12 -9
- infrahub/graphql/queries/task.py +11 -9
- infrahub/graphql/resolvers/resolver.py +69 -43
- infrahub/graphql/resolvers/single_relationship.py +16 -10
- infrahub/graphql/schema.py +2 -0
- infrahub/graphql/subscription/__init__.py +1 -1
- infrahub/graphql/subscription/events.py +1 -1
- infrahub/graphql/subscription/graphql_query.py +8 -8
- infrahub/graphql/types/branch.py +2 -2
- infrahub/graphql/types/common.py +6 -1
- infrahub/graphql/types/enums.py +2 -0
- infrahub/graphql/types/event.py +100 -0
- infrahub/graphql/types/interface.py +2 -2
- infrahub/graphql/types/node.py +3 -3
- infrahub/graphql/types/permission.py +2 -2
- infrahub/graphql/types/relationship.py +3 -3
- infrahub/graphql/types/standard_node.py +9 -11
- infrahub/graphql/utils.py +28 -182
- infrahub/groups/tasks.py +2 -3
- infrahub/lock.py +1 -1
- infrahub/menu/constants.py +1 -0
- infrahub/menu/generator.py +14 -3
- infrahub/menu/menu.py +116 -127
- infrahub/menu/models.py +4 -4
- infrahub/message_bus/messages/__init__.py +0 -4
- infrahub/message_bus/messages/event_branch_merge.py +3 -0
- infrahub/message_bus/messages/request_proposedchange_pipeline.py +2 -0
- infrahub/message_bus/operations/__init__.py +3 -5
- infrahub/message_bus/operations/check/__init__.py +2 -2
- infrahub/message_bus/operations/check/generator.py +1 -3
- infrahub/message_bus/operations/check/repository.py +1 -1
- infrahub/message_bus/operations/event/branch.py +7 -3
- infrahub/message_bus/operations/event/schema.py +1 -1
- infrahub/message_bus/operations/finalize/validator.py +1 -1
- infrahub/message_bus/operations/git/file.py +2 -2
- infrahub/message_bus/operations/git/repository.py +1 -1
- infrahub/message_bus/operations/requests/__init__.py +0 -2
- infrahub/message_bus/operations/requests/generator_definition.py +1 -1
- infrahub/message_bus/operations/requests/proposed_change.py +26 -11
- infrahub/message_bus/operations/requests/repository.py +2 -2
- infrahub/message_bus/operations/send/echo.py +1 -1
- infrahub/message_bus/types.py +1 -1
- infrahub/permissions/__init__.py +2 -1
- infrahub/permissions/types.py +26 -0
- infrahub/pools/prefix.py +29 -165
- infrahub/prefect_server/__init__.py +0 -0
- infrahub/prefect_server/app.py +18 -0
- infrahub/prefect_server/database.py +20 -0
- infrahub/prefect_server/events.py +28 -0
- infrahub/prefect_server/models.py +46 -0
- infrahub/proposed_change/models.py +15 -1
- infrahub/proposed_change/tasks.py +173 -35
- infrahub/pytest_plugin.py +4 -4
- infrahub/server.py +12 -11
- infrahub/services/__init__.py +147 -62
- infrahub/services/adapters/cache/__init__.py +7 -5
- infrahub/services/adapters/cache/nats.py +40 -22
- infrahub/services/adapters/cache/redis.py +0 -4
- infrahub/services/adapters/event/__init__.py +10 -18
- infrahub/services/adapters/http/__init__.py +0 -5
- infrahub/services/adapters/http/httpx.py +22 -15
- infrahub/services/adapters/message_bus/__init__.py +23 -6
- infrahub/services/adapters/message_bus/local.py +8 -6
- infrahub/services/adapters/message_bus/nats.py +12 -6
- infrahub/services/adapters/message_bus/rabbitmq.py +22 -9
- infrahub/services/adapters/workflow/__init__.py +11 -8
- infrahub/services/adapters/workflow/local.py +28 -7
- infrahub/services/adapters/workflow/worker.py +23 -7
- infrahub/services/component.py +38 -35
- infrahub/services/scheduler.py +32 -29
- infrahub/storage.py +2 -4
- infrahub/task_manager/constants.py +1 -1
- infrahub/task_manager/event.py +182 -0
- infrahub/task_manager/models.py +125 -1
- infrahub/task_manager/task.py +1 -1
- infrahub/tasks/artifact.py +14 -16
- infrahub/tasks/registry.py +1 -1
- infrahub/tasks/telemetry.py +13 -14
- infrahub/transformations/tasks.py +3 -5
- infrahub/trigger/__init__.py +0 -0
- infrahub/trigger/catalogue.py +15 -0
- infrahub/trigger/constants.py +9 -0
- infrahub/trigger/models.py +69 -0
- infrahub/trigger/tasks.py +85 -0
- infrahub/types.py +1 -1
- infrahub/utils.py +1 -1
- infrahub/webhook/constants.py +0 -2
- infrahub/webhook/models.py +8 -2
- infrahub/webhook/tasks.py +20 -73
- infrahub/webhook/triggers.py +20 -0
- infrahub/workers/infrahub_async.py +36 -25
- infrahub/workers/utils.py +63 -0
- infrahub/workflows/catalogue.py +13 -37
- infrahub/workflows/initialization.py +6 -8
- infrahub/workflows/models.py +3 -5
- infrahub/workflows/utils.py +1 -1
- infrahub_sdk/ctl/check.py +3 -3
- infrahub_sdk/ctl/cli_commands.py +11 -10
- infrahub_sdk/ctl/exceptions.py +0 -6
- infrahub_sdk/ctl/exporter.py +1 -1
- infrahub_sdk/ctl/generator.py +5 -5
- infrahub_sdk/ctl/importer.py +3 -2
- infrahub_sdk/ctl/menu.py +1 -1
- infrahub_sdk/ctl/object.py +1 -1
- infrahub_sdk/ctl/repository.py +23 -15
- infrahub_sdk/ctl/schema.py +2 -2
- infrahub_sdk/ctl/utils.py +4 -3
- infrahub_sdk/ctl/validate.py +2 -1
- infrahub_sdk/exceptions.py +6 -0
- infrahub_sdk/generator.py +3 -0
- infrahub_sdk/node.py +2 -2
- infrahub_sdk/schema/__init__.py +14 -2
- infrahub_sdk/schema/main.py +7 -0
- infrahub_sdk/utils.py +11 -1
- infrahub_sdk/yaml.py +2 -3
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/METADATA +46 -12
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/RECORD +338 -321
- infrahub_testcontainers/container.py +14 -6
- infrahub_testcontainers/docker-compose.test.yml +24 -5
- infrahub_testcontainers/haproxy.cfg +43 -0
- infrahub_testcontainers/helpers.py +85 -1
- infrahub/core/branch/constants.py +0 -2
- infrahub/graphql/query.py +0 -52
- infrahub/message_bus/messages/request_artifactdefinition_check.py +0 -17
- infrahub/message_bus/operations/requests/artifact_definition.py +0 -148
- infrahub/schema/constants.py +0 -1
- infrahub/schema/tasks.py +0 -76
- infrahub/services/adapters/database/__init__.py +0 -9
- infrahub_sdk/ctl/_file.py +0 -13
- /infrahub/{schema → artifacts}/__init__.py +0 -0
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/WHEEL +0 -0
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from infrahub_sdk.utils import compare_lists
|
|
4
|
+
from prefect import get_run_logger, task
|
|
5
|
+
from prefect.automations import AutomationCore
|
|
6
|
+
from prefect.cache_policies import NONE
|
|
7
|
+
from prefect.client.orchestration import PrefectClient
|
|
8
|
+
from prefect.client.schemas.filters import DeploymentFilter, DeploymentFilterName
|
|
9
|
+
|
|
10
|
+
from .catalogue import triggers
|
|
11
|
+
from .constants import DEPRECATED_STATIC_TRIGGER_NAMES
|
|
12
|
+
from .models import TriggerType
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from uuid import UUID
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@task(name="trigger-setup", task_run_name="Setup triggers in task-manager", cache_policy=NONE) # type: ignore[arg-type]
|
|
19
|
+
async def setup_triggers(client: PrefectClient) -> None:
|
|
20
|
+
log = get_run_logger()
|
|
21
|
+
|
|
22
|
+
# -------------------------------------------------------------
|
|
23
|
+
# Retrieve existing Deployments and Automation from the server
|
|
24
|
+
# -------------------------------------------------------------
|
|
25
|
+
deployment_names = list({name for trigger in triggers for name in trigger.get_deployment_names()})
|
|
26
|
+
deployments = {
|
|
27
|
+
item.name: item
|
|
28
|
+
for item in await client.read_deployments(
|
|
29
|
+
deployment_filter=DeploymentFilter(name=DeploymentFilterName(any_=deployment_names))
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
deployments_mapping: dict[str, UUID] = {name: item.id for name, item in deployments.items()}
|
|
33
|
+
existing_automations = {item.name: item for item in await client.read_automations()}
|
|
34
|
+
|
|
35
|
+
builtin_automations = [
|
|
36
|
+
item.name for item in await client.read_automations() if item.name.startswith(TriggerType.BUILTIN.value)
|
|
37
|
+
]
|
|
38
|
+
trigger_names = [trigger.generate_name() for trigger in triggers]
|
|
39
|
+
|
|
40
|
+
_, to_delete, _ = compare_lists(list1=builtin_automations, list2=trigger_names)
|
|
41
|
+
|
|
42
|
+
# -------------------------------------------------------------
|
|
43
|
+
# Create or Update all builtin triggers
|
|
44
|
+
# -------------------------------------------------------------
|
|
45
|
+
for trigger in triggers:
|
|
46
|
+
automation = AutomationCore(
|
|
47
|
+
name=trigger.generate_name(),
|
|
48
|
+
description=trigger.description,
|
|
49
|
+
enabled=True,
|
|
50
|
+
trigger=trigger.trigger.get_prefect(),
|
|
51
|
+
actions=[action.get_prefect(mapping=deployments_mapping) for action in trigger.actions],
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
existing_automation = existing_automations.get(trigger.name, None)
|
|
55
|
+
|
|
56
|
+
if existing_automation:
|
|
57
|
+
await client.update_automation(automation_id=existing_automation.id, automation=automation)
|
|
58
|
+
log.info(f"{trigger.name} Updated")
|
|
59
|
+
else:
|
|
60
|
+
await client.create_automation(automation=automation)
|
|
61
|
+
log.info(f"{trigger.name} Created")
|
|
62
|
+
|
|
63
|
+
# -------------------------------------------------------------
|
|
64
|
+
# Delete Builtin Triggers that shouldn't be there
|
|
65
|
+
# -------------------------------------------------------------
|
|
66
|
+
for item_to_delete in to_delete:
|
|
67
|
+
existing_automation = existing_automations.get(item_to_delete)
|
|
68
|
+
|
|
69
|
+
if not existing_automation:
|
|
70
|
+
continue
|
|
71
|
+
|
|
72
|
+
await client.delete_automation(automation_id=existing_automation.id)
|
|
73
|
+
log.info(f"{item_to_delete} Deleted")
|
|
74
|
+
|
|
75
|
+
# -------------------------------------------------------------
|
|
76
|
+
# Delete Deprecated triggers
|
|
77
|
+
# -------------------------------------------------------------
|
|
78
|
+
for trigger_name in DEPRECATED_STATIC_TRIGGER_NAMES:
|
|
79
|
+
existing_automation = existing_automations.get(trigger_name)
|
|
80
|
+
|
|
81
|
+
if not existing_automation:
|
|
82
|
+
continue
|
|
83
|
+
|
|
84
|
+
await client.delete_automation(automation_id=existing_automation.id)
|
|
85
|
+
log.info(f"{trigger_name} Deleted")
|
infrahub/types.py
CHANGED
|
@@ -354,7 +354,7 @@ ATTRIBUTE_PYTHON_TYPES: dict[str, type] = {
|
|
|
354
354
|
"Color": str, # Colors often represented as hex strings
|
|
355
355
|
"Number": float, # Numbers can be floats for general use
|
|
356
356
|
"Bandwidth": float, # Bandwidth in some units, represented as a float
|
|
357
|
-
"IPHost": IPvAnyAddress,
|
|
357
|
+
"IPHost": IPvAnyAddress, # type: ignore[dict-item]
|
|
358
358
|
"IPNetwork": str,
|
|
359
359
|
"Boolean": bool,
|
|
360
360
|
"Checkbox": bool, # Checkboxes represent boolean values
|
infrahub/utils.py
CHANGED
infrahub/webhook/constants.py
CHANGED
infrahub/webhook/models.py
CHANGED
|
@@ -87,11 +87,17 @@ class TransformWebhook(Webhook):
|
|
|
87
87
|
repo: Union[InfrahubReadOnlyRepository, InfrahubRepository]
|
|
88
88
|
if self.repository_kind == InfrahubKind.READONLYREPOSITORY:
|
|
89
89
|
repo = await InfrahubReadOnlyRepository.init(
|
|
90
|
-
id=self.repository_id,
|
|
90
|
+
id=self.repository_id,
|
|
91
|
+
name=self.repository_name,
|
|
92
|
+
client=self.service.client,
|
|
93
|
+
service=self.service,
|
|
91
94
|
)
|
|
92
95
|
else:
|
|
93
96
|
repo = await InfrahubRepository.init(
|
|
94
|
-
id=self.repository_id,
|
|
97
|
+
id=self.repository_id,
|
|
98
|
+
name=self.repository_name,
|
|
99
|
+
client=self.service.client,
|
|
100
|
+
service=self.service,
|
|
95
101
|
)
|
|
96
102
|
|
|
97
103
|
default_branch = repo.default_branch
|
infrahub/webhook/tasks.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from datetime import timedelta
|
|
2
|
-
from typing import Any
|
|
2
|
+
from typing import TYPE_CHECKING, Any
|
|
3
3
|
|
|
4
4
|
import ujson
|
|
5
5
|
from infrahub_sdk.protocols import CoreCustomWebhook, CoreStandardWebhook, CoreTransformPython
|
|
@@ -12,18 +12,20 @@ from prefect.events.schemas.automations import EventTrigger, Posture
|
|
|
12
12
|
from prefect.events.schemas.events import ResourceSpecification
|
|
13
13
|
from prefect.logging import get_run_logger
|
|
14
14
|
|
|
15
|
-
from infrahub.core.constants import
|
|
15
|
+
from infrahub.core.constants import MutationAction
|
|
16
16
|
from infrahub.exceptions import NodeNotFoundError
|
|
17
|
-
from infrahub.services import
|
|
18
|
-
from infrahub.workflows.catalogue import
|
|
17
|
+
from infrahub.services import InfrahubServices
|
|
18
|
+
from infrahub.workflows.catalogue import WEBHOOK_SEND, WEBHOOK_TRIGGER
|
|
19
19
|
|
|
20
|
-
from .constants import
|
|
20
|
+
from .constants import AUTOMATION_NAME_RUN
|
|
21
21
|
from .models import CustomWebhook, SendWebhookData, StandardWebhook, TransformWebhook, Webhook
|
|
22
22
|
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from prefect.events.schemas.automations import Automation
|
|
25
|
+
|
|
23
26
|
|
|
24
27
|
@flow(name="event-send-webhook", flow_run_name="Send Webhook")
|
|
25
|
-
async def send_webhook(model: SendWebhookData) -> None:
|
|
26
|
-
service = services.service
|
|
28
|
+
async def send_webhook(model: SendWebhookData, service: InfrahubServices) -> None:
|
|
27
29
|
log = get_run_logger()
|
|
28
30
|
|
|
29
31
|
webhook_definition = await service.cache.get(key=f"webhook:active:{model.webhook_id}")
|
|
@@ -49,20 +51,16 @@ async def send_webhook(model: SendWebhookData) -> None:
|
|
|
49
51
|
|
|
50
52
|
|
|
51
53
|
@flow(name="webhook-trigger-actions", flow_run_name="Trigger configured webhooks")
|
|
52
|
-
async def trigger_webhooks(event_type: str, event_data:
|
|
53
|
-
service = services.service
|
|
54
|
-
payload: dict = ujson.loads(event_data)
|
|
55
|
-
|
|
54
|
+
async def trigger_webhooks(event_type: str, event_data: dict, service: InfrahubServices) -> None:
|
|
56
55
|
webhooks = await service.cache.list_keys(filter_pattern="webhook:active:*")
|
|
57
56
|
for webhook in webhooks:
|
|
58
57
|
webhook_id = webhook.split(":")[-1]
|
|
59
|
-
model = SendWebhookData(webhook_id=webhook_id, event_type=event_type, event_data=
|
|
58
|
+
model = SendWebhookData(webhook_id=webhook_id, event_type=event_type, event_data=event_data)
|
|
60
59
|
await service.workflow.submit_workflow(workflow=WEBHOOK_SEND, parameters={"model": model})
|
|
61
60
|
|
|
62
61
|
|
|
63
62
|
@flow(name="webhook-setup-automations", flow_run_name="Configuration webhook automation and populate cache")
|
|
64
|
-
async def configure_webhooks() -> None:
|
|
65
|
-
service = services.service
|
|
63
|
+
async def configure_webhooks(service: InfrahubServices) -> None:
|
|
66
64
|
log = get_run_logger()
|
|
67
65
|
|
|
68
66
|
log.debug("Refreshing webhook configuration")
|
|
@@ -135,7 +133,10 @@ async def configure_webhooks() -> None:
|
|
|
135
133
|
|
|
136
134
|
deployment_id_webhook_trigger = deployments[WEBHOOK_TRIGGER.name].id
|
|
137
135
|
|
|
138
|
-
webhook_configure_automation
|
|
136
|
+
webhook_configure_automation: Automation | None = None
|
|
137
|
+
automations = await client.read_automations_by_name(name=AUTOMATION_NAME_RUN)
|
|
138
|
+
if automations:
|
|
139
|
+
webhook_configure_automation = automations[0]
|
|
139
140
|
|
|
140
141
|
if not has_webhooks:
|
|
141
142
|
if webhook_configure_automation:
|
|
@@ -163,7 +164,10 @@ async def configure_webhooks() -> None:
|
|
|
163
164
|
deployment_id=deployment_id_webhook_trigger,
|
|
164
165
|
parameters={
|
|
165
166
|
"event_type": "{{ event.resource['infrahub.node.kind'] }}.{{ event.resource['infrahub.node.action'] }}",
|
|
166
|
-
"event_data":
|
|
167
|
+
"event_data": {
|
|
168
|
+
"__prefect_kind": "json",
|
|
169
|
+
"value": {"__prefect_kind": "jinja", "template": "{{ event.payload['data'] | tojson }}"},
|
|
170
|
+
},
|
|
167
171
|
},
|
|
168
172
|
job_variables={},
|
|
169
173
|
),
|
|
@@ -176,60 +180,3 @@ async def configure_webhooks() -> None:
|
|
|
176
180
|
else:
|
|
177
181
|
await client.create_automation(automation=automation)
|
|
178
182
|
log.info(f"{AUTOMATION_NAME_RUN} Created")
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
@flow(name="webhook-setup-configuration-trigger", flow_run_name="Setup automations for webhooks")
|
|
182
|
-
async def trigger_webhook_configuration() -> None:
|
|
183
|
-
log = get_run_logger()
|
|
184
|
-
|
|
185
|
-
async with get_client(sync_client=False) as client:
|
|
186
|
-
deployments = {
|
|
187
|
-
item.name: item
|
|
188
|
-
for item in await client.read_deployments(
|
|
189
|
-
deployment_filter=DeploymentFilter(
|
|
190
|
-
name=DeploymentFilterName(
|
|
191
|
-
any_=[
|
|
192
|
-
WEBHOOK_CONFIGURE.name,
|
|
193
|
-
]
|
|
194
|
-
)
|
|
195
|
-
)
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
if WEBHOOK_CONFIGURE.name not in deployments:
|
|
199
|
-
raise ValueError("Unable to find the deployment for WEBHOOK_CONFIGURE")
|
|
200
|
-
|
|
201
|
-
deployment_id_webhook_setup = deployments[WEBHOOK_CONFIGURE.name].id
|
|
202
|
-
|
|
203
|
-
webhook_configure_automation = await client.find_automation(id_or_name=AUTOMATION_NAME)
|
|
204
|
-
|
|
205
|
-
automation = AutomationCore(
|
|
206
|
-
name=AUTOMATION_NAME,
|
|
207
|
-
description="Trigger actions on schema update event",
|
|
208
|
-
enabled=True,
|
|
209
|
-
trigger=EventTrigger(
|
|
210
|
-
posture=Posture.Reactive,
|
|
211
|
-
expect={"infrahub.node.*"},
|
|
212
|
-
within=timedelta(0),
|
|
213
|
-
match=ResourceSpecification(
|
|
214
|
-
{
|
|
215
|
-
"infrahub.node.kind": [InfrahubKind.WEBHOOK, InfrahubKind.STANDARDWEBHOOK],
|
|
216
|
-
}
|
|
217
|
-
),
|
|
218
|
-
threshold=1,
|
|
219
|
-
),
|
|
220
|
-
actions=[
|
|
221
|
-
RunDeployment(
|
|
222
|
-
source="selected",
|
|
223
|
-
deployment_id=deployment_id_webhook_setup,
|
|
224
|
-
parameters={},
|
|
225
|
-
job_variables={},
|
|
226
|
-
),
|
|
227
|
-
],
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
if webhook_configure_automation:
|
|
231
|
-
await client.update_automation(automation_id=webhook_configure_automation.id, automation=automation)
|
|
232
|
-
log.info(f"{AUTOMATION_NAME} Updated")
|
|
233
|
-
else:
|
|
234
|
-
await client.create_automation(automation=automation)
|
|
235
|
-
log.info(f"{AUTOMATION_NAME} Created")
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from infrahub.core.constants import InfrahubKind
|
|
2
|
+
from infrahub.trigger.models import BuiltinTriggerDefinition, EventTrigger, ExecuteWorkflow
|
|
3
|
+
from infrahub.workflows.catalogue import (
|
|
4
|
+
WEBHOOK_CONFIGURE,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
TRIGGER_WEBHOOK_SETUP_UPDATE = BuiltinTriggerDefinition(
|
|
8
|
+
name="webhook-setup-update-configuration",
|
|
9
|
+
trigger=EventTrigger(
|
|
10
|
+
events={"infrahub.node.*"},
|
|
11
|
+
match={
|
|
12
|
+
"infrahub.node.kind": [InfrahubKind.WEBHOOK, InfrahubKind.STANDARDWEBHOOK],
|
|
13
|
+
},
|
|
14
|
+
),
|
|
15
|
+
actions=[
|
|
16
|
+
ExecuteWorkflow(
|
|
17
|
+
name=WEBHOOK_CONFIGURE.name,
|
|
18
|
+
),
|
|
19
|
+
],
|
|
20
|
+
)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import importlib
|
|
2
1
|
import logging
|
|
3
2
|
import os
|
|
4
3
|
from typing import Any, Optional
|
|
@@ -23,7 +22,7 @@ from infrahub.database import InfrahubDatabase, get_db
|
|
|
23
22
|
from infrahub.dependencies.registry import build_component_registry
|
|
24
23
|
from infrahub.git import initialize_repositories_directory
|
|
25
24
|
from infrahub.lock import initialize_lock
|
|
26
|
-
from infrahub.services import InfrahubServices
|
|
25
|
+
from infrahub.services import InfrahubServices
|
|
27
26
|
from infrahub.services.adapters.cache import InfrahubCache
|
|
28
27
|
from infrahub.services.adapters.cache.nats import NATSCache
|
|
29
28
|
from infrahub.services.adapters.cache.redis import RedisCache
|
|
@@ -33,6 +32,8 @@ from infrahub.services.adapters.message_bus.rabbitmq import RabbitMQMessageBus
|
|
|
33
32
|
from infrahub.services.adapters.workflow import InfrahubWorkflow
|
|
34
33
|
from infrahub.services.adapters.workflow.local import WorkflowLocalExecution
|
|
35
34
|
from infrahub.services.adapters.workflow.worker import WorkflowWorkerExecution
|
|
35
|
+
from infrahub.trace import configure_trace
|
|
36
|
+
from infrahub.workers.utils import inject_service_parameter, load_flow_function
|
|
36
37
|
from infrahub.workflows.models import TASK_RESULT_STORAGE_NAME
|
|
37
38
|
|
|
38
39
|
WORKER_QUERY_SECONDS = "2"
|
|
@@ -65,6 +66,7 @@ class InfrahubWorkerAsync(BaseWorker):
|
|
|
65
66
|
_documentation_url = "https://example.com/docs"
|
|
66
67
|
_logo_url = "https://example.com/logo"
|
|
67
68
|
_description = "Infrahub worker designed to run the flow in the main async loop."
|
|
69
|
+
service: InfrahubServices # keep a reference to `service` so we can inject it within flows parameters.
|
|
68
70
|
|
|
69
71
|
async def setup(
|
|
70
72
|
self,
|
|
@@ -89,6 +91,16 @@ class InfrahubWorkerAsync(BaseWorker):
|
|
|
89
91
|
|
|
90
92
|
self._init_logger()
|
|
91
93
|
|
|
94
|
+
# Initialize trace
|
|
95
|
+
if config.SETTINGS.trace.enable:
|
|
96
|
+
configure_trace(
|
|
97
|
+
service="infrahub-task-worker",
|
|
98
|
+
version=infrahub_version,
|
|
99
|
+
exporter_type=config.SETTINGS.trace.exporter_type,
|
|
100
|
+
exporter_endpoint=config.SETTINGS.trace.exporter_endpoint,
|
|
101
|
+
exporter_protocol=config.SETTINGS.trace.exporter_protocol,
|
|
102
|
+
)
|
|
103
|
+
|
|
92
104
|
# Start metric endpoint
|
|
93
105
|
if metric_port is None or metric_port != 0:
|
|
94
106
|
metric_port = metric_port or int(os.environ.get("INFRAHUB_METRICS_PORT", 8000))
|
|
@@ -107,20 +119,19 @@ class InfrahubWorkerAsync(BaseWorker):
|
|
|
107
119
|
)
|
|
108
120
|
)
|
|
109
121
|
|
|
110
|
-
|
|
111
|
-
service = await self._init_services(client=client)
|
|
122
|
+
await self._init_services(client=client)
|
|
112
123
|
|
|
113
124
|
if not registry.schema_has_been_initialized():
|
|
114
|
-
initialize_lock(service=service)
|
|
125
|
+
initialize_lock(service=self.service)
|
|
115
126
|
|
|
116
|
-
async with service.database.start_session() as db:
|
|
127
|
+
async with self.service.database.start_session() as db:
|
|
117
128
|
await initialization(db=db)
|
|
118
129
|
|
|
119
|
-
await service.component.refresh_schema_hash()
|
|
130
|
+
await self.service.component.refresh_schema_hash()
|
|
120
131
|
|
|
121
132
|
initialize_repositories_directory()
|
|
122
133
|
build_component_registry()
|
|
123
|
-
await service.scheduler.start_schedule()
|
|
134
|
+
await self.service.scheduler.start_schedule()
|
|
124
135
|
self._logger.info("Worker initialization completed .. ")
|
|
125
136
|
|
|
126
137
|
async def run(
|
|
@@ -136,9 +147,8 @@ class InfrahubWorkerAsync(BaseWorker):
|
|
|
136
147
|
file_path, flow_name = entrypoint.split(":")
|
|
137
148
|
file_path.replace("/", ".")
|
|
138
149
|
module_path = file_path.replace("backend/", "").replace(".py", "").replace("/", ".")
|
|
139
|
-
|
|
140
|
-
flow_func =
|
|
141
|
-
|
|
150
|
+
flow_func = load_flow_function(module_path=module_path, flow_name=flow_name)
|
|
151
|
+
inject_service_parameter(func=flow_func, parameters=flow_run.parameters, service=self.service)
|
|
142
152
|
flow_run_logger.debug("Validating parameters")
|
|
143
153
|
params = flow_func.validate_parameters(parameters=flow_run.parameters)
|
|
144
154
|
|
|
@@ -170,9 +180,9 @@ class InfrahubWorkerAsync(BaseWorker):
|
|
|
170
180
|
|
|
171
181
|
try:
|
|
172
182
|
await client.branch.all()
|
|
173
|
-
except SdkError as
|
|
174
|
-
self._logger.error(f"Error in communication with Infrahub: {
|
|
175
|
-
raise typer.Exit(1)
|
|
183
|
+
except SdkError as err:
|
|
184
|
+
self._logger.error(f"Error in communication with Infrahub: {err.message}")
|
|
185
|
+
raise typer.Exit(1) from err
|
|
176
186
|
|
|
177
187
|
return client
|
|
178
188
|
|
|
@@ -186,32 +196,33 @@ class InfrahubWorkerAsync(BaseWorker):
|
|
|
186
196
|
else WorkflowLocalExecution()
|
|
187
197
|
)
|
|
188
198
|
|
|
189
|
-
async def _init_message_bus(self) -> InfrahubMessageBus:
|
|
199
|
+
async def _init_message_bus(self, component_type: ComponentType) -> InfrahubMessageBus:
|
|
190
200
|
return config.OVERRIDE.message_bus or (
|
|
191
|
-
NATSMessageBus
|
|
201
|
+
await NATSMessageBus.new(component_type=component_type)
|
|
202
|
+
if config.SETTINGS.broker.driver == config.BrokerDriver.NATS
|
|
203
|
+
else await RabbitMQMessageBus.new(component_type=component_type)
|
|
192
204
|
)
|
|
193
205
|
|
|
194
206
|
async def _init_cache(self) -> InfrahubCache:
|
|
195
207
|
return config.OVERRIDE.cache or (
|
|
196
|
-
NATSCache() if config.SETTINGS.cache.driver == config.CacheDriver.NATS else RedisCache()
|
|
208
|
+
await NATSCache.new() if config.SETTINGS.cache.driver == config.CacheDriver.NATS else RedisCache()
|
|
197
209
|
)
|
|
198
210
|
|
|
199
|
-
async def _init_services(self, client: InfrahubClient) ->
|
|
211
|
+
async def _init_services(self, client: InfrahubClient) -> None:
|
|
212
|
+
component_type = ComponentType.GIT_AGENT
|
|
213
|
+
client = await self._init_infrahub_client(client=client)
|
|
200
214
|
database = await self._init_database()
|
|
201
215
|
workflow = await self._init_workflow()
|
|
202
|
-
message_bus = await self._init_message_bus()
|
|
216
|
+
message_bus = await self._init_message_bus(component_type=component_type)
|
|
203
217
|
cache = await self._init_cache()
|
|
204
218
|
|
|
205
|
-
service = InfrahubServices(
|
|
219
|
+
service = await InfrahubServices.new(
|
|
206
220
|
cache=cache,
|
|
207
221
|
client=client,
|
|
208
222
|
database=database,
|
|
209
223
|
message_bus=message_bus,
|
|
210
224
|
workflow=workflow,
|
|
211
|
-
component_type=
|
|
225
|
+
component_type=component_type,
|
|
212
226
|
)
|
|
213
227
|
|
|
214
|
-
|
|
215
|
-
await service.initialize()
|
|
216
|
-
|
|
217
|
-
return service
|
|
228
|
+
self.service = service
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import inspect
|
|
5
|
+
from typing import TYPE_CHECKING, Any
|
|
6
|
+
|
|
7
|
+
from prefect import Flow
|
|
8
|
+
|
|
9
|
+
from infrahub.context import InfrahubContext
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from infrahub.services import InfrahubServices
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def inject_service_parameter(func: Flow, parameters: dict[str, Any], service: InfrahubServices) -> None:
|
|
16
|
+
"""
|
|
17
|
+
`service` object instantiates connections to various services (db, cache...) at worker startup,
|
|
18
|
+
so it is not meant to be sent by the server payload. We inject it here to avoid relying on a global variable.
|
|
19
|
+
This mutates input `parameters`.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
# avoid circular imports
|
|
23
|
+
from infrahub.services import InfrahubServices # pylint: disable=C0415
|
|
24
|
+
|
|
25
|
+
if service_parameter_name := get_parameter_name(func=func, types=[InfrahubServices.__name__, InfrahubServices]):
|
|
26
|
+
if any(isinstance(param_value, InfrahubServices) for param_value in parameters):
|
|
27
|
+
raise ValueError(f"{func} parameters contains an InfrahubServices object while it should be injected")
|
|
28
|
+
parameters[service_parameter_name] = service
|
|
29
|
+
return
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def inject_context_parameter(func: Flow, parameters: dict[str, Any], context: InfrahubContext | None = None) -> None:
|
|
33
|
+
service_parameter_name = get_parameter_name(func=func, types=[InfrahubContext.__name__, InfrahubContext])
|
|
34
|
+
if service_parameter_name and context:
|
|
35
|
+
parameters[service_parameter_name] = context
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
if service_parameter_name and not context:
|
|
39
|
+
raise ValueError(
|
|
40
|
+
f"{func} has a {service_parameter_name} parameter of type InfrahubContext, while context is not provided"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def load_flow_function(module_path: str, flow_name: str) -> Flow:
|
|
45
|
+
module = importlib.import_module(module_path)
|
|
46
|
+
flow_func = getattr(module, flow_name)
|
|
47
|
+
if not isinstance(flow_func, Flow):
|
|
48
|
+
raise ValueError(
|
|
49
|
+
f"Function loaded at {module_path=} with {flow_name=} has type {type(flow_func)}, expected {Flow}"
|
|
50
|
+
)
|
|
51
|
+
return flow_func
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_parameter_name(func: Flow, types: list[Any]) -> str | None:
|
|
55
|
+
sig = inspect.signature(func)
|
|
56
|
+
for sig_param in sig.parameters.values():
|
|
57
|
+
if sig_param.annotation in types:
|
|
58
|
+
return sig_param.name
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def has_parameter(func: Flow, types: list[Any]) -> bool:
|
|
63
|
+
return get_parameter_name(func=func, types=types) is not None
|
infrahub/workflows/catalogue.py
CHANGED
|
@@ -319,27 +319,6 @@ REQUEST_PROPOSED_CHANGE_USER_TESTS = WorkflowDefinition(
|
|
|
319
319
|
function="run_proposed_change_user_tests",
|
|
320
320
|
)
|
|
321
321
|
|
|
322
|
-
AUTOMATION_BRANCH_ACTIONS = WorkflowDefinition(
|
|
323
|
-
name="branch-actions-setup",
|
|
324
|
-
type=WorkflowType.CORE,
|
|
325
|
-
module="infrahub.core.branch.tasks",
|
|
326
|
-
function="branch_actions_setup",
|
|
327
|
-
)
|
|
328
|
-
|
|
329
|
-
AUTOMATION_SCHEMA_UPDATED = WorkflowDefinition(
|
|
330
|
-
name="schema-updated-setup",
|
|
331
|
-
type=WorkflowType.CORE,
|
|
332
|
-
module="infrahub.schema.tasks",
|
|
333
|
-
function="schema_updated_setup",
|
|
334
|
-
)
|
|
335
|
-
|
|
336
|
-
AUTOMATION_GIT_UPDATED = WorkflowDefinition(
|
|
337
|
-
name="git-commit-automation-setup",
|
|
338
|
-
type=WorkflowType.CORE,
|
|
339
|
-
module="infrahub.git.tasks",
|
|
340
|
-
function="setup_commit_automation",
|
|
341
|
-
)
|
|
342
|
-
|
|
343
322
|
GIT_REPOSITORIES_DIFF_NAMES_ONLY = WorkflowDefinition(
|
|
344
323
|
name="git-repository-diff-names-only",
|
|
345
324
|
type=WorkflowType.INTERNAL,
|
|
@@ -370,6 +349,13 @@ REQUEST_PROPOSED_CHANGE_REPOSITORY_CHECKS = WorkflowDefinition(
|
|
|
370
349
|
function="repository_checks",
|
|
371
350
|
)
|
|
372
351
|
|
|
352
|
+
REQUEST_ARTIFACT_DEFINITION_CHECK = WorkflowDefinition(
|
|
353
|
+
name="artifacts-generation-validation",
|
|
354
|
+
type=WorkflowType.INTERNAL,
|
|
355
|
+
module="infrahub.proposed_change.tasks",
|
|
356
|
+
function="validate_artifacts_generation",
|
|
357
|
+
)
|
|
358
|
+
|
|
373
359
|
WEBHOOK_CONFIGURE = WorkflowDefinition(
|
|
374
360
|
name="webhook-setup-automations",
|
|
375
361
|
type=WorkflowType.USER,
|
|
@@ -384,22 +370,17 @@ WEBHOOK_TRIGGER = WorkflowDefinition(
|
|
|
384
370
|
function="trigger_webhooks",
|
|
385
371
|
)
|
|
386
372
|
|
|
387
|
-
|
|
388
|
-
name="
|
|
373
|
+
GIT_REPOSITORIES_CHECK_ARTIFACT_CREATE = WorkflowDefinition(
|
|
374
|
+
name="git-repository-check-artifact-create",
|
|
389
375
|
type=WorkflowType.USER,
|
|
390
|
-
module="infrahub.
|
|
391
|
-
function="
|
|
376
|
+
module="infrahub.artifacts.tasks",
|
|
377
|
+
function="create",
|
|
392
378
|
)
|
|
393
379
|
|
|
394
|
-
|
|
395
380
|
worker_pools = [INFRAHUB_WORKER_POOL]
|
|
396
381
|
|
|
397
382
|
workflows = [
|
|
398
383
|
ANONYMOUS_TELEMETRY_SEND,
|
|
399
|
-
AUTOMATION_BRANCH_ACTIONS,
|
|
400
|
-
AUTOMATION_GIT_UPDATED,
|
|
401
|
-
AUTOMATION_SCHEMA_UPDATED,
|
|
402
|
-
AUTOMATION_SETUP_WEBHOOK_CONFIGURATION_TRIGGER,
|
|
403
384
|
BRANCH_CANCEL_PROPOSED_CHANGES,
|
|
404
385
|
BRANCH_CREATE,
|
|
405
386
|
BRANCH_DELETE,
|
|
@@ -413,6 +394,7 @@ workflows = [
|
|
|
413
394
|
DIFF_REFRESH,
|
|
414
395
|
DIFF_REFRESH_ALL,
|
|
415
396
|
DIFF_UPDATE,
|
|
397
|
+
GIT_REPOSITORIES_CHECK_ARTIFACT_CREATE,
|
|
416
398
|
GIT_REPOSITORIES_CREATE_BRANCH,
|
|
417
399
|
GIT_REPOSITORIES_DIFF_NAMES_ONLY,
|
|
418
400
|
GIT_REPOSITORIES_IMPORT_OBJECTS,
|
|
@@ -426,6 +408,7 @@ workflows = [
|
|
|
426
408
|
PROCESS_COMPUTED_MACRO,
|
|
427
409
|
PROPOSED_CHANGE_MERGE,
|
|
428
410
|
QUERY_COMPUTED_ATTRIBUTE_TRANSFORM_TARGETS,
|
|
411
|
+
REQUEST_ARTIFACT_DEFINITION_CHECK,
|
|
429
412
|
REQUEST_ARTIFACT_DEFINITION_GENERATE,
|
|
430
413
|
REQUEST_ARTIFACT_GENERATE,
|
|
431
414
|
REQUEST_GENERATOR_DEFINITION_RUN,
|
|
@@ -448,10 +431,3 @@ workflows = [
|
|
|
448
431
|
WEBHOOK_SEND,
|
|
449
432
|
WEBHOOK_TRIGGER,
|
|
450
433
|
]
|
|
451
|
-
|
|
452
|
-
automation_setup_workflows = [
|
|
453
|
-
AUTOMATION_BRANCH_ACTIONS,
|
|
454
|
-
AUTOMATION_GIT_UPDATED,
|
|
455
|
-
AUTOMATION_SCHEMA_UPDATED,
|
|
456
|
-
AUTOMATION_SETUP_WEBHOOK_CONFIGURATION_TRIGGER,
|
|
457
|
-
]
|
|
@@ -7,12 +7,13 @@ from prefect.exceptions import ObjectAlreadyExists
|
|
|
7
7
|
from prefect.logging import get_run_logger
|
|
8
8
|
|
|
9
9
|
from infrahub import config
|
|
10
|
+
from infrahub.trigger.tasks import setup_triggers
|
|
10
11
|
|
|
11
|
-
from .catalogue import
|
|
12
|
+
from .catalogue import worker_pools, workflows
|
|
12
13
|
from .models import TASK_RESULT_STORAGE_NAME
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
@task(name="task-manager-setup-worker-pools", task_run_name="Setup Worker pools", cache_policy=NONE)
|
|
16
|
+
@task(name="task-manager-setup-worker-pools", task_run_name="Setup Worker pools", cache_policy=NONE) # type: ignore[arg-type]
|
|
16
17
|
async def setup_worker_pools(client: PrefectClient) -> None:
|
|
17
18
|
log = get_run_logger()
|
|
18
19
|
for worker in worker_pools:
|
|
@@ -28,7 +29,7 @@ async def setup_worker_pools(client: PrefectClient) -> None:
|
|
|
28
29
|
log.warning(f"Work pool {worker.name} already present ")
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
@task(name="task-manager-setup-deployments", task_run_name="Setup Deployments", cache_policy=NONE)
|
|
32
|
+
@task(name="task-manager-setup-deployments", task_run_name="Setup Deployments", cache_policy=NONE) # type: ignore[arg-type]
|
|
32
33
|
async def setup_deployments(client: PrefectClient) -> None:
|
|
33
34
|
log = get_run_logger()
|
|
34
35
|
for workflow in workflows:
|
|
@@ -38,12 +39,8 @@ async def setup_deployments(client: PrefectClient) -> None:
|
|
|
38
39
|
await workflow.save(client=client, work_pool=work_pool)
|
|
39
40
|
log.info(f"Flow {workflow.name}, created successfully ... ")
|
|
40
41
|
|
|
41
|
-
for automation_setup_workflow in automation_setup_workflows:
|
|
42
|
-
automation_setup = automation_setup_workflow.get_function()
|
|
43
|
-
await automation_setup()
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
@task(name="task-manager-setup-blocks", task_run_name="Setup Blocks", cache_policy=NONE)
|
|
43
|
+
@task(name="task-manager-setup-blocks", task_run_name="Setup Blocks", cache_policy=NONE) # type: ignore[arg-type]
|
|
47
44
|
async def setup_blocks() -> None:
|
|
48
45
|
log = get_run_logger()
|
|
49
46
|
|
|
@@ -71,3 +68,4 @@ async def setup_task_manager() -> None:
|
|
|
71
68
|
await setup_blocks()
|
|
72
69
|
await setup_worker_pools(client=client)
|
|
73
70
|
await setup_deployments(client=client)
|
|
71
|
+
await setup_triggers(client=client)
|
infrahub/workflows/models.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import importlib
|
|
2
|
-
from typing import Any, Awaitable,
|
|
2
|
+
from typing import Any, Awaitable, TypeVar
|
|
3
3
|
from uuid import UUID
|
|
4
4
|
|
|
5
|
+
from prefect import Flow
|
|
5
6
|
from prefect.client.orchestration import PrefectClient
|
|
6
7
|
from prefect.client.schemas.actions import DeploymentScheduleCreate
|
|
7
8
|
from prefect.client.schemas.objects import FlowRun
|
|
@@ -72,9 +73,6 @@ class WorkflowDefinition(BaseModel):
|
|
|
72
73
|
data["work_pool_name"] = work_pool.name
|
|
73
74
|
return await client.create_deployment(flow_id=flow_id, **data)
|
|
74
75
|
|
|
75
|
-
def
|
|
76
|
+
def load_function(self) -> Flow[Any, Awaitable]:
|
|
76
77
|
module = importlib.import_module(self.module)
|
|
77
78
|
return getattr(module, self.function)
|
|
78
|
-
|
|
79
|
-
def validate_workflow(self) -> None:
|
|
80
|
-
self.get_function()
|
infrahub/workflows/utils.py
CHANGED