infrahub-server 1.2.0rc0__py3-none-any.whl → 1.2.1__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/dependencies.py +6 -6
- infrahub/api/diff/validation_models.py +7 -7
- infrahub/api/schema.py +1 -1
- infrahub/artifacts/models.py +5 -3
- infrahub/artifacts/tasks.py +3 -5
- infrahub/cli/__init__.py +13 -9
- infrahub/cli/constants.py +3 -0
- infrahub/cli/db.py +165 -183
- infrahub/cli/upgrade.py +146 -0
- infrahub/computed_attribute/gather.py +185 -0
- infrahub/computed_attribute/models.py +240 -12
- infrahub/computed_attribute/tasks.py +77 -441
- infrahub/computed_attribute/triggers.py +13 -47
- infrahub/config.py +43 -32
- infrahub/context.py +14 -0
- infrahub/core/account.py +4 -4
- infrahub/core/attribute.py +58 -58
- infrahub/core/branch/tasks.py +74 -22
- infrahub/core/changelog/diff.py +95 -36
- infrahub/core/changelog/models.py +217 -43
- infrahub/core/constants/__init__.py +28 -0
- infrahub/core/constants/infrahubkind.py +2 -0
- infrahub/core/constants/schema.py +2 -0
- infrahub/core/constraint/node/runner.py +9 -8
- infrahub/core/diff/branch_differ.py +10 -10
- infrahub/core/diff/enricher/cardinality_one.py +5 -0
- infrahub/core/diff/enricher/hierarchy.py +17 -4
- infrahub/core/diff/enricher/labels.py +5 -0
- infrahub/core/diff/enricher/path_identifier.py +4 -0
- infrahub/core/diff/ipam_diff_parser.py +4 -5
- infrahub/core/diff/model/diff.py +27 -27
- infrahub/core/diff/model/path.py +32 -9
- infrahub/core/diff/parent_node_adder.py +78 -0
- infrahub/core/diff/payload_builder.py +13 -2
- infrahub/core/diff/query/filters.py +2 -2
- infrahub/core/diff/query/merge.py +20 -17
- infrahub/core/diff/query/save.py +188 -182
- infrahub/core/diff/query/summary_counts_enricher.py +51 -4
- infrahub/core/diff/query_parser.py +4 -4
- infrahub/core/diff/repository/deserializer.py +8 -3
- infrahub/core/diff/repository/repository.py +156 -38
- infrahub/core/diff/tasks.py +4 -4
- infrahub/core/graph/__init__.py +1 -1
- infrahub/core/graph/index.py +3 -0
- infrahub/core/initialization.py +1 -10
- infrahub/core/ipam/constants.py +3 -4
- infrahub/core/ipam/reconciler.py +12 -12
- infrahub/core/ipam/utilization.py +10 -13
- infrahub/core/manager.py +36 -36
- infrahub/core/merge.py +7 -7
- infrahub/core/migrations/__init__.py +2 -3
- infrahub/core/migrations/graph/__init__.py +12 -3
- infrahub/core/migrations/graph/m017_add_core_profile.py +1 -5
- infrahub/core/migrations/graph/m018_uniqueness_nulls.py +4 -4
- infrahub/core/migrations/graph/m019_restore_rels_to_time.py +256 -0
- infrahub/core/migrations/graph/m020_duplicate_edges.py +160 -0
- infrahub/core/migrations/graph/m021_missing_hierarchy_merge.py +51 -0
- infrahub/core/migrations/graph/m022_add_generate_template_attr.py +48 -0
- infrahub/core/migrations/graph/m023_deduplicate_cardinality_one_relationships.py +96 -0
- infrahub/core/migrations/query/attribute_add.py +2 -2
- infrahub/core/migrations/query/node_duplicate.py +43 -26
- infrahub/core/migrations/query/schema_attribute_update.py +2 -2
- infrahub/core/migrations/schema/models.py +19 -4
- infrahub/core/migrations/schema/node_remove.py +26 -12
- infrahub/core/migrations/schema/tasks.py +2 -2
- infrahub/core/migrations/shared.py +16 -16
- infrahub/core/models.py +15 -6
- infrahub/core/node/__init__.py +43 -39
- infrahub/core/node/base.py +2 -4
- infrahub/core/node/constraints/attribute_uniqueness.py +2 -2
- infrahub/core/node/constraints/grouped_uniqueness.py +99 -47
- infrahub/core/node/constraints/interface.py +1 -2
- infrahub/core/node/delete_validator.py +3 -5
- infrahub/core/node/ipam.py +4 -4
- infrahub/core/node/permissions.py +7 -7
- infrahub/core/node/resource_manager/ip_address_pool.py +6 -6
- infrahub/core/node/resource_manager/ip_prefix_pool.py +6 -6
- infrahub/core/node/resource_manager/number_pool.py +3 -3
- infrahub/core/path.py +12 -12
- infrahub/core/property.py +11 -11
- infrahub/core/protocols.py +7 -0
- infrahub/core/protocols_base.py +21 -21
- infrahub/core/query/__init__.py +33 -33
- infrahub/core/query/attribute.py +6 -4
- infrahub/core/query/diff.py +3 -3
- infrahub/core/query/node.py +82 -32
- infrahub/core/query/relationship.py +228 -40
- infrahub/core/query/resource_manager.py +2 -0
- infrahub/core/query/standard_node.py +3 -3
- infrahub/core/query/subquery.py +9 -9
- infrahub/core/registry.py +13 -15
- infrahub/core/relationship/constraints/count.py +3 -4
- infrahub/core/relationship/constraints/peer_kind.py +3 -4
- infrahub/core/relationship/constraints/profiles_kind.py +2 -2
- infrahub/core/relationship/model.py +51 -59
- infrahub/core/schema/attribute_schema.py +16 -8
- infrahub/core/schema/basenode_schema.py +105 -44
- infrahub/core/schema/computed_attribute.py +3 -3
- infrahub/core/schema/definitions/core/__init__.py +147 -0
- infrahub/core/schema/definitions/core/account.py +171 -0
- infrahub/core/schema/definitions/core/artifact.py +136 -0
- infrahub/core/schema/definitions/core/builtin.py +24 -0
- infrahub/core/schema/definitions/core/check.py +68 -0
- infrahub/core/schema/definitions/core/core.py +17 -0
- infrahub/core/schema/definitions/core/generator.py +100 -0
- infrahub/core/schema/definitions/core/graphql_query.py +79 -0
- infrahub/core/schema/definitions/core/group.py +108 -0
- infrahub/core/schema/definitions/core/ipam.py +193 -0
- infrahub/core/schema/definitions/core/lineage.py +19 -0
- infrahub/core/schema/definitions/core/menu.py +48 -0
- infrahub/core/schema/definitions/core/permission.py +163 -0
- infrahub/core/schema/definitions/core/profile.py +18 -0
- infrahub/core/schema/definitions/core/propose_change.py +97 -0
- infrahub/core/schema/definitions/core/propose_change_comment.py +193 -0
- infrahub/core/schema/definitions/core/propose_change_validator.py +328 -0
- infrahub/core/schema/definitions/core/repository.py +286 -0
- infrahub/core/schema/definitions/core/resource_pool.py +170 -0
- infrahub/core/schema/definitions/core/template.py +27 -0
- infrahub/core/schema/definitions/core/transform.py +96 -0
- infrahub/core/schema/definitions/core/webhook.py +134 -0
- infrahub/core/schema/definitions/internal.py +16 -16
- infrahub/core/schema/dropdown.py +3 -4
- infrahub/core/schema/generated/attribute_schema.py +15 -18
- infrahub/core/schema/generated/base_node_schema.py +12 -14
- infrahub/core/schema/generated/node_schema.py +3 -5
- infrahub/core/schema/generated/relationship_schema.py +9 -11
- infrahub/core/schema/generic_schema.py +2 -2
- infrahub/core/schema/manager.py +20 -9
- infrahub/core/schema/node_schema.py +4 -2
- infrahub/core/schema/relationship_schema.py +14 -6
- infrahub/core/schema/schema_branch.py +292 -144
- infrahub/core/schema/schema_branch_computed.py +41 -4
- infrahub/core/task/task.py +3 -3
- infrahub/core/task/user_task.py +15 -15
- infrahub/core/timestamp.py +3 -3
- infrahub/core/utils.py +20 -18
- infrahub/core/validators/__init__.py +1 -3
- infrahub/core/validators/aggregated_checker.py +2 -2
- infrahub/core/validators/attribute/choices.py +2 -2
- infrahub/core/validators/attribute/enum.py +2 -2
- infrahub/core/validators/attribute/kind.py +2 -2
- infrahub/core/validators/attribute/length.py +2 -2
- infrahub/core/validators/attribute/optional.py +2 -2
- infrahub/core/validators/attribute/regex.py +2 -2
- infrahub/core/validators/attribute/unique.py +2 -2
- infrahub/core/validators/checks_runner.py +25 -2
- infrahub/core/validators/determiner.py +1 -3
- infrahub/core/validators/interface.py +6 -2
- infrahub/core/validators/model.py +22 -3
- infrahub/core/validators/models/validate_migration.py +17 -4
- infrahub/core/validators/node/attribute.py +2 -2
- infrahub/core/validators/node/generate_profile.py +2 -2
- infrahub/core/validators/node/hierarchy.py +3 -5
- infrahub/core/validators/node/inherit_from.py +27 -5
- infrahub/core/validators/node/relationship.py +2 -2
- infrahub/core/validators/relationship/count.py +4 -4
- infrahub/core/validators/relationship/optional.py +2 -2
- infrahub/core/validators/relationship/peer.py +2 -2
- infrahub/core/validators/shared.py +2 -2
- infrahub/core/validators/tasks.py +8 -0
- infrahub/core/validators/uniqueness/checker.py +22 -21
- infrahub/core/validators/uniqueness/index.py +2 -2
- infrahub/core/validators/uniqueness/model.py +11 -11
- infrahub/database/__init__.py +27 -22
- infrahub/database/metrics.py +7 -1
- infrahub/dependencies/builder/constraint/grouped/node_runner.py +1 -3
- infrahub/dependencies/builder/diff/deserializer.py +3 -1
- infrahub/dependencies/builder/diff/enricher/hierarchy.py +3 -1
- infrahub/dependencies/builder/diff/parent_node_adder.py +8 -0
- infrahub/dependencies/component/registry.py +2 -2
- infrahub/events/__init__.py +25 -2
- infrahub/events/artifact_action.py +64 -0
- infrahub/events/branch_action.py +33 -22
- infrahub/events/generator.py +71 -0
- infrahub/events/group_action.py +51 -21
- infrahub/events/models.py +18 -19
- infrahub/events/node_action.py +88 -37
- infrahub/events/repository_action.py +5 -18
- infrahub/events/schema_action.py +4 -9
- infrahub/events/utils.py +16 -0
- infrahub/events/validator_action.py +55 -0
- infrahub/exceptions.py +32 -24
- infrahub/generators/models.py +2 -3
- infrahub/generators/tasks.py +24 -4
- infrahub/git/base.py +7 -7
- infrahub/git/integrator.py +48 -24
- infrahub/git/models.py +101 -9
- infrahub/git/repository.py +3 -3
- infrahub/git/tasks.py +408 -6
- infrahub/git/utils.py +48 -0
- infrahub/git/worktree.py +1 -2
- infrahub/git_credential/askpass.py +1 -2
- infrahub/graphql/analyzer.py +12 -0
- infrahub/graphql/app.py +13 -15
- infrahub/graphql/context.py +39 -0
- infrahub/graphql/initialization.py +3 -0
- infrahub/graphql/loaders/node.py +2 -12
- infrahub/graphql/loaders/peers.py +77 -0
- infrahub/graphql/loaders/shared.py +13 -0
- infrahub/graphql/manager.py +17 -19
- infrahub/graphql/mutations/artifact_definition.py +5 -5
- infrahub/graphql/mutations/branch.py +26 -1
- infrahub/graphql/mutations/computed_attribute.py +9 -5
- infrahub/graphql/mutations/diff.py +23 -11
- infrahub/graphql/mutations/diff_conflict.py +5 -0
- infrahub/graphql/mutations/generator.py +83 -0
- infrahub/graphql/mutations/graphql_query.py +5 -5
- infrahub/graphql/mutations/ipam.py +54 -74
- infrahub/graphql/mutations/main.py +195 -132
- infrahub/graphql/mutations/menu.py +7 -7
- infrahub/graphql/mutations/models.py +2 -4
- infrahub/graphql/mutations/node_getter/by_default_filter.py +10 -10
- infrahub/graphql/mutations/node_getter/by_hfid.py +1 -3
- infrahub/graphql/mutations/node_getter/by_id.py +1 -3
- infrahub/graphql/mutations/node_getter/interface.py +1 -2
- infrahub/graphql/mutations/proposed_change.py +7 -7
- infrahub/graphql/mutations/relationship.py +93 -19
- infrahub/graphql/mutations/repository.py +8 -8
- infrahub/graphql/mutations/resource_manager.py +3 -3
- infrahub/graphql/mutations/schema.py +19 -4
- infrahub/graphql/mutations/webhook.py +137 -0
- infrahub/graphql/parser.py +4 -4
- infrahub/graphql/permissions.py +1 -10
- infrahub/graphql/queries/diff/tree.py +19 -14
- infrahub/graphql/queries/event.py +5 -2
- infrahub/graphql/queries/ipam.py +2 -2
- infrahub/graphql/queries/relationship.py +2 -2
- infrahub/graphql/queries/search.py +2 -2
- infrahub/graphql/resolvers/many_relationship.py +264 -0
- infrahub/graphql/resolvers/resolver.py +13 -110
- infrahub/graphql/schema.py +2 -0
- infrahub/graphql/subscription/graphql_query.py +2 -0
- infrahub/graphql/types/context.py +12 -0
- infrahub/graphql/types/event.py +84 -17
- infrahub/graphql/types/node.py +2 -2
- infrahub/graphql/utils.py +2 -2
- infrahub/groups/ancestors.py +29 -0
- infrahub/groups/parsers.py +107 -0
- infrahub/lock.py +20 -20
- infrahub/menu/constants.py +0 -1
- infrahub/menu/generator.py +9 -21
- infrahub/menu/menu.py +17 -38
- infrahub/menu/models.py +117 -16
- infrahub/menu/repository.py +111 -0
- infrahub/menu/utils.py +5 -8
- infrahub/message_bus/__init__.py +11 -13
- infrahub/message_bus/messages/__init__.py +1 -21
- infrahub/message_bus/messages/check_generator_run.py +3 -3
- infrahub/message_bus/messages/finalize_validator_execution.py +3 -0
- infrahub/message_bus/messages/proposed_change/request_proposedchange_refreshartifacts.py +6 -0
- infrahub/message_bus/messages/request_generatordefinition_check.py +2 -0
- infrahub/message_bus/messages/send_echo_request.py +1 -1
- infrahub/message_bus/operations/__init__.py +1 -10
- infrahub/message_bus/operations/check/__init__.py +2 -2
- infrahub/message_bus/operations/check/generator.py +1 -0
- infrahub/message_bus/operations/event/__init__.py +2 -2
- infrahub/message_bus/operations/event/worker.py +0 -3
- infrahub/message_bus/operations/finalize/validator.py +51 -1
- infrahub/message_bus/operations/requests/__init__.py +0 -2
- infrahub/message_bus/operations/requests/generator_definition.py +21 -23
- infrahub/message_bus/operations/requests/proposed_change.py +14 -10
- infrahub/permissions/globals.py +15 -0
- infrahub/pools/number.py +2 -4
- infrahub/proposed_change/models.py +3 -0
- infrahub/proposed_change/tasks.py +58 -45
- infrahub/pytest_plugin.py +13 -10
- infrahub/server.py +2 -3
- infrahub/services/__init__.py +2 -2
- infrahub/services/adapters/cache/__init__.py +4 -6
- infrahub/services/adapters/cache/nats.py +4 -5
- infrahub/services/adapters/cache/redis.py +3 -7
- infrahub/services/adapters/event/__init__.py +1 -1
- infrahub/services/adapters/message_bus/__init__.py +3 -3
- infrahub/services/adapters/message_bus/local.py +2 -2
- infrahub/services/adapters/message_bus/nats.py +4 -4
- infrahub/services/adapters/message_bus/rabbitmq.py +4 -4
- infrahub/services/adapters/workflow/local.py +2 -2
- infrahub/services/component.py +5 -5
- infrahub/services/protocols.py +7 -7
- infrahub/services/scheduler.py +1 -3
- infrahub/task_manager/event.py +102 -9
- infrahub/task_manager/models.py +27 -7
- infrahub/tasks/artifact.py +7 -6
- infrahub/telemetry/__init__.py +0 -0
- infrahub/telemetry/constants.py +9 -0
- infrahub/telemetry/database.py +86 -0
- infrahub/telemetry/models.py +65 -0
- infrahub/telemetry/task_manager.py +77 -0
- infrahub/{tasks/telemetry.py → telemetry/tasks.py} +49 -56
- infrahub/telemetry/utils.py +11 -0
- infrahub/trace.py +4 -4
- infrahub/transformations/tasks.py +2 -2
- infrahub/trigger/catalogue.py +4 -6
- infrahub/trigger/constants.py +0 -8
- infrahub/trigger/models.py +54 -5
- infrahub/trigger/setup.py +90 -0
- infrahub/trigger/tasks.py +35 -84
- infrahub/utils.py +11 -1
- infrahub/validators/__init__.py +0 -0
- infrahub/validators/events.py +42 -0
- infrahub/validators/tasks.py +41 -0
- infrahub/webhook/gather.py +17 -0
- infrahub/webhook/models.py +176 -44
- infrahub/webhook/tasks.py +154 -155
- infrahub/webhook/triggers.py +31 -7
- infrahub/workers/infrahub_async.py +2 -2
- infrahub/workers/utils.py +2 -2
- infrahub/workflows/catalogue.py +86 -35
- infrahub/workflows/initialization.py +8 -2
- infrahub/workflows/models.py +27 -1
- infrahub/workflows/utils.py +10 -1
- infrahub_sdk/client.py +35 -8
- infrahub_sdk/config.py +3 -0
- infrahub_sdk/context.py +13 -0
- infrahub_sdk/ctl/branch.py +3 -2
- infrahub_sdk/ctl/cli_commands.py +5 -1
- infrahub_sdk/ctl/utils.py +0 -16
- infrahub_sdk/exceptions.py +12 -0
- infrahub_sdk/generator.py +4 -1
- infrahub_sdk/graphql.py +45 -13
- infrahub_sdk/node.py +71 -22
- infrahub_sdk/protocols.py +21 -8
- infrahub_sdk/protocols_base.py +32 -11
- infrahub_sdk/query_groups.py +6 -35
- infrahub_sdk/schema/__init__.py +55 -26
- infrahub_sdk/schema/main.py +8 -0
- infrahub_sdk/task/__init__.py +11 -0
- infrahub_sdk/task/constants.py +3 -0
- infrahub_sdk/task/exceptions.py +25 -0
- infrahub_sdk/task/manager.py +551 -0
- infrahub_sdk/task/models.py +74 -0
- infrahub_sdk/testing/schemas/animal.py +9 -0
- infrahub_sdk/timestamp.py +142 -33
- infrahub_sdk/utils.py +29 -1
- {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/METADATA +8 -6
- {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/RECORD +349 -293
- {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/entry_points.txt +1 -0
- infrahub_testcontainers/constants.py +2 -0
- infrahub_testcontainers/container.py +157 -12
- infrahub_testcontainers/docker-compose.test.yml +31 -6
- infrahub_testcontainers/helpers.py +18 -73
- infrahub_testcontainers/host.py +41 -0
- infrahub_testcontainers/measurements.py +93 -0
- infrahub_testcontainers/models.py +38 -0
- infrahub_testcontainers/performance_test.py +166 -0
- infrahub_testcontainers/plugin.py +136 -0
- infrahub_testcontainers/prometheus.yml +30 -0
- infrahub/core/schema/definitions/core.py +0 -2286
- infrahub/message_bus/messages/check_repository_checkdefinition.py +0 -20
- infrahub/message_bus/messages/check_repository_mergeconflicts.py +0 -16
- infrahub/message_bus/messages/check_repository_usercheck.py +0 -26
- infrahub/message_bus/messages/event_branch_create.py +0 -11
- infrahub/message_bus/messages/event_branch_delete.py +0 -11
- infrahub/message_bus/messages/event_branch_rebased.py +0 -9
- infrahub/message_bus/messages/event_node_mutated.py +0 -15
- infrahub/message_bus/messages/event_schema_update.py +0 -9
- infrahub/message_bus/messages/request_repository_checks.py +0 -12
- infrahub/message_bus/messages/request_repository_userchecks.py +0 -18
- infrahub/message_bus/operations/check/repository.py +0 -293
- infrahub/message_bus/operations/event/node.py +0 -20
- infrahub/message_bus/operations/event/schema.py +0 -17
- infrahub/message_bus/operations/requests/repository.py +0 -133
- infrahub/webhook/constants.py +0 -1
- {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/WHEEL +0 -0
|
@@ -1,51 +1,38 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from typing import TYPE_CHECKING, Any
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
5
4
|
|
|
6
|
-
import ujson
|
|
7
5
|
from infrahub_sdk.protocols import (
|
|
8
6
|
CoreNode, # noqa: TC002
|
|
9
7
|
CoreTransformPython,
|
|
10
8
|
)
|
|
11
9
|
from prefect import flow
|
|
12
|
-
from prefect.automations import AutomationCore
|
|
13
10
|
from prefect.client.orchestration import get_client
|
|
14
|
-
from prefect.client.schemas.filters import DeploymentFilter, DeploymentFilterName
|
|
15
|
-
from prefect.events.actions import (
|
|
16
|
-
RunDeployment,
|
|
17
|
-
)
|
|
18
|
-
from prefect.events.schemas.automations import EventTrigger, Posture
|
|
19
|
-
from prefect.events.schemas.events import ResourceSpecification
|
|
20
11
|
from prefect.logging import get_run_logger
|
|
21
12
|
|
|
22
13
|
from infrahub.context import InfrahubContext # noqa: TC001 needed for prefect flow
|
|
23
14
|
from infrahub.core.constants import ComputedAttributeKind, InfrahubKind
|
|
24
15
|
from infrahub.core.registry import registry
|
|
16
|
+
from infrahub.events import BranchDeletedEvent
|
|
25
17
|
from infrahub.git.repository import get_initialized_repo
|
|
26
18
|
from infrahub.services import InfrahubServices # noqa: TC001 needed for prefect flow
|
|
27
19
|
from infrahub.support.macro import MacroDefinition
|
|
20
|
+
from infrahub.trigger.models import TriggerType
|
|
21
|
+
from infrahub.trigger.setup import setup_triggers
|
|
28
22
|
from infrahub.workflows.catalogue import (
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
COMPUTED_ATTRIBUTE_PROCESS_JINJA2,
|
|
24
|
+
COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
|
|
31
25
|
TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
|
|
32
26
|
TRIGGER_UPDATE_PYTHON_COMPUTED_ATTRIBUTES,
|
|
33
|
-
UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM,
|
|
34
27
|
)
|
|
35
28
|
from infrahub.workflows.utils import add_tags, wait_for_schema_to_converge
|
|
36
29
|
|
|
37
|
-
from .
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
PROCESS_PYTHON_AUTOMATION_NAME_PREFIX,
|
|
41
|
-
QUERY_AUTOMATION_NAME,
|
|
42
|
-
QUERY_AUTOMATION_NAME_PREFIX,
|
|
30
|
+
from .gather import gather_trigger_computed_attribute_jinja2, gather_trigger_computed_attribute_python
|
|
31
|
+
from .models import (
|
|
32
|
+
PythonTransformTarget,
|
|
43
33
|
)
|
|
44
|
-
from .models import ComputedAttributeAutomations, PythonTransformComputedAttribute, PythonTransformTarget
|
|
45
34
|
|
|
46
35
|
if TYPE_CHECKING:
|
|
47
|
-
import logging
|
|
48
|
-
|
|
49
36
|
from infrahub.core.schema.computed_attribute import ComputedAttribute
|
|
50
37
|
|
|
51
38
|
UPDATE_ATTRIBUTE = """
|
|
@@ -65,7 +52,7 @@ mutation UpdateAttribute(
|
|
|
65
52
|
|
|
66
53
|
|
|
67
54
|
@flow(
|
|
68
|
-
name="
|
|
55
|
+
name="computed_attribute_process_transform",
|
|
69
56
|
flow_run_name="Process computed attribute for {computed_attribute_kind}.{computed_attribute_name}",
|
|
70
57
|
)
|
|
71
58
|
async def process_transform(
|
|
@@ -115,7 +102,7 @@ async def process_transform(
|
|
|
115
102
|
service=service,
|
|
116
103
|
repository_kind=str(transform.repository.peer.typename),
|
|
117
104
|
commit=repo_node.commit.value,
|
|
118
|
-
)
|
|
105
|
+
) # type: ignore[misc]
|
|
119
106
|
|
|
120
107
|
data = await service.client.query_gql_query(
|
|
121
108
|
name=transform.query.peer.name.value,
|
|
@@ -131,7 +118,7 @@ async def process_transform(
|
|
|
131
118
|
location=f"{transform.file_path.value}::{transform.class_name.value}",
|
|
132
119
|
data=data,
|
|
133
120
|
client=service.client,
|
|
134
|
-
)
|
|
121
|
+
) # type: ignore[misc]
|
|
135
122
|
|
|
136
123
|
await service.client.execute_graphql(
|
|
137
124
|
query=UPDATE_ATTRIBUTE,
|
|
@@ -162,7 +149,7 @@ async def trigger_update_python_computed_attributes(
|
|
|
162
149
|
|
|
163
150
|
for node in nodes:
|
|
164
151
|
await service.workflow.submit_workflow(
|
|
165
|
-
workflow=
|
|
152
|
+
workflow=COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
|
|
166
153
|
context=context,
|
|
167
154
|
parameters={
|
|
168
155
|
"branch_name": branch_name,
|
|
@@ -226,7 +213,7 @@ async def update_computed_attribute_value_jinja2(
|
|
|
226
213
|
|
|
227
214
|
|
|
228
215
|
@flow(
|
|
229
|
-
name="
|
|
216
|
+
name="computed_attribute_process_jinja2",
|
|
230
217
|
flow_run_name="Process computed attribute for {computed_attribute_kind}.{computed_attribute_name}",
|
|
231
218
|
)
|
|
232
219
|
async def process_jinja2(
|
|
@@ -237,20 +224,18 @@ async def process_jinja2(
|
|
|
237
224
|
computed_attribute_kind: str,
|
|
238
225
|
context: InfrahubContext, # noqa: ARG001
|
|
239
226
|
service: InfrahubServices,
|
|
240
|
-
updated_fields: str | None = None,
|
|
227
|
+
updated_fields: list[str] | None = None,
|
|
241
228
|
) -> None:
|
|
242
229
|
log = get_run_logger()
|
|
243
230
|
|
|
244
231
|
await add_tags(branches=[branch_name])
|
|
245
|
-
updates: list[str] = []
|
|
246
|
-
if isinstance(updated_fields, str):
|
|
247
|
-
updates = ujson.loads(updated_fields)
|
|
232
|
+
updates: list[str] = updated_fields or []
|
|
248
233
|
|
|
249
234
|
target_branch_schema = (
|
|
250
235
|
branch_name if branch_name in registry.get_altered_schema_branches() else registry.default_branch
|
|
251
236
|
)
|
|
252
237
|
schema_branch = registry.schema.get_schema_branch(name=target_branch_schema)
|
|
253
|
-
await service.client.schema.all(branch=branch_name, refresh=True)
|
|
238
|
+
await service.client.schema.all(branch=branch_name, refresh=True, schema_hash=schema_branch.get_hash())
|
|
254
239
|
|
|
255
240
|
computed_macros = [
|
|
256
241
|
attrib
|
|
@@ -304,11 +289,12 @@ async def trigger_update_jinja2_computed_attributes(
|
|
|
304
289
|
) -> None:
|
|
305
290
|
await add_tags(branches=[branch_name])
|
|
306
291
|
|
|
292
|
+
# NOTE we only need the id of the nodes, we need to ooptimize the query here
|
|
307
293
|
nodes = await service.client.all(kind=computed_attribute_kind, branch=branch_name)
|
|
308
294
|
|
|
309
295
|
for node in nodes:
|
|
310
296
|
await service.workflow.submit_workflow(
|
|
311
|
-
workflow=
|
|
297
|
+
workflow=COMPUTED_ATTRIBUTE_PROCESS_JINJA2,
|
|
312
298
|
context=context,
|
|
313
299
|
parameters={
|
|
314
300
|
"branch_name": branch_name,
|
|
@@ -321,183 +307,39 @@ async def trigger_update_jinja2_computed_attributes(
|
|
|
321
307
|
)
|
|
322
308
|
|
|
323
309
|
|
|
324
|
-
@flow(name="computed-attribute-setup", flow_run_name="Setup computed attributes in task-manager")
|
|
325
|
-
async def
|
|
326
|
-
service: InfrahubServices, context: InfrahubContext, branch_name: str | None = None
|
|
310
|
+
@flow(name="computed-attribute-setup-jinja2", flow_run_name="Setup computed attributes in task-manager")
|
|
311
|
+
async def computed_attribute_setup_jinja2(
|
|
312
|
+
service: InfrahubServices, context: InfrahubContext, branch_name: str | None = None, event_name: str | None = None
|
|
327
313
|
) -> None:
|
|
328
|
-
branch_name = branch_name or registry.default_branch
|
|
329
|
-
|
|
330
|
-
await add_tags(branches=[branch_name])
|
|
331
|
-
|
|
332
314
|
log = get_run_logger()
|
|
333
|
-
await wait_for_schema_to_converge(branch_name=branch_name, service=service, log=log)
|
|
334
315
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
316
|
+
if branch_name:
|
|
317
|
+
await add_tags(branches=[branch_name])
|
|
318
|
+
await wait_for_schema_to_converge(branch_name=branch_name, service=service, log=log)
|
|
319
|
+
|
|
320
|
+
triggers = await gather_trigger_computed_attribute_jinja2()
|
|
321
|
+
|
|
322
|
+
for trigger in triggers:
|
|
323
|
+
if event_name != BranchDeletedEvent.event_name and trigger.branch == branch_name:
|
|
324
|
+
await service.workflow.submit_workflow(
|
|
325
|
+
workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
|
|
326
|
+
context=context,
|
|
327
|
+
parameters={
|
|
328
|
+
"branch_name": trigger.branch,
|
|
329
|
+
"computed_attribute_name": trigger.computed_attribute.attribute.name,
|
|
330
|
+
"computed_attribute_kind": trigger.computed_attribute.kind,
|
|
331
|
+
},
|
|
343
332
|
)
|
|
344
|
-
}
|
|
345
|
-
if PROCESS_COMPUTED_MACRO.name not in deployments:
|
|
346
|
-
raise ValueError("Unable to find the deployment for PROCESS_COMPUTED_MACRO")
|
|
347
333
|
|
|
348
|
-
|
|
334
|
+
# Configure all ComputedAttrJinja2Trigger in Prefect
|
|
335
|
+
async with get_client(sync_client=False) as prefect_client:
|
|
336
|
+
await setup_triggers(
|
|
337
|
+
client=prefect_client,
|
|
338
|
+
triggers=triggers,
|
|
339
|
+
trigger_type=TriggerType.COMPUTED_ATTR_JINJA2,
|
|
340
|
+
) # type: ignore[misc]
|
|
349
341
|
|
|
350
|
-
|
|
351
|
-
existing_computed_attr_automations = ComputedAttributeAutomations.from_prefect(
|
|
352
|
-
automations=automations, prefix=PROCESS_JINJA2_AUTOMATION_NAME_PREFIX
|
|
353
|
-
)
|
|
354
|
-
automations_to_keep = []
|
|
355
|
-
mapping = schema_branch.computed_attributes.get_jinja2_target_map()
|
|
356
|
-
for computed_attribute, source_node_types in mapping.items():
|
|
357
|
-
log.info(f"processing {computed_attribute.key_name}")
|
|
358
|
-
scope = registry.default_branch
|
|
359
|
-
|
|
360
|
-
match_criteria: dict[str, Any] = {"infrahub.node.kind": source_node_types}
|
|
361
|
-
if branches_with_diff_from_main:
|
|
362
|
-
match_criteria["infrahub.branch.name"] = [f"!{branch}" for branch in branches_with_diff_from_main]
|
|
363
|
-
|
|
364
|
-
automation = AutomationCore(
|
|
365
|
-
name=PROCESS_AUTOMATION_NAME.format(
|
|
366
|
-
prefix=PROCESS_JINJA2_AUTOMATION_NAME_PREFIX, identifier=computed_attribute.key_name, scope=scope
|
|
367
|
-
),
|
|
368
|
-
description=f"Process value of the computed attribute for {computed_attribute.key_name} [{scope}] and branches with the same schema",
|
|
369
|
-
enabled=True,
|
|
370
|
-
trigger=EventTrigger(
|
|
371
|
-
posture=Posture.Reactive,
|
|
372
|
-
expect={"infrahub.node.*"},
|
|
373
|
-
within=timedelta(0),
|
|
374
|
-
match=ResourceSpecification(match_criteria),
|
|
375
|
-
threshold=1,
|
|
376
|
-
),
|
|
377
|
-
actions=[
|
|
378
|
-
RunDeployment(
|
|
379
|
-
source="selected",
|
|
380
|
-
deployment_id=deployment_id_jinja,
|
|
381
|
-
parameters={
|
|
382
|
-
"branch_name": "{{ event.resource['infrahub.branch.name'] }}",
|
|
383
|
-
"node_kind": "{{ event.resource['infrahub.node.kind'] }}",
|
|
384
|
-
"object_id": "{{ event.resource['infrahub.node.id'] }}",
|
|
385
|
-
"computed_attribute_name": computed_attribute.attribute.name,
|
|
386
|
-
"computed_attribute_kind": computed_attribute.kind,
|
|
387
|
-
"updated_fields": "{{ event.payload['fields'] | tojson }}",
|
|
388
|
-
"context": {
|
|
389
|
-
"__prefect_kind": "json",
|
|
390
|
-
"value": {
|
|
391
|
-
"__prefect_kind": "jinja",
|
|
392
|
-
"template": "{{ event.payload['context'] | tojson }}",
|
|
393
|
-
},
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
job_variables={},
|
|
397
|
-
)
|
|
398
|
-
],
|
|
399
|
-
)
|
|
400
|
-
|
|
401
|
-
if existing_computed_attr_automations.has(identifier=computed_attribute.key_name, scope=scope):
|
|
402
|
-
existing = existing_computed_attr_automations.get(identifier=computed_attribute.key_name, scope=scope)
|
|
403
|
-
await client.update_automation(automation_id=existing.id, automation=automation)
|
|
404
|
-
automations_to_keep.append(existing.id)
|
|
405
|
-
log.info(f"{computed_attribute.key_name} Updated")
|
|
406
|
-
else:
|
|
407
|
-
automation_id = await client.create_automation(automation=automation)
|
|
408
|
-
automations_to_keep.append(automation_id)
|
|
409
|
-
log.info(f"{computed_attribute.key_name} Created")
|
|
410
|
-
|
|
411
|
-
if branch_name == registry.default_branch:
|
|
412
|
-
await service.workflow.submit_workflow(
|
|
413
|
-
workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
|
|
414
|
-
context=context,
|
|
415
|
-
parameters={
|
|
416
|
-
"branch_name": registry.default_branch,
|
|
417
|
-
"computed_attribute_name": computed_attribute.attribute.name,
|
|
418
|
-
"computed_attribute_kind": computed_attribute.kind,
|
|
419
|
-
"context": context,
|
|
420
|
-
},
|
|
421
|
-
)
|
|
422
|
-
|
|
423
|
-
for diff_branch in branches_with_diff_from_main:
|
|
424
|
-
schema_branch = registry.schema.get_schema_branch(name=diff_branch)
|
|
425
|
-
|
|
426
|
-
mapping = schema_branch.computed_attributes.get_jinja2_target_map()
|
|
427
|
-
for computed_attribute, source_node_types in mapping.items():
|
|
428
|
-
log.info(f"processing {computed_attribute.key_name}")
|
|
429
|
-
|
|
430
|
-
automation = AutomationCore(
|
|
431
|
-
name=PROCESS_AUTOMATION_NAME.format(
|
|
432
|
-
prefix=PROCESS_PYTHON_AUTOMATION_NAME_PREFIX,
|
|
433
|
-
identifier=computed_attribute.key_name,
|
|
434
|
-
scope=diff_branch,
|
|
435
|
-
),
|
|
436
|
-
description=f"Process value of the computed attribute for {computed_attribute.key_name} [{diff_branch}]",
|
|
437
|
-
enabled=True,
|
|
438
|
-
trigger=EventTrigger(
|
|
439
|
-
posture=Posture.Reactive,
|
|
440
|
-
expect={"infrahub.node.*"},
|
|
441
|
-
within=timedelta(0),
|
|
442
|
-
match=ResourceSpecification(
|
|
443
|
-
{
|
|
444
|
-
"infrahub.node.kind": source_node_types,
|
|
445
|
-
"infrahub.branch.name": diff_branch,
|
|
446
|
-
}
|
|
447
|
-
),
|
|
448
|
-
threshold=1,
|
|
449
|
-
),
|
|
450
|
-
actions=[
|
|
451
|
-
RunDeployment(
|
|
452
|
-
source="selected",
|
|
453
|
-
deployment_id=deployment_id_jinja,
|
|
454
|
-
parameters={
|
|
455
|
-
"branch_name": "{{ event.resource['infrahub.branch.name'] }}",
|
|
456
|
-
"node_kind": "{{ event.resource['infrahub.node.kind'] }}",
|
|
457
|
-
"object_id": "{{ event.resource['infrahub.node.id'] }}",
|
|
458
|
-
"computed_attribute_name": computed_attribute.attribute.name,
|
|
459
|
-
"computed_attribute_kind": computed_attribute.kind,
|
|
460
|
-
"updated_fields": "{{ event.payload['fields'] | tojson }}",
|
|
461
|
-
"context": {
|
|
462
|
-
"__prefect_kind": "json",
|
|
463
|
-
"value": {
|
|
464
|
-
"__prefect_kind": "jinja",
|
|
465
|
-
"template": "{{ event.payload['context'] | tojson }}",
|
|
466
|
-
},
|
|
467
|
-
},
|
|
468
|
-
},
|
|
469
|
-
job_variables={},
|
|
470
|
-
)
|
|
471
|
-
],
|
|
472
|
-
)
|
|
473
|
-
|
|
474
|
-
if existing_computed_attr_automations.has(identifier=computed_attribute.key_name, scope=diff_branch):
|
|
475
|
-
existing = existing_computed_attr_automations.get(
|
|
476
|
-
identifier=computed_attribute.key_name, scope=diff_branch
|
|
477
|
-
)
|
|
478
|
-
await client.update_automation(automation_id=existing.id, automation=automation)
|
|
479
|
-
automations_to_keep.append(existing.id)
|
|
480
|
-
log.info(f"{computed_attribute.key_name} Updated")
|
|
481
|
-
else:
|
|
482
|
-
automation_id = await client.create_automation(automation=automation)
|
|
483
|
-
automations_to_keep.append(automation_id)
|
|
484
|
-
log.info(f"{computed_attribute.key_name} Created")
|
|
485
|
-
|
|
486
|
-
if branch_name == diff_branch:
|
|
487
|
-
await service.workflow.submit_workflow(
|
|
488
|
-
workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
|
|
489
|
-
context=context,
|
|
490
|
-
parameters={
|
|
491
|
-
"branch_name": branch_name,
|
|
492
|
-
"computed_attribute_name": computed_attribute.attribute.name,
|
|
493
|
-
"computed_attribute_kind": computed_attribute.kind,
|
|
494
|
-
"context": context,
|
|
495
|
-
},
|
|
496
|
-
)
|
|
497
|
-
|
|
498
|
-
automations_to_remove = existing_computed_attr_automations.return_obsolete(keep=automations_to_keep)
|
|
499
|
-
for automation_to_remove in automations_to_remove:
|
|
500
|
-
await client.delete_automation(automation_id=automation_to_remove)
|
|
342
|
+
log.info(f"{len(triggers)} Computed Attribute for Jinja2 automation configuration completed")
|
|
501
343
|
|
|
502
344
|
|
|
503
345
|
@flow(
|
|
@@ -508,205 +350,48 @@ async def computed_attribute_setup_python(
|
|
|
508
350
|
service: InfrahubServices,
|
|
509
351
|
context: InfrahubContext,
|
|
510
352
|
branch_name: str | None = None,
|
|
353
|
+
event_name: str | None = None,
|
|
511
354
|
commit: str | None = None, # noqa: ARG001
|
|
512
|
-
trigger_updates: bool = True,
|
|
513
355
|
) -> None:
|
|
514
356
|
log = get_run_logger()
|
|
515
357
|
|
|
516
358
|
branch_name = branch_name or registry.default_branch
|
|
517
359
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
360
|
+
if branch_name:
|
|
361
|
+
await add_tags(branches=[branch_name])
|
|
362
|
+
await wait_for_schema_to_converge(branch_name=branch_name, service=service, log=log)
|
|
521
363
|
|
|
522
|
-
|
|
364
|
+
triggers_python, triggers_python_query = await gather_trigger_computed_attribute_python(db=service.database)
|
|
523
365
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
deployment_filter=DeploymentFilter(
|
|
529
|
-
name=DeploymentFilterName(
|
|
530
|
-
any_=[UPDATE_COMPUTED_ATTRIBUTE_TRANSFORM.name, QUERY_COMPUTED_ATTRIBUTE_TRANSFORM_TARGETS.name]
|
|
531
|
-
)
|
|
532
|
-
)
|
|
366
|
+
for trigger in triggers_python:
|
|
367
|
+
if event_name != BranchDeletedEvent.event_name and trigger.branch == branch_name:
|
|
368
|
+
log.info(
|
|
369
|
+
f"Triggering update for {trigger.computed_attribute.computed_attribute.attribute.name} on {branch_name}"
|
|
533
370
|
)
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
automations = await client.read_automations()
|
|
544
|
-
existing_computed_attr_process_automations = ComputedAttributeAutomations.from_prefect(
|
|
545
|
-
automations=automations, prefix=f"{PROCESS_PYTHON_AUTOMATION_NAME_PREFIX}::{branch_name}::"
|
|
546
|
-
)
|
|
547
|
-
existing_computed_attr_query_automations = ComputedAttributeAutomations.from_prefect(
|
|
548
|
-
automations=automations, prefix=f"{QUERY_AUTOMATION_NAME_PREFIX}::{branch_name}::"
|
|
549
|
-
)
|
|
550
|
-
|
|
551
|
-
automations_to_keep = []
|
|
552
|
-
for computed_attribute in computed_attributes:
|
|
553
|
-
log.info(f"processing {computed_attribute.computed_attribute.key_name}")
|
|
554
|
-
scope = branch_name
|
|
555
|
-
|
|
556
|
-
automation = AutomationCore(
|
|
557
|
-
name=PROCESS_AUTOMATION_NAME.format(
|
|
558
|
-
prefix=PROCESS_PYTHON_AUTOMATION_NAME_PREFIX,
|
|
559
|
-
identifier=computed_attribute.computed_attribute.key_name,
|
|
560
|
-
scope=scope,
|
|
561
|
-
),
|
|
562
|
-
description=f"Process value of the computed attribute for {computed_attribute.computed_attribute.key_name} [{scope}]",
|
|
563
|
-
enabled=True,
|
|
564
|
-
trigger=EventTrigger(
|
|
565
|
-
posture=Posture.Reactive,
|
|
566
|
-
expect={"infrahub.node.*"},
|
|
567
|
-
within=timedelta(0),
|
|
568
|
-
match=ResourceSpecification(
|
|
569
|
-
{
|
|
570
|
-
"infrahub.node.kind": [computed_attribute.computed_attribute.kind],
|
|
571
|
-
"infrahub.branch.name": branch_name,
|
|
572
|
-
}
|
|
573
|
-
),
|
|
574
|
-
threshold=1,
|
|
575
|
-
),
|
|
576
|
-
actions=[
|
|
577
|
-
RunDeployment(
|
|
578
|
-
source="selected",
|
|
579
|
-
deployment_id=deployment_id_python,
|
|
580
|
-
parameters={
|
|
581
|
-
"branch_name": "{{ event.resource['infrahub.branch.name'] }}",
|
|
582
|
-
"node_kind": "{{ event.resource['infrahub.node.kind'] }}",
|
|
583
|
-
"object_id": "{{ event.resource['infrahub.node.id'] }}",
|
|
584
|
-
"computed_attribute_name": computed_attribute.computed_attribute.attribute.name,
|
|
585
|
-
"computed_attribute_kind": computed_attribute.computed_attribute.kind,
|
|
586
|
-
"context": {
|
|
587
|
-
"__prefect_kind": "json",
|
|
588
|
-
"value": {
|
|
589
|
-
"__prefect_kind": "jinja",
|
|
590
|
-
"template": "{{ event.payload['context'] | tojson }}",
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
},
|
|
594
|
-
job_variables={},
|
|
595
|
-
)
|
|
596
|
-
],
|
|
371
|
+
await service.workflow.submit_workflow(
|
|
372
|
+
workflow=TRIGGER_UPDATE_PYTHON_COMPUTED_ATTRIBUTES,
|
|
373
|
+
context=context,
|
|
374
|
+
parameters={
|
|
375
|
+
"branch_name": branch_name,
|
|
376
|
+
"computed_attribute_name": trigger.computed_attribute.computed_attribute.attribute.name,
|
|
377
|
+
"computed_attribute_kind": trigger.computed_attribute.computed_attribute.kind,
|
|
378
|
+
},
|
|
597
379
|
)
|
|
598
380
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
log.info(f"Process {computed_attribute.computed_attribute.key_name} Updated")
|
|
607
|
-
automations_to_keep.append(existing.id)
|
|
608
|
-
else:
|
|
609
|
-
automation_id = await client.create_automation(automation=automation)
|
|
610
|
-
automations_to_keep.append(automation_id)
|
|
611
|
-
log.info(f"Process {computed_attribute.computed_attribute.key_name} Created")
|
|
612
|
-
|
|
613
|
-
automation = AutomationCore(
|
|
614
|
-
name=QUERY_AUTOMATION_NAME.format(
|
|
615
|
-
prefix=QUERY_AUTOMATION_NAME_PREFIX,
|
|
616
|
-
identifier=computed_attribute.computed_attribute.key_name,
|
|
617
|
-
scope=scope,
|
|
618
|
-
),
|
|
619
|
-
description=f"Query the computed attribute targets for {computed_attribute.computed_attribute.key_name} [{scope}]",
|
|
620
|
-
enabled=True,
|
|
621
|
-
trigger=EventTrigger(
|
|
622
|
-
posture=Posture.Reactive,
|
|
623
|
-
expect={"infrahub.node.*"},
|
|
624
|
-
within=timedelta(0),
|
|
625
|
-
match=ResourceSpecification(
|
|
626
|
-
{
|
|
627
|
-
"infrahub.node.kind": computed_attribute.query_models,
|
|
628
|
-
"infrahub.branch.name": branch_name,
|
|
629
|
-
}
|
|
630
|
-
),
|
|
631
|
-
threshold=1,
|
|
632
|
-
),
|
|
633
|
-
actions=[
|
|
634
|
-
RunDeployment(
|
|
635
|
-
source="selected",
|
|
636
|
-
deployment_id=deployment_id_query,
|
|
637
|
-
parameters={
|
|
638
|
-
"branch_name": "{{ event.resource['infrahub.branch.name'] }}",
|
|
639
|
-
"node_kind": "{{ event.resource['infrahub.node.kind'] }}",
|
|
640
|
-
"object_id": "{{ event.resource['infrahub.node.id'] }}",
|
|
641
|
-
"context": {
|
|
642
|
-
"__prefect_kind": "json",
|
|
643
|
-
"value": {
|
|
644
|
-
"__prefect_kind": "jinja",
|
|
645
|
-
"template": "{{ event.payload['context'] | tojson }}",
|
|
646
|
-
},
|
|
647
|
-
},
|
|
648
|
-
},
|
|
649
|
-
job_variables={},
|
|
650
|
-
)
|
|
651
|
-
],
|
|
652
|
-
)
|
|
381
|
+
async with get_client(sync_client=False) as prefect_client:
|
|
382
|
+
await setup_triggers(
|
|
383
|
+
client=prefect_client,
|
|
384
|
+
triggers=triggers_python,
|
|
385
|
+
trigger_type=TriggerType.COMPUTED_ATTR_PYTHON,
|
|
386
|
+
) # type: ignore[misc]
|
|
387
|
+
log.info(f"{len(triggers_python)} Computed Attribute for Python automation configuration completed")
|
|
653
388
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
await client.update_automation(automation_id=existing.id, automation=automation)
|
|
661
|
-
automations_to_keep.append(existing.id)
|
|
662
|
-
log.info(f"Query {computed_attribute.computed_attribute.key_name} Updated")
|
|
663
|
-
else:
|
|
664
|
-
automation_id = await client.create_automation(automation=automation)
|
|
665
|
-
automations_to_keep.append(automation_id)
|
|
666
|
-
log.info(f"Query {computed_attribute.computed_attribute.key_name} Created")
|
|
667
|
-
|
|
668
|
-
if trigger_updates:
|
|
669
|
-
await service.workflow.submit_workflow(
|
|
670
|
-
workflow=TRIGGER_UPDATE_PYTHON_COMPUTED_ATTRIBUTES,
|
|
671
|
-
context=context,
|
|
672
|
-
parameters={
|
|
673
|
-
"branch_name": branch_name,
|
|
674
|
-
"computed_attribute_name": computed_attribute.computed_attribute.attribute.name,
|
|
675
|
-
"computed_attribute_kind": computed_attribute.computed_attribute.kind,
|
|
676
|
-
"context": context,
|
|
677
|
-
},
|
|
678
|
-
)
|
|
679
|
-
|
|
680
|
-
automations_to_remove = existing_computed_attr_process_automations.return_obsolete(keep=automations_to_keep)
|
|
681
|
-
for automation_to_remove in automations_to_remove:
|
|
682
|
-
await client.delete_automation(automation_id=automation_to_remove)
|
|
683
|
-
|
|
684
|
-
automations_to_remove = existing_computed_attr_query_automations.return_obsolete(keep=automations_to_keep)
|
|
685
|
-
for automation_to_remove in automations_to_remove:
|
|
686
|
-
await client.delete_automation(automation_id=automation_to_remove)
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
@flow(
|
|
690
|
-
name="computed-attribute-remove-python",
|
|
691
|
-
flow_run_name="Remove Python based computed attributes on branch={branch_name}",
|
|
692
|
-
)
|
|
693
|
-
async def computed_attribute_remove_python(
|
|
694
|
-
branch_name: str,
|
|
695
|
-
) -> None:
|
|
696
|
-
async with get_client(sync_client=False) as client:
|
|
697
|
-
automations = await client.read_automations()
|
|
698
|
-
existing_computed_attr_process_automations = ComputedAttributeAutomations.from_prefect(
|
|
699
|
-
automations=automations, prefix=f"{PROCESS_PYTHON_AUTOMATION_NAME_PREFIX}::{branch_name}::"
|
|
700
|
-
)
|
|
701
|
-
existing_computed_attr_query_automations = ComputedAttributeAutomations.from_prefect(
|
|
702
|
-
automations=automations, prefix=f"{QUERY_AUTOMATION_NAME_PREFIX}::{branch_name}::"
|
|
703
|
-
)
|
|
704
|
-
|
|
705
|
-
for automation_id in existing_computed_attr_process_automations.all_automation_ids:
|
|
706
|
-
await client.delete_automation(automation_id=automation_id)
|
|
707
|
-
|
|
708
|
-
for automation_id in existing_computed_attr_query_automations.all_automation_ids:
|
|
709
|
-
await client.delete_automation(automation_id=automation_id)
|
|
389
|
+
await setup_triggers(
|
|
390
|
+
client=prefect_client,
|
|
391
|
+
triggers=triggers_python_query,
|
|
392
|
+
trigger_type=TriggerType.COMPUTED_ATTR_PYTHON_QUERY,
|
|
393
|
+
) # type: ignore[misc]
|
|
394
|
+
log.info(f"{len(triggers_python_query)} Computed Attribute for Python Query automation configuration completed")
|
|
710
395
|
|
|
711
396
|
|
|
712
397
|
@flow(
|
|
@@ -739,7 +424,7 @@ async def query_transform_targets(
|
|
|
739
424
|
if subscriber.kind in nodes_with_computed_attributes:
|
|
740
425
|
for computed_attribute in nodes_with_computed_attributes[subscriber.kind]:
|
|
741
426
|
await service.workflow.submit_workflow(
|
|
742
|
-
workflow=
|
|
427
|
+
workflow=COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
|
|
743
428
|
context=context,
|
|
744
429
|
parameters={
|
|
745
430
|
"branch_name": branch_name,
|
|
@@ -751,55 +436,6 @@ async def query_transform_targets(
|
|
|
751
436
|
)
|
|
752
437
|
|
|
753
438
|
|
|
754
|
-
async def _gather_python_transform_attributes(
|
|
755
|
-
branch_name: str, service: InfrahubServices, log: logging.Logger | logging.LoggerAdapter
|
|
756
|
-
) -> list[PythonTransformComputedAttribute]:
|
|
757
|
-
schema_branch = registry.schema.get_schema_branch(name=branch_name)
|
|
758
|
-
branches_with_diff_from_main = registry.get_altered_schema_branches()
|
|
759
|
-
|
|
760
|
-
transform_attributes = schema_branch.computed_attributes.python_attributes_by_transform
|
|
761
|
-
|
|
762
|
-
transform_names = list(transform_attributes.keys())
|
|
763
|
-
if not transform_names:
|
|
764
|
-
return []
|
|
765
|
-
|
|
766
|
-
transforms = await service.client.filters(
|
|
767
|
-
kind="CoreTransformPython",
|
|
768
|
-
branch=branch_name,
|
|
769
|
-
prefetch_relationships=True,
|
|
770
|
-
populate_store=True,
|
|
771
|
-
name__values=transform_names,
|
|
772
|
-
)
|
|
773
|
-
|
|
774
|
-
found_transforms_names = [transform.name.value for transform in transforms]
|
|
775
|
-
for transform_name in transform_names:
|
|
776
|
-
if transform_name not in found_transforms_names:
|
|
777
|
-
log.warning(
|
|
778
|
-
msg=f"The transform {transform_name} is assigned to a computed attribute but the transform could not be found in the database."
|
|
779
|
-
)
|
|
780
|
-
|
|
781
|
-
repositories = await service.client.get_list_repositories()
|
|
782
|
-
computed_attributes: list[PythonTransformComputedAttribute] = []
|
|
783
|
-
for transform in transforms:
|
|
784
|
-
for attribute in transform_attributes[transform.name.value]:
|
|
785
|
-
python_transform_computed_attribute = PythonTransformComputedAttribute(
|
|
786
|
-
name=transform.name.value,
|
|
787
|
-
repository_id=transform.repository.peer.id,
|
|
788
|
-
repository_name=transform.repository.peer.name.value,
|
|
789
|
-
repository_kind=transform.repository.peer.typename,
|
|
790
|
-
query_name=transform.query.peer.name.value,
|
|
791
|
-
query_models=transform.query.peer.models.value,
|
|
792
|
-
computed_attribute=attribute,
|
|
793
|
-
default_schema=branch_name not in branches_with_diff_from_main,
|
|
794
|
-
)
|
|
795
|
-
python_transform_computed_attribute.populate_branch_commit(
|
|
796
|
-
repository_data=repositories.get(transform.repository.peer.name.value)
|
|
797
|
-
)
|
|
798
|
-
computed_attributes.append(python_transform_computed_attribute)
|
|
799
|
-
|
|
800
|
-
return computed_attributes
|
|
801
|
-
|
|
802
|
-
|
|
803
439
|
GATHER_GRAPHQL_QUERY_SUBSCRIBERS = """
|
|
804
440
|
query GatherGraphQLQuerySubscribers($members: [ID!]) {
|
|
805
441
|
CoreGraphQLQueryGroup(members__ids: $members) {
|