infrahub-server 1.1.6__py3-none-any.whl → 1.2.0b1__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} +5 -3
- 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/models.py +1 -1
- infrahub/computed_attribute/tasks.py +64 -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 +54 -22
- infrahub/core/branch/models.py +4 -4
- infrahub/core/branch/tasks.py +137 -129
- infrahub/core/changelog/__init__.py +0 -0
- infrahub/core/changelog/diff.py +283 -0
- infrahub/core/changelog/models.py +499 -0
- infrahub/core/constants/__init__.py +43 -2
- infrahub/core/constants/infrahubkind.py +1 -0
- infrahub/core/constants/schema.py +2 -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 +7 -7
- infrahub/core/diff/enricher/hierarchy.py +22 -7
- infrahub/core/diff/enricher/labels.py +19 -4
- infrahub/core/diff/enricher/path_identifier.py +7 -9
- infrahub/core/diff/enricher/summary_counts.py +3 -1
- infrahub/core/diff/merger/merger.py +8 -4
- infrahub/core/diff/model/path.py +76 -35
- infrahub/core/diff/parent_node_adder.py +78 -0
- infrahub/core/diff/payload_builder.py +13 -2
- 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 +14 -3
- 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 +233 -142
- infrahub/core/diff/query/summary_counts_enricher.py +267 -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 +32 -28
- infrahub/core/diff/repository/repository.py +215 -41
- infrahub/core/diff/tasks.py +13 -12
- infrahub/core/enums.py +1 -1
- infrahub/core/graph/__init__.py +1 -1
- infrahub/core/graph/index.py +3 -0
- 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 +20 -15
- infrahub/core/merge.py +5 -2
- infrahub/core/migrations/graph/__init__.py +4 -0
- 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/graph/m019_restore_rels_to_time.py +256 -0
- infrahub/core/migrations/graph/m020_add_generate_template_attr.py +48 -0
- 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 +39 -19
- 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 +27 -13
- 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 +170 -46
- 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 +6 -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 +213 -26
- 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 +76 -38
- infrahub/core/schema/__init__.py +6 -4
- infrahub/core/schema/attribute_schema.py +8 -0
- infrahub/core/schema/basenode_schema.py +13 -3
- infrahub/core/schema/definitions/core/__init__.py +153 -0
- infrahub/core/schema/definitions/core/account.py +168 -0
- infrahub/core/schema/definitions/core/artifact.py +127 -0
- infrahub/core/schema/definitions/core/builtin.py +21 -0
- infrahub/core/schema/definitions/core/check.py +60 -0
- infrahub/core/schema/definitions/core/generator.py +96 -0
- infrahub/core/schema/definitions/core/graphql_query.py +77 -0
- infrahub/core/schema/definitions/core/group.py +105 -0
- infrahub/core/schema/definitions/core/ipam.py +252 -0
- infrahub/core/schema/definitions/core/lineage.py +17 -0
- infrahub/core/schema/definitions/core/menu.py +46 -0
- infrahub/core/schema/definitions/core/permission.py +161 -0
- infrahub/core/schema/definitions/core/profile.py +29 -0
- infrahub/core/schema/definitions/core/propose_change.py +88 -0
- infrahub/core/schema/definitions/core/propose_change_comment.py +188 -0
- infrahub/core/schema/definitions/core/propose_change_validator.py +326 -0
- infrahub/core/schema/definitions/core/repository.py +280 -0
- infrahub/core/schema/definitions/core/resource_pool.py +180 -0
- infrahub/core/schema/definitions/core/template.py +12 -0
- infrahub/core/schema/definitions/core/transform.py +87 -0
- infrahub/core/schema/definitions/core/webhook.py +108 -0
- 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 +10 -2
- infrahub/core/schema/schema_branch.py +260 -16
- infrahub/core/schema/template_schema.py +36 -0
- infrahub/core/task/user_task.py +7 -5
- infrahub/core/timestamp.py +3 -3
- 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 +16 -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 +4 -2
- infrahub/dependencies/builder/diff/enricher/hierarchy.py +3 -1
- infrahub/dependencies/builder/diff/enricher/summary_counts.py +1 -1
- infrahub/dependencies/builder/diff/parent_node_adder.py +8 -0
- infrahub/events/artifact_action.py +76 -0
- infrahub/events/branch_action.py +50 -21
- infrahub/events/group_action.py +117 -0
- infrahub/events/models.py +164 -51
- infrahub/events/node_action.py +70 -8
- infrahub/events/repository_action.py +8 -8
- infrahub/events/schema_action.py +21 -8
- infrahub/exceptions.py +9 -0
- infrahub/generators/models.py +1 -0
- infrahub/generators/tasks.py +34 -15
- infrahub/git/base.py +3 -5
- infrahub/git/constants.py +0 -1
- infrahub/git/integrator.py +60 -36
- infrahub/git/models.py +80 -1
- infrahub/git/repository.py +7 -8
- infrahub/git/tasks.py +432 -112
- 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/context.py +33 -0
- infrahub/graphql/enums.py +1 -1
- infrahub/graphql/initialization.py +5 -1
- infrahub/graphql/loaders/node.py +2 -2
- infrahub/graphql/manager.py +63 -63
- infrahub/graphql/mutations/account.py +20 -13
- infrahub/graphql/mutations/artifact_definition.py +16 -12
- infrahub/graphql/mutations/branch.py +86 -40
- infrahub/graphql/mutations/computed_attribute.py +24 -13
- infrahub/graphql/mutations/diff.py +54 -14
- infrahub/graphql/mutations/diff_conflict.py +14 -8
- infrahub/graphql/mutations/generator.py +83 -0
- infrahub/graphql/mutations/graphql_query.py +19 -11
- infrahub/graphql/mutations/ipam.py +25 -23
- infrahub/graphql/mutations/main.py +243 -50
- infrahub/graphql/mutations/menu.py +10 -10
- infrahub/graphql/mutations/proposed_change.py +36 -28
- infrahub/graphql/mutations/relationship.py +343 -104
- infrahub/graphql/mutations/repository.py +41 -35
- infrahub/graphql/mutations/resource_manager.py +26 -26
- infrahub/graphql/mutations/schema.py +66 -33
- infrahub/graphql/mutations/tasks.py +16 -10
- infrahub/graphql/parser.py +1 -1
- infrahub/graphql/permissions.py +3 -10
- infrahub/graphql/queries/account.py +22 -18
- infrahub/graphql/queries/branch.py +6 -4
- infrahub/graphql/queries/diff/tree.py +63 -52
- infrahub/graphql/queries/event.py +115 -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 +4 -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/context.py +12 -0
- infrahub/graphql/types/enums.py +2 -0
- infrahub/graphql/types/event.py +158 -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 +21 -21
- infrahub/menu/generator.py +0 -1
- infrahub/menu/menu.py +116 -138
- infrahub/menu/models.py +4 -4
- infrahub/message_bus/__init__.py +11 -13
- infrahub/message_bus/messages/__init__.py +0 -14
- infrahub/message_bus/messages/check_generator_run.py +1 -3
- infrahub/message_bus/messages/event_branch_merge.py +3 -0
- infrahub/message_bus/messages/proposed_change/request_proposedchange_refreshartifacts.py +6 -0
- infrahub/message_bus/messages/request_proposedchange_pipeline.py +2 -0
- infrahub/message_bus/messages/send_echo_request.py +1 -1
- infrahub/message_bus/operations/__init__.py +4 -13
- infrahub/message_bus/operations/check/__init__.py +2 -2
- infrahub/message_bus/operations/check/generator.py +1 -3
- infrahub/message_bus/operations/event/branch.py +7 -3
- infrahub/message_bus/operations/event/schema.py +1 -1
- infrahub/message_bus/operations/event/worker.py +0 -3
- 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 -4
- infrahub/message_bus/operations/requests/generator_definition.py +2 -4
- infrahub/message_bus/operations/requests/proposed_change.py +37 -20
- infrahub/message_bus/operations/send/echo.py +1 -1
- infrahub/message_bus/types.py +1 -1
- infrahub/permissions/__init__.py +2 -1
- infrahub/permissions/globals.py +15 -0
- 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 +18 -1
- infrahub/proposed_change/tasks.py +195 -53
- infrahub/pytest_plugin.py +4 -4
- infrahub/server.py +13 -12
- infrahub/services/__init__.py +148 -63
- infrahub/services/adapters/cache/__init__.py +11 -11
- infrahub/services/adapters/cache/nats.py +42 -25
- infrahub/services/adapters/cache/redis.py +3 -11
- 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 +25 -8
- infrahub/services/adapters/message_bus/local.py +9 -7
- infrahub/services/adapters/message_bus/nats.py +14 -8
- infrahub/services/adapters/message_bus/rabbitmq.py +23 -10
- infrahub/services/adapters/workflow/__init__.py +11 -8
- infrahub/services/adapters/workflow/local.py +27 -6
- infrahub/services/adapters/workflow/worker.py +23 -7
- infrahub/services/component.py +43 -40
- infrahub/services/protocols.py +7 -7
- infrahub/services/scheduler.py +30 -29
- infrahub/storage.py +2 -4
- infrahub/task_manager/constants.py +1 -1
- infrahub/task_manager/event.py +261 -0
- infrahub/task_manager/models.py +147 -3
- infrahub/task_manager/task.py +1 -1
- infrahub/tasks/artifact.py +19 -18
- 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 +16 -0
- infrahub/trigger/constants.py +9 -0
- infrahub/trigger/models.py +105 -0
- infrahub/trigger/tasks.py +91 -0
- infrahub/types.py +1 -1
- infrahub/utils.py +1 -1
- infrahub/webhook/constants.py +0 -2
- infrahub/webhook/models.py +161 -40
- infrahub/webhook/tasks.py +123 -202
- infrahub/webhook/triggers.py +27 -0
- infrahub/workers/infrahub_async.py +36 -25
- infrahub/workers/utils.py +63 -0
- infrahub/workflows/catalogue.py +71 -52
- infrahub/workflows/initialization.py +14 -8
- infrahub/workflows/models.py +28 -4
- infrahub/workflows/utils.py +1 -1
- infrahub_sdk/client.py +8 -0
- infrahub_sdk/ctl/branch.py +3 -2
- infrahub_sdk/ctl/check.py +3 -3
- infrahub_sdk/ctl/cli_commands.py +16 -11
- 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 -19
- infrahub_sdk/ctl/validate.py +2 -1
- infrahub_sdk/exceptions.py +12 -0
- infrahub_sdk/generator.py +3 -0
- infrahub_sdk/node.py +4 -4
- infrahub_sdk/protocols.py +21 -8
- infrahub_sdk/schema/__init__.py +14 -2
- infrahub_sdk/schema/main.py +7 -0
- infrahub_sdk/task/__init__.py +1 -0
- infrahub_sdk/task/constants.py +3 -0
- infrahub_sdk/task/exceptions.py +25 -0
- infrahub_sdk/task/manager.py +545 -0
- infrahub_sdk/task/models.py +74 -0
- infrahub_sdk/timestamp.py +134 -33
- infrahub_sdk/utils.py +39 -1
- infrahub_sdk/yaml.py +2 -3
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0b1.dist-info}/METADATA +47 -12
- infrahub_server-1.2.0b1.dist-info/RECORD +725 -0
- 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/core/schema/definitions/core.py +0 -2274
- infrahub/graphql/query.py +0 -52
- 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/request_artifactdefinition_check.py +0 -17
- 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/requests/artifact_definition.py +0 -148
- infrahub/message_bus/operations/requests/repository.py +0 -133
- 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_server-1.1.6.dist-info/RECORD +0 -681
- /infrahub/{schema → artifacts}/__init__.py +0 -0
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0b1.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0b1.dist-info}/WHEEL +0 -0
- {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0b1.dist-info}/entry_points.txt +0 -0
|
@@ -7,11 +7,18 @@ from typing import TYPE_CHECKING, Generator, Optional, Union
|
|
|
7
7
|
|
|
8
8
|
from infrahub_sdk.uuidt import UUIDT
|
|
9
9
|
|
|
10
|
+
from infrahub.core.changelog.models import (
|
|
11
|
+
ChangelogRelationshipMapper,
|
|
12
|
+
RelationshipCardinalityManyChangelog,
|
|
13
|
+
RelationshipCardinalityOneChangelog,
|
|
14
|
+
)
|
|
10
15
|
from infrahub.core.constants import RelationshipDirection, RelationshipStatus
|
|
16
|
+
from infrahub.core.constants.database import DatabaseEdgeType
|
|
11
17
|
from infrahub.core.query import Query, QueryType
|
|
12
18
|
from infrahub.core.query.subquery import build_subquery_filter, build_subquery_order
|
|
13
19
|
from infrahub.core.timestamp import Timestamp
|
|
14
20
|
from infrahub.core.utils import extract_field_filters
|
|
21
|
+
from infrahub.log import get_logger
|
|
15
22
|
|
|
16
23
|
if TYPE_CHECKING:
|
|
17
24
|
from uuid import UUID
|
|
@@ -21,10 +28,12 @@ if TYPE_CHECKING:
|
|
|
21
28
|
from infrahub.core.branch import Branch
|
|
22
29
|
from infrahub.core.node import Node
|
|
23
30
|
from infrahub.core.relationship import Relationship
|
|
24
|
-
from infrahub.core.schema import RelationshipSchema
|
|
31
|
+
from infrahub.core.schema import NodeSchema, RelationshipSchema
|
|
25
32
|
from infrahub.database import InfrahubDatabase
|
|
26
33
|
|
|
27
|
-
# pylint: disable=redefined-builtin
|
|
34
|
+
# pylint: disable=redefined-builtin,too-many-lines
|
|
35
|
+
|
|
36
|
+
log = get_logger()
|
|
28
37
|
|
|
29
38
|
|
|
30
39
|
@dataclass
|
|
@@ -204,7 +213,7 @@ class RelationshipCreateQuery(RelationshipQuery):
|
|
|
204
213
|
|
|
205
214
|
super().__init__(destination=destination, destination_id=destination_id, **kwargs)
|
|
206
215
|
|
|
207
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
|
|
216
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
208
217
|
self.params["source_id"] = self.source_id
|
|
209
218
|
self.params["destination_id"] = self.destination_id
|
|
210
219
|
self.params["name"] = self.schema.identifier
|
|
@@ -289,7 +298,7 @@ class RelationshipUpdatePropertyQuery(RelationshipQuery):
|
|
|
289
298
|
|
|
290
299
|
super().__init__(**kwargs)
|
|
291
300
|
|
|
292
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
|
|
301
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
293
302
|
self.params["rel_node_id"] = self.data.rel_node_id
|
|
294
303
|
self.params["branch"] = self.branch.name
|
|
295
304
|
self.params["branch_level"] = self.branch.hierarchy_level
|
|
@@ -367,7 +376,7 @@ class RelationshipDataDeleteQuery(RelationshipQuery):
|
|
|
367
376
|
self.data = data
|
|
368
377
|
super().__init__(**kwargs)
|
|
369
378
|
|
|
370
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
|
|
379
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
371
380
|
self.params["source_id"] = self.source_id
|
|
372
381
|
self.params["destination_id"] = self.data.peer_id
|
|
373
382
|
self.params["rel_node_id"] = self.data.rel_node_id
|
|
@@ -431,7 +440,7 @@ class RelationshipDeleteQuery(RelationshipQuery):
|
|
|
431
440
|
if inspect.isclass(self.rel):
|
|
432
441
|
raise TypeError("An instance of Relationship must be provided to RelationshipDeleteQuery")
|
|
433
442
|
|
|
434
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
|
|
443
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
435
444
|
rel_filter, rel_params = self.branch.get_query_filter_path(at=self.at, variable_name="edge")
|
|
436
445
|
self.params["source_id"] = self.source_id
|
|
437
446
|
self.params["destination_id"] = self.destination_id
|
|
@@ -558,7 +567,7 @@ class RelationshipGetPeerQuery(Query):
|
|
|
558
567
|
|
|
559
568
|
super().__init__(**kwargs)
|
|
560
569
|
|
|
561
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: #
|
|
570
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
562
571
|
branch_filter, branch_params = self.branch.get_query_filter_path(
|
|
563
572
|
at=self.at, branch_agnostic=self.branch_agnostic
|
|
564
573
|
)
|
|
@@ -583,6 +592,7 @@ class RelationshipGetPeerQuery(Query):
|
|
|
583
592
|
query = """
|
|
584
593
|
MATCH (source_node:Node)%(arrow_left_start)s[:IS_RELATED]%(arrow_left_end)s(rl:Relationship { name: $rel_identifier })
|
|
585
594
|
WHERE source_node.uuid IN $source_ids
|
|
595
|
+
WITH DISTINCT source_node, rl
|
|
586
596
|
CALL {
|
|
587
597
|
WITH rl, source_node
|
|
588
598
|
MATCH path = (source_node)%(path)s(peer:Node)
|
|
@@ -659,10 +669,23 @@ class RelationshipGetPeerQuery(Query):
|
|
|
659
669
|
# QUERY Properties
|
|
660
670
|
# ----------------------------------------------------------------------------
|
|
661
671
|
query = """
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
672
|
+
CALL {
|
|
673
|
+
WITH rl
|
|
674
|
+
MATCH (rl)-[r:IS_VISIBLE]-(is_visible)
|
|
675
|
+
WHERE %(branch_filter)s
|
|
676
|
+
RETURN r AS rel_is_visible, is_visible
|
|
677
|
+
ORDER BY r.branch_level DESC, r.from DESC, r.status ASC
|
|
678
|
+
LIMIT 1
|
|
679
|
+
}
|
|
680
|
+
CALL {
|
|
681
|
+
WITH rl
|
|
682
|
+
MATCH (rl)-[r:IS_PROTECTED]-(is_protected)
|
|
683
|
+
WHERE %(branch_filter)s
|
|
684
|
+
RETURN r AS rel_is_protected, is_protected
|
|
685
|
+
ORDER BY r.branch_level DESC, r.from DESC, r.status ASC
|
|
686
|
+
LIMIT 1
|
|
687
|
+
}
|
|
688
|
+
""" % {"branch_filter": branch_filter}
|
|
666
689
|
|
|
667
690
|
self.add_to_query(query)
|
|
668
691
|
|
|
@@ -672,20 +695,24 @@ class RelationshipGetPeerQuery(Query):
|
|
|
672
695
|
# We must query them one by one otherwise the second one won't return
|
|
673
696
|
for node_prop in ["source", "owner"]:
|
|
674
697
|
query = """
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
698
|
+
CALL {
|
|
699
|
+
WITH rl
|
|
700
|
+
OPTIONAL MATCH (rl)-[r:HAS_%(node_prop_type)s]-(%(node_prop)s)
|
|
701
|
+
WHERE %(branch_filter)s
|
|
702
|
+
RETURN r AS rel_%(node_prop)s, %(node_prop)s
|
|
703
|
+
ORDER BY r.branch_level DESC, r.from DESC, r.status ASC
|
|
704
|
+
LIMIT 1
|
|
705
|
+
}
|
|
706
|
+
""" % {
|
|
707
|
+
"node_prop": node_prop,
|
|
708
|
+
"node_prop_type": node_prop.upper(),
|
|
709
|
+
"branch_filter": branch_filter,
|
|
710
|
+
}
|
|
686
711
|
self.add_to_query(query)
|
|
687
712
|
self.update_return_labels([f"rel_{node_prop}", node_prop])
|
|
688
713
|
|
|
714
|
+
self.add_to_query("WITH " + ",".join(self.return_labels))
|
|
715
|
+
|
|
689
716
|
# ----------------------------------------------------------------------------
|
|
690
717
|
# ORDER Results
|
|
691
718
|
# ----------------------------------------------------------------------------
|
|
@@ -765,7 +792,7 @@ class RelationshipGetQuery(RelationshipQuery):
|
|
|
765
792
|
|
|
766
793
|
type: QueryType = QueryType.READ
|
|
767
794
|
|
|
768
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
|
|
795
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
769
796
|
self.params["source_id"] = self.source_id
|
|
770
797
|
self.params["destination_id"] = self.destination_id
|
|
771
798
|
self.params["name"] = self.schema.identifier
|
|
@@ -826,7 +853,7 @@ class RelationshipGetByIdentifierQuery(Query):
|
|
|
826
853
|
|
|
827
854
|
super().__init__(**kwargs)
|
|
828
855
|
|
|
829
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
|
|
856
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
830
857
|
self.params["identifiers"] = self.identifiers
|
|
831
858
|
self.params["full_identifiers"] = [
|
|
832
859
|
[full_id.source_kind, full_id.identifier, full_id.destination_kind] for full_id in self.full_identifiers
|
|
@@ -891,7 +918,7 @@ class RelationshipCountPerNodeQuery(Query):
|
|
|
891
918
|
|
|
892
919
|
super().__init__(**kwargs)
|
|
893
920
|
|
|
894
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None:
|
|
921
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
895
922
|
branch_filter, branch_params = self.branch.get_query_filter_path(at=self.at.to_string())
|
|
896
923
|
self.params.update(branch_params)
|
|
897
924
|
|
|
@@ -905,7 +932,8 @@ class RelationshipCountPerNodeQuery(Query):
|
|
|
905
932
|
path = "<-[r:IS_RELATED]-"
|
|
906
933
|
|
|
907
934
|
query = """
|
|
908
|
-
MATCH (rl:Relationship { name: $rel_identifier })
|
|
935
|
+
MATCH (peer_node:Node)%(path)s(rl:Relationship { name: $rel_identifier })
|
|
936
|
+
WHERE peer_node.uuid IN $peer_ids AND %(branch_filter)s
|
|
909
937
|
CALL {
|
|
910
938
|
WITH rl
|
|
911
939
|
MATCH path = (peer_node:Node)%(path)s(rl)
|
|
@@ -931,3 +959,162 @@ class RelationshipCountPerNodeQuery(Query):
|
|
|
931
959
|
data[node_id] = 0
|
|
932
960
|
|
|
933
961
|
return data
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
class RelationshipDeleteAllQuery(Query):
|
|
965
|
+
"""
|
|
966
|
+
Delete all relationships linked to a given node on a given branch at a given time. For every IS_RELATED edge:
|
|
967
|
+
- Set `to` time if an active edge exist on the same branch.
|
|
968
|
+
- Create `deleted` edge.
|
|
969
|
+
- Apply above to every edges linked to any connected Relationship node.
|
|
970
|
+
This query returns node uuids/kinds and corresponding relationship identifiers of deleted nodes,
|
|
971
|
+
that are later used to update node changelog.
|
|
972
|
+
"""
|
|
973
|
+
|
|
974
|
+
name = "node_delete_all_relationships"
|
|
975
|
+
type = QueryType.WRITE
|
|
976
|
+
insert_return = False
|
|
977
|
+
|
|
978
|
+
def __init__(self, node_id: str, **kwargs):
|
|
979
|
+
self.node_id = node_id
|
|
980
|
+
super().__init__(**kwargs)
|
|
981
|
+
|
|
982
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs) -> None: # noqa: ARG002
|
|
983
|
+
self.params["source_id"] = kwargs["node_id"]
|
|
984
|
+
self.params["branch"] = self.branch.name
|
|
985
|
+
|
|
986
|
+
self.params["rel_prop"] = {
|
|
987
|
+
"branch": self.branch.name,
|
|
988
|
+
"branch_level": self.branch.hierarchy_level,
|
|
989
|
+
"status": RelationshipStatus.DELETED.value,
|
|
990
|
+
"from": self.at.to_string(),
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
self.params["at"] = self.at.to_string()
|
|
994
|
+
|
|
995
|
+
active_rel_filter, rel_params = self.branch.get_query_filter_path(
|
|
996
|
+
at=self.at, variable_name="active_edge", branch_agnostic=self.branch_agnostic
|
|
997
|
+
)
|
|
998
|
+
self.params.update(rel_params)
|
|
999
|
+
|
|
1000
|
+
query = """
|
|
1001
|
+
MATCH (s:Node { uuid: $source_id })-[active_edge:IS_RELATED]-(rl:Relationship)
|
|
1002
|
+
WHERE %(active_rel_filter)s AND active_edge.status = "active"
|
|
1003
|
+
WITH DISTINCT rl
|
|
1004
|
+
""" % {"active_rel_filter": active_rel_filter}
|
|
1005
|
+
|
|
1006
|
+
edge_types = [
|
|
1007
|
+
DatabaseEdgeType.IS_VISIBLE.value,
|
|
1008
|
+
DatabaseEdgeType.IS_PROTECTED.value,
|
|
1009
|
+
DatabaseEdgeType.HAS_OWNER.value,
|
|
1010
|
+
DatabaseEdgeType.HAS_SOURCE.value,
|
|
1011
|
+
]
|
|
1012
|
+
|
|
1013
|
+
for arrow_left, arrow_right in (("<-", "-"), ("-", "->")):
|
|
1014
|
+
for edge_type in edge_types:
|
|
1015
|
+
sub_query = """
|
|
1016
|
+
CALL {
|
|
1017
|
+
WITH rl
|
|
1018
|
+
MATCH (rl)%(arrow_left)s[active_edge:%(edge_type)s]%(arrow_right)s(n)
|
|
1019
|
+
WHERE %(active_rel_filter)s AND active_edge.status ="active"
|
|
1020
|
+
CREATE (rl)%(arrow_left)s[deleted_edge:%(edge_type)s $rel_prop]%(arrow_right)s(n)
|
|
1021
|
+
SET deleted_edge.hierarchy = active_edge.hierarchy
|
|
1022
|
+
WITH active_edge, n
|
|
1023
|
+
WHERE active_edge.branch = $branch AND active_edge.to IS NULL
|
|
1024
|
+
SET active_edge.to = $at
|
|
1025
|
+
}
|
|
1026
|
+
""" % {
|
|
1027
|
+
"arrow_left": arrow_left,
|
|
1028
|
+
"arrow_right": arrow_right,
|
|
1029
|
+
"active_rel_filter": active_rel_filter,
|
|
1030
|
+
"edge_type": edge_type,
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
query += sub_query
|
|
1034
|
+
|
|
1035
|
+
# We only want to return uuid/kind of `Node` connected through `IS_RELATED` edges.
|
|
1036
|
+
query += """
|
|
1037
|
+
CALL {
|
|
1038
|
+
WITH rl
|
|
1039
|
+
MATCH (rl)-[active_edge:IS_RELATED]->(n)
|
|
1040
|
+
WHERE %(active_rel_filter)s AND active_edge.status ="active"
|
|
1041
|
+
CREATE (rl)-[deleted_edge:IS_RELATED $rel_prop]->(n)
|
|
1042
|
+
SET deleted_edge.hierarchy = active_edge.hierarchy
|
|
1043
|
+
WITH rl, active_edge, n
|
|
1044
|
+
WHERE active_edge.branch = $branch AND active_edge.to IS NULL
|
|
1045
|
+
SET active_edge.to = $at
|
|
1046
|
+
RETURN
|
|
1047
|
+
n.uuid as uuid,
|
|
1048
|
+
n.kind as kind,
|
|
1049
|
+
rl.name as rel_identifier,
|
|
1050
|
+
"outbound" as rel_direction
|
|
1051
|
+
|
|
1052
|
+
UNION
|
|
1053
|
+
|
|
1054
|
+
WITH rl
|
|
1055
|
+
MATCH (rl)<-[active_edge:IS_RELATED]-(n)
|
|
1056
|
+
WHERE %(active_rel_filter)s AND active_edge.status ="active"
|
|
1057
|
+
CREATE (rl)<-[deleted_edge:IS_RELATED $rel_prop]-(n)
|
|
1058
|
+
SET deleted_edge.hierarchy = active_edge.hierarchy
|
|
1059
|
+
WITH rl, active_edge, n
|
|
1060
|
+
WHERE active_edge.branch = $branch AND active_edge.to IS NULL
|
|
1061
|
+
SET active_edge.to = $at
|
|
1062
|
+
RETURN
|
|
1063
|
+
n.uuid as uuid,
|
|
1064
|
+
n.kind as kind,
|
|
1065
|
+
rl.name as rel_identifier,
|
|
1066
|
+
"inbound" as rel_direction
|
|
1067
|
+
}
|
|
1068
|
+
RETURN DISTINCT uuid, kind, rel_identifier, rel_direction
|
|
1069
|
+
""" % {
|
|
1070
|
+
"active_rel_filter": active_rel_filter,
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
self.add_to_query(query)
|
|
1074
|
+
|
|
1075
|
+
def get_deleted_relationships_changelog(
|
|
1076
|
+
self, node_schema: NodeSchema
|
|
1077
|
+
) -> list[RelationshipCardinalityOneChangelog | RelationshipCardinalityManyChangelog]:
|
|
1078
|
+
rel_identifier_to_changelog_mapper = {}
|
|
1079
|
+
|
|
1080
|
+
for result in self.get_results():
|
|
1081
|
+
peer_uuid = result.data["uuid"]
|
|
1082
|
+
if peer_uuid == self.node_id:
|
|
1083
|
+
continue
|
|
1084
|
+
|
|
1085
|
+
rel_identifier = result.data["rel_identifier"]
|
|
1086
|
+
kind = result.data["kind"]
|
|
1087
|
+
deleted_rel_schemas = [
|
|
1088
|
+
rel_schema for rel_schema in node_schema.relationships if rel_schema.identifier == rel_identifier
|
|
1089
|
+
]
|
|
1090
|
+
|
|
1091
|
+
if len(deleted_rel_schemas) == 0:
|
|
1092
|
+
continue # TODO Unidirectional relationship changelog should be handled, cf IFC-1319.
|
|
1093
|
+
|
|
1094
|
+
if len(deleted_rel_schemas) > 2:
|
|
1095
|
+
log.error(f"Duplicated relationship schema with identifier {rel_identifier}")
|
|
1096
|
+
continue
|
|
1097
|
+
|
|
1098
|
+
if len(deleted_rel_schemas) == 2:
|
|
1099
|
+
# Hierarchical schema nodes have 2 relationships with `parent_child` identifiers,
|
|
1100
|
+
# which are differentiated by their direction within the database.
|
|
1101
|
+
# assert rel_identifier != PARENT_CHILD_IDENTIFIER
|
|
1102
|
+
|
|
1103
|
+
rel_direction = result.data["rel_direction"]
|
|
1104
|
+
deleted_rel_schema = (
|
|
1105
|
+
deleted_rel_schemas[0]
|
|
1106
|
+
if deleted_rel_schemas[0].direction.value == rel_direction
|
|
1107
|
+
else deleted_rel_schemas[1]
|
|
1108
|
+
)
|
|
1109
|
+
else:
|
|
1110
|
+
deleted_rel_schema = deleted_rel_schemas[0]
|
|
1111
|
+
|
|
1112
|
+
try:
|
|
1113
|
+
changelog_mapper = rel_identifier_to_changelog_mapper[rel_identifier]
|
|
1114
|
+
except KeyError:
|
|
1115
|
+
changelog_mapper = ChangelogRelationshipMapper(schema=deleted_rel_schema)
|
|
1116
|
+
rel_identifier_to_changelog_mapper[rel_identifier] = changelog_mapper
|
|
1117
|
+
|
|
1118
|
+
changelog_mapper.delete_relationship(peer_id=peer_uuid, peer_kind=kind, rel_schema=deleted_rel_schema)
|
|
1119
|
+
|
|
1120
|
+
return [changelog_mapper.changelog for changelog_mapper in rel_identifier_to_changelog_mapper.values()]
|
|
@@ -26,7 +26,7 @@ class IPAddressPoolGetIdentifiers(Query):
|
|
|
26
26
|
|
|
27
27
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
28
28
|
|
|
29
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
29
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
30
30
|
self.params["pool_id"] = self.pool_id
|
|
31
31
|
self.params["addresses"] = self.addresses
|
|
32
32
|
|
|
@@ -53,7 +53,7 @@ class IPAddressPoolGetReserved(Query):
|
|
|
53
53
|
|
|
54
54
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
55
55
|
|
|
56
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
56
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
57
57
|
self.params["pool_id"] = self.pool_id
|
|
58
58
|
self.params["identifier"] = self.identifier
|
|
59
59
|
|
|
@@ -82,7 +82,7 @@ class IPAddressPoolSetReserved(Query):
|
|
|
82
82
|
|
|
83
83
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
84
84
|
|
|
85
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
85
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
86
86
|
self.params["pool_id"] = self.pool_id
|
|
87
87
|
self.params["address_id"] = self.address_id
|
|
88
88
|
self.params["identifier"] = self.identifier
|
|
@@ -119,10 +119,11 @@ class NumberPoolGetAllocated(Query):
|
|
|
119
119
|
|
|
120
120
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
121
121
|
|
|
122
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
122
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
123
123
|
self.params["node_attribute"] = self.pool.node_attribute.value
|
|
124
124
|
self.params["start_range"] = self.pool.start_range.value
|
|
125
125
|
self.params["end_range"] = self.pool.end_range.value
|
|
126
|
+
self.params["pool_id"] = self.pool.get_id()
|
|
126
127
|
|
|
127
128
|
branch_filter, branch_params = self.branch.get_query_filter_path(
|
|
128
129
|
at=self.at.to_string(), branch_agnostic=self.branch_agnostic
|
|
@@ -133,7 +134,8 @@ class NumberPoolGetAllocated(Query):
|
|
|
133
134
|
MATCH (n:%(node)s)-[ha:HAS_ATTRIBUTE]-(a:Attribute {name: $node_attribute})-[hv:HAS_VALUE]-(av:AttributeValue)
|
|
134
135
|
MATCH (a)-[hs:HAS_SOURCE]-(pool:%(number_pool_kind)s)
|
|
135
136
|
WHERE
|
|
136
|
-
|
|
137
|
+
pool.uuid = $pool_id
|
|
138
|
+
AND av.value >= $start_range and av.value <= $end_range
|
|
137
139
|
AND all(r in [ha, hv, hs] WHERE (%(branch_filter)s))
|
|
138
140
|
AND ha.status = "active"
|
|
139
141
|
AND hv.status = "active"
|
|
@@ -164,7 +166,7 @@ class NumberPoolGetReserved(Query):
|
|
|
164
166
|
|
|
165
167
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
166
168
|
|
|
167
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
169
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
168
170
|
self.params["pool_id"] = self.pool_id
|
|
169
171
|
self.params["identifier"] = self.identifier
|
|
170
172
|
|
|
@@ -204,7 +206,7 @@ class NumberPoolGetUsed(Query):
|
|
|
204
206
|
|
|
205
207
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
206
208
|
|
|
207
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
209
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
208
210
|
self.params["pool_id"] = self.pool.get_id()
|
|
209
211
|
self.params["start_range"] = self.pool.start_range.value
|
|
210
212
|
self.params["end_range"] = self.pool.end_range.value
|
|
@@ -257,7 +259,7 @@ class NumberPoolSetReserved(Query):
|
|
|
257
259
|
|
|
258
260
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
259
261
|
|
|
260
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
262
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
261
263
|
self.params["pool_id"] = self.pool_id
|
|
262
264
|
self.params["reserved"] = self.reserved
|
|
263
265
|
self.params["identifier"] = self.identifier
|
|
@@ -296,7 +298,7 @@ class PrefixPoolGetIdentifiers(Query):
|
|
|
296
298
|
|
|
297
299
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
298
300
|
|
|
299
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
301
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
300
302
|
self.params["pool_id"] = self.pool_id
|
|
301
303
|
self.params["prefixes"] = self.prefixes
|
|
302
304
|
|
|
@@ -323,7 +325,7 @@ class PrefixPoolGetReserved(Query):
|
|
|
323
325
|
|
|
324
326
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
325
327
|
|
|
326
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
328
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
327
329
|
self.params["pool_id"] = self.pool_id
|
|
328
330
|
self.params["identifier"] = self.identifier
|
|
329
331
|
|
|
@@ -352,7 +354,7 @@ class PrefixPoolSetReserved(Query):
|
|
|
352
354
|
|
|
353
355
|
super().__init__(**kwargs) # type: ignore[arg-type]
|
|
354
356
|
|
|
355
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None:
|
|
357
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
356
358
|
self.params["pool_id"] = self.pool_id
|
|
357
359
|
self.params["prefix_id"] = self.prefix_id
|
|
358
360
|
self.params["identifier"] = self.identifier
|
|
@@ -30,7 +30,7 @@ class RootNodeCreateQuery(StandardNodeQuery):
|
|
|
30
30
|
name = "standard_node_create"
|
|
31
31
|
type = QueryType.WRITE
|
|
32
32
|
|
|
33
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
33
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
34
34
|
node_type = self.node.get_type()
|
|
35
35
|
self.params["node_prop"] = self.node.to_db()
|
|
36
36
|
|
|
@@ -46,7 +46,7 @@ class StandardNodeCreateQuery(StandardNodeQuery):
|
|
|
46
46
|
name = "standard_node_create"
|
|
47
47
|
type = QueryType.WRITE
|
|
48
48
|
|
|
49
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
49
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
50
50
|
node_type = self.node.get_type()
|
|
51
51
|
self.params["node_prop"] = self.node.to_db()
|
|
52
52
|
|
|
@@ -63,7 +63,7 @@ class StandardNodeUpdateQuery(StandardNodeQuery):
|
|
|
63
63
|
name = "standard_node_update"
|
|
64
64
|
type = QueryType.WRITE
|
|
65
65
|
|
|
66
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
66
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
67
67
|
self.node.get_type()
|
|
68
68
|
self.params["node_prop"] = self.node.to_db()
|
|
69
69
|
self.params["node_prop"]["uuid"] = str(self.node.uuid)
|
|
@@ -83,7 +83,7 @@ class StandardNodeDeleteQuery(StandardNodeQuery):
|
|
|
83
83
|
insert_return = False
|
|
84
84
|
type = QueryType.WRITE
|
|
85
85
|
|
|
86
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
86
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
87
87
|
query = """
|
|
88
88
|
MATCH (n:%s { uuid: $uuid })
|
|
89
89
|
DETACH DELETE (n)
|
|
@@ -103,7 +103,7 @@ class StandardNodeGetItemQuery(Query):
|
|
|
103
103
|
|
|
104
104
|
super().__init__(**kwargs)
|
|
105
105
|
|
|
106
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
106
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
107
107
|
query = """
|
|
108
108
|
MATCH (n:%(node_type)s)
|
|
109
109
|
WHERE %(id_func)s(n) = $node_id OR n.uuid = $node_id
|
|
@@ -128,7 +128,7 @@ class StandardNodeGetListQuery(Query):
|
|
|
128
128
|
|
|
129
129
|
super().__init__(**kwargs)
|
|
130
130
|
|
|
131
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
131
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
132
132
|
filters = []
|
|
133
133
|
if self.ids:
|
|
134
134
|
filters.append("n.uuid in $ids_value")
|
infrahub/core/query/task.py
CHANGED
|
@@ -18,7 +18,7 @@ class TaskNodeCreateQuery(StandardNodeQuery):
|
|
|
18
18
|
|
|
19
19
|
type: QueryType = QueryType.WRITE
|
|
20
20
|
|
|
21
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
21
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
22
22
|
node_type = self.node.get_type()
|
|
23
23
|
self.params["node_prop"] = self.node.to_db()
|
|
24
24
|
self.params["related_id"] = self.node.related.get_id()
|
|
@@ -56,7 +56,7 @@ class TaskNodeQuery(StandardNodeQuery):
|
|
|
56
56
|
self.params["related_nodes"] = self.related_nodes
|
|
57
57
|
self.params["ids"] = self.ids
|
|
58
58
|
|
|
59
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
59
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
60
60
|
self.add_to_query(query="MATCH (n:Task)-[:IMPACTS]->(rn:Node)")
|
|
61
61
|
if self.ids:
|
|
62
62
|
self.add_to_query(query="WHERE n.uuid in $ids")
|
|
@@ -75,7 +75,7 @@ class TaskNodeQueryWithLogs(TaskNodeQuery):
|
|
|
75
75
|
|
|
76
76
|
type: QueryType = QueryType.READ
|
|
77
77
|
|
|
78
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
78
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
79
79
|
self.add_to_query(query="MATCH (n:Task)-[:IMPACTS]->(rn:Node)")
|
|
80
80
|
if self.ids:
|
|
81
81
|
self.add_to_query(query="WHERE n.uuid in $ids")
|
infrahub/core/query/task_log.py
CHANGED
|
@@ -17,7 +17,7 @@ class TaskLogNodeCreateQuery(StandardNodeQuery):
|
|
|
17
17
|
|
|
18
18
|
type: QueryType = QueryType.WRITE
|
|
19
19
|
|
|
20
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
20
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
21
21
|
node_type = self.node.get_type()
|
|
22
22
|
self.params["node_prop"] = self.node.to_db()
|
|
23
23
|
self.params["task_id"] = self.node.task_id
|
infrahub/core/query/utils.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
4
|
|
|
5
|
-
from infrahub.core.schema import NodeSchema, ProfileSchema
|
|
5
|
+
from infrahub.core.schema import NodeSchema, ProfileSchema, TemplateSchema
|
|
6
6
|
|
|
7
7
|
if TYPE_CHECKING:
|
|
8
8
|
from neo4j.graph import Node as Neo4jNode
|
|
@@ -12,12 +12,12 @@ if TYPE_CHECKING:
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def find_node_schema(
|
|
15
|
-
db: InfrahubDatabase, node: Neo4jNode, branch:
|
|
16
|
-
) ->
|
|
15
|
+
db: InfrahubDatabase, node: Neo4jNode, branch: Branch | str, duplicate: bool = False
|
|
16
|
+
) -> NodeSchema | ProfileSchema | TemplateSchema | None:
|
|
17
17
|
for label in node.labels:
|
|
18
18
|
if db.schema.has(name=label, branch=branch):
|
|
19
19
|
schema = db.schema.get(name=label, branch=branch, duplicate=duplicate)
|
|
20
|
-
if isinstance(schema,
|
|
20
|
+
if isinstance(schema, NodeSchema | ProfileSchema | TemplateSchema):
|
|
21
21
|
return schema
|
|
22
22
|
|
|
23
23
|
return None
|
infrahub/core/registry.py
CHANGED
|
@@ -26,7 +26,7 @@ class RelationshipCountConstraint(RelationshipManagerConstraintInterface):
|
|
|
26
26
|
self.db = db
|
|
27
27
|
self.branch = branch
|
|
28
28
|
|
|
29
|
-
async def check(self, relm: RelationshipManager, node_schema: MainSchemaTypes) -> None:
|
|
29
|
+
async def check(self, relm: RelationshipManager, node_schema: MainSchemaTypes) -> None: # noqa: ARG002
|
|
30
30
|
branch = await registry.get_branch(db=self.db) if not self.branch else self.branch
|
|
31
31
|
|
|
32
32
|
# NOTE adding resolve here because we need to retrieve the real ID
|
|
@@ -27,7 +27,7 @@ class RelationshipPeerKindConstraint(RelationshipManagerConstraintInterface):
|
|
|
27
27
|
self.db = db
|
|
28
28
|
self.branch = branch
|
|
29
29
|
|
|
30
|
-
async def check(self, relm: RelationshipManager, node_schema: MainSchemaTypes) -> None:
|
|
30
|
+
async def check(self, relm: RelationshipManager, node_schema: MainSchemaTypes) -> None: # noqa: ARG002
|
|
31
31
|
branch = await registry.get_branch(db=self.db) if not self.branch else self.branch
|
|
32
32
|
peer_schema = registry.schema.get(name=relm.schema.peer, branch=branch, duplicate=False)
|
|
33
33
|
if isinstance(peer_schema, GenericSchema):
|