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
|
@@ -23,7 +23,8 @@ from infrahub_sdk.uuidt import UUIDT
|
|
|
23
23
|
from pydantic import BaseModel, Field
|
|
24
24
|
|
|
25
25
|
from infrahub.core import registry
|
|
26
|
-
from infrahub.core.
|
|
26
|
+
from infrahub.core.changelog.models import ChangelogRelationshipMapper
|
|
27
|
+
from infrahub.core.constants import BranchSupportType, InfrahubKind, RelationshipKind
|
|
27
28
|
from infrahub.core.property import (
|
|
28
29
|
FlagPropertyMixin,
|
|
29
30
|
NodePropertyData,
|
|
@@ -48,11 +49,11 @@ if TYPE_CHECKING:
|
|
|
48
49
|
from typing_extensions import Self
|
|
49
50
|
|
|
50
51
|
from infrahub.core.branch import Branch
|
|
52
|
+
from infrahub.core.changelog.models import RelationshipCardinalityManyChangelog, RelationshipCardinalityOneChangelog
|
|
51
53
|
from infrahub.core.node import Node
|
|
52
54
|
from infrahub.core.schema import MainSchemaTypes, RelationshipSchema
|
|
53
55
|
from infrahub.database import InfrahubDatabase
|
|
54
56
|
|
|
55
|
-
# pylint: disable=redefined-builtin,too-many-lines
|
|
56
57
|
|
|
57
58
|
PeerType = TypeVar("PeerType")
|
|
58
59
|
|
|
@@ -140,6 +141,12 @@ class Relationship(FlagPropertyMixin, NodePropertyMixin):
|
|
|
140
141
|
|
|
141
142
|
return self.peer_id
|
|
142
143
|
|
|
144
|
+
def get_peer_kind(self) -> str:
|
|
145
|
+
if not self._peer or isinstance(self._peer, str):
|
|
146
|
+
return self.schema.peer
|
|
147
|
+
|
|
148
|
+
return self._peer.get_kind()
|
|
149
|
+
|
|
143
150
|
@property
|
|
144
151
|
def node_id(self) -> str:
|
|
145
152
|
if self._node_id:
|
|
@@ -159,7 +166,7 @@ class Relationship(FlagPropertyMixin, NodePropertyMixin):
|
|
|
159
166
|
return registry.get_global_branch()
|
|
160
167
|
return self.branch
|
|
161
168
|
|
|
162
|
-
async def _process_data(self, data: Union[dict, RelationshipPeerData, str]) -> None:
|
|
169
|
+
async def _process_data(self, data: Union[dict, RelationshipPeerData, str]) -> None:
|
|
163
170
|
self.data = data
|
|
164
171
|
|
|
165
172
|
if isinstance(data, RelationshipPeerData):
|
|
@@ -193,16 +200,19 @@ class Relationship(FlagPropertyMixin, NodePropertyMixin):
|
|
|
193
200
|
else:
|
|
194
201
|
await self.set_peer(value=data)
|
|
195
202
|
|
|
196
|
-
async def new(
|
|
197
|
-
self,
|
|
203
|
+
async def new(
|
|
204
|
+
self,
|
|
205
|
+
db: InfrahubDatabase, # noqa: ARG002
|
|
206
|
+
data: Union[dict, RelationshipPeerData, Any] = None,
|
|
207
|
+
**kwargs: Any, # noqa: ARG002
|
|
198
208
|
) -> Relationship:
|
|
199
209
|
await self._process_data(data=data)
|
|
200
210
|
|
|
201
211
|
return self
|
|
202
212
|
|
|
203
|
-
async def load(
|
|
213
|
+
async def load(
|
|
204
214
|
self,
|
|
205
|
-
db: InfrahubDatabase,
|
|
215
|
+
db: InfrahubDatabase, # noqa: ARG002
|
|
206
216
|
id: Optional[UUID] = None,
|
|
207
217
|
db_id: Optional[str] = None,
|
|
208
218
|
updated_at: Optional[Union[Timestamp, str]] = None,
|
|
@@ -253,9 +263,9 @@ class Relationship(FlagPropertyMixin, NodePropertyMixin):
|
|
|
253
263
|
async def get_peer(self, db: InfrahubDatabase, peer_type: type[PeerType]) -> PeerType: ...
|
|
254
264
|
|
|
255
265
|
@overload
|
|
256
|
-
async def get_peer(self, db: InfrahubDatabase, peer_type:
|
|
266
|
+
async def get_peer(self, db: InfrahubDatabase, peer_type: None = ...) -> Node: ...
|
|
257
267
|
|
|
258
|
-
async def get_peer(self, db: InfrahubDatabase, peer_type: type[PeerType] | None = None) -> Any: #
|
|
268
|
+
async def get_peer(self, db: InfrahubDatabase, peer_type: type[PeerType] | None = None) -> Any: # noqa: ARG002
|
|
259
269
|
"""Return the peer of the relationship."""
|
|
260
270
|
if self._peer is None:
|
|
261
271
|
await self._get_peer(db=db)
|
|
@@ -521,8 +531,6 @@ class Relationship(FlagPropertyMixin, NodePropertyMixin):
|
|
|
521
531
|
return response
|
|
522
532
|
|
|
523
533
|
async def get_create_data(self, db: InfrahubDatabase) -> RelationshipCreateData:
|
|
524
|
-
# pylint: disable=no-member
|
|
525
|
-
|
|
526
534
|
branch = self.get_branch_based_on_support_type()
|
|
527
535
|
|
|
528
536
|
await self.resolve(db=db)
|
|
@@ -749,7 +757,7 @@ class RelationshipManager:
|
|
|
749
757
|
await rm._validate_hierarchy()
|
|
750
758
|
|
|
751
759
|
for item in data:
|
|
752
|
-
if not isinstance(item,
|
|
760
|
+
if not isinstance(item, rm.rel_class | str | dict) and not hasattr(item, "_schema"):
|
|
753
761
|
raise ValidationError({rm.name: f"Invalid data provided to form a relationship {item}"})
|
|
754
762
|
|
|
755
763
|
rel = rm.rel_class(schema=rm.schema, branch=rm.branch, at=rm.at, node=rm.node)
|
|
@@ -813,7 +821,7 @@ class RelationshipManager:
|
|
|
813
821
|
async def get_peer(
|
|
814
822
|
self,
|
|
815
823
|
db: InfrahubDatabase,
|
|
816
|
-
peer_type:
|
|
824
|
+
peer_type: None = ...,
|
|
817
825
|
raise_on_error: Literal[False] = ...,
|
|
818
826
|
) -> Node | None: ...
|
|
819
827
|
|
|
@@ -821,7 +829,7 @@ class RelationshipManager:
|
|
|
821
829
|
async def get_peer(
|
|
822
830
|
self,
|
|
823
831
|
db: InfrahubDatabase,
|
|
824
|
-
peer_type:
|
|
832
|
+
peer_type: None = ...,
|
|
825
833
|
raise_on_error: Literal[True] = ...,
|
|
826
834
|
) -> Node: ...
|
|
827
835
|
|
|
@@ -829,14 +837,14 @@ class RelationshipManager:
|
|
|
829
837
|
async def get_peer(
|
|
830
838
|
self,
|
|
831
839
|
db: InfrahubDatabase,
|
|
832
|
-
peer_type:
|
|
840
|
+
peer_type: None = ...,
|
|
833
841
|
raise_on_error: bool = ...,
|
|
834
842
|
) -> Node: ...
|
|
835
843
|
|
|
836
844
|
async def get_peer(
|
|
837
845
|
self,
|
|
838
846
|
db: InfrahubDatabase,
|
|
839
|
-
peer_type: type[PeerType] | None = None, #
|
|
847
|
+
peer_type: type[PeerType] | None = None, # noqa: ARG002
|
|
840
848
|
raise_on_error: bool = False,
|
|
841
849
|
) -> Node | PeerType | None:
|
|
842
850
|
if self.schema.cardinality == "many":
|
|
@@ -863,14 +871,14 @@ class RelationshipManager:
|
|
|
863
871
|
async def get_peers(
|
|
864
872
|
self,
|
|
865
873
|
db: InfrahubDatabase,
|
|
866
|
-
peer_type:
|
|
874
|
+
peer_type: None = None,
|
|
867
875
|
branch_agnostic: bool = ...,
|
|
868
876
|
) -> Mapping[str, Node]: ...
|
|
869
877
|
|
|
870
878
|
async def get_peers(
|
|
871
879
|
self,
|
|
872
880
|
db: InfrahubDatabase,
|
|
873
|
-
peer_type: type[PeerType] | None = None, #
|
|
881
|
+
peer_type: type[PeerType] | None = None, # noqa: ARG002
|
|
874
882
|
branch_agnostic: bool = False,
|
|
875
883
|
) -> Mapping[str, Node | PeerType]:
|
|
876
884
|
rels = await self.get_relationships(db=db, branch_agnostic=branch_agnostic)
|
|
@@ -884,6 +892,8 @@ class RelationshipManager:
|
|
|
884
892
|
"""If the attribute is branch aware, return the Branch object associated with this attribute
|
|
885
893
|
If the attribute is branch agnostic return the Global Branch
|
|
886
894
|
|
|
895
|
+
Note that if this relationship is Aware and source node is Agnostic, it will return -global- branch.
|
|
896
|
+
|
|
887
897
|
Returns:
|
|
888
898
|
Branch:
|
|
889
899
|
"""
|
|
@@ -959,7 +969,7 @@ class RelationshipManager:
|
|
|
959
969
|
self.has_fetched_relationships = True
|
|
960
970
|
|
|
961
971
|
for peer_id in details.peer_ids_present_local_only:
|
|
962
|
-
await self.
|
|
972
|
+
await self.remove_locally(peer_id=peer_id, db=db)
|
|
963
973
|
|
|
964
974
|
async def get(self, db: InfrahubDatabase) -> Relationship | list[Relationship] | None:
|
|
965
975
|
rels = await self.get_relationships(db=db)
|
|
@@ -971,6 +981,19 @@ class RelationshipManager:
|
|
|
971
981
|
|
|
972
982
|
return rels
|
|
973
983
|
|
|
984
|
+
async def get_parent(
|
|
985
|
+
self, db: InfrahubDatabase, branch_agnostic: bool = False, force_refresh: bool = False
|
|
986
|
+
) -> Relationship | None:
|
|
987
|
+
if self.schema.kind == RelationshipKind.PARENT:
|
|
988
|
+
for relationship in await self.get_relationships(
|
|
989
|
+
db=db, branch_agnostic=branch_agnostic, force_refresh=force_refresh
|
|
990
|
+
):
|
|
991
|
+
# As parent relationships requires cardinality=one there will always only be one relationship
|
|
992
|
+
# here even though it's within a loop
|
|
993
|
+
return relationship
|
|
994
|
+
|
|
995
|
+
return None
|
|
996
|
+
|
|
974
997
|
async def get_relationships(
|
|
975
998
|
self, db: InfrahubDatabase, branch_agnostic: bool = False, force_refresh: bool = False
|
|
976
999
|
) -> list[Relationship]:
|
|
@@ -985,7 +1008,7 @@ class RelationshipManager:
|
|
|
985
1008
|
|
|
986
1009
|
return self._relationships.as_list()
|
|
987
1010
|
|
|
988
|
-
async def update(
|
|
1011
|
+
async def update(
|
|
989
1012
|
self, data: Union[list[Union[str, Node]], dict[str, Any], str, Node, None], db: InfrahubDatabase
|
|
990
1013
|
) -> bool:
|
|
991
1014
|
"""Replace and Update the list of relationships with this one."""
|
|
@@ -1002,7 +1025,7 @@ class RelationshipManager:
|
|
|
1002
1025
|
changed = False
|
|
1003
1026
|
|
|
1004
1027
|
for item in list_data:
|
|
1005
|
-
if not isinstance(item,
|
|
1028
|
+
if not isinstance(item, self.rel_class | str | dict | type(None)) and not hasattr(item, "_schema"):
|
|
1006
1029
|
raise ValidationError({self.name: f"Invalid data provided to form a relationship {item}"})
|
|
1007
1030
|
|
|
1008
1031
|
if hasattr(item, "_schema"):
|
|
@@ -1040,7 +1063,7 @@ class RelationshipManager:
|
|
|
1040
1063
|
changed = True
|
|
1041
1064
|
|
|
1042
1065
|
# Check if some relationship got removed by checking if the previous list of relationship is a subset of the current list of not
|
|
1043
|
-
if set(
|
|
1066
|
+
if set(previous_relationships.keys()) <= {rel.peer_id for rel in await self.get_relationships(db=db)}:
|
|
1044
1067
|
changed = True
|
|
1045
1068
|
|
|
1046
1069
|
if changed:
|
|
@@ -1050,7 +1073,7 @@ class RelationshipManager:
|
|
|
1050
1073
|
|
|
1051
1074
|
async def add(self, data: Union[dict[str, Any], Node], db: InfrahubDatabase) -> bool:
|
|
1052
1075
|
"""Add a new relationship to the list of existing ones, avoid duplication."""
|
|
1053
|
-
if not isinstance(data,
|
|
1076
|
+
if not isinstance(data, self.rel_class | dict) and not hasattr(data, "_schema"):
|
|
1054
1077
|
raise ValidationError({self.name: f"Invalid data provided to form a relationship {data}"})
|
|
1055
1078
|
|
|
1056
1079
|
await self._validate_hierarchy()
|
|
@@ -1077,22 +1100,17 @@ class RelationshipManager:
|
|
|
1077
1100
|
for rel in self._relationships:
|
|
1078
1101
|
await rel.resolve(db=db)
|
|
1079
1102
|
|
|
1080
|
-
async def
|
|
1103
|
+
async def remove_locally(
|
|
1081
1104
|
self,
|
|
1082
1105
|
peer_id: Union[str, UUID],
|
|
1083
1106
|
db: InfrahubDatabase,
|
|
1084
|
-
update_db: bool = False,
|
|
1085
1107
|
) -> bool:
|
|
1086
|
-
"""Remove a peer id from the local relationships list
|
|
1087
|
-
need to investigate if and when we should update the relationship in the database."""
|
|
1108
|
+
"""Remove a peer id from the local relationships list"""
|
|
1088
1109
|
|
|
1089
1110
|
for idx, rel in enumerate(await self.get_relationships(db=db)):
|
|
1090
1111
|
if str(rel.peer_id) != str(peer_id):
|
|
1091
1112
|
continue
|
|
1092
1113
|
|
|
1093
|
-
if update_db:
|
|
1094
|
-
await rel.delete(db=db)
|
|
1095
|
-
|
|
1096
1114
|
self._relationships.pop(idx)
|
|
1097
1115
|
return True
|
|
1098
1116
|
|
|
@@ -1109,14 +1127,13 @@ class RelationshipManager:
|
|
|
1109
1127
|
|
|
1110
1128
|
# - Update the existing relationship if we are on the same branch
|
|
1111
1129
|
rel_ids_per_branch = peer_data.rel_ids_per_branch()
|
|
1130
|
+
|
|
1131
|
+
# In which cases do we end up here and do not want to set `to` time?
|
|
1112
1132
|
if branch.name in rel_ids_per_branch:
|
|
1113
1133
|
await update_relationships_to([str(ri) for ri in rel_ids_per_branch[branch.name]], to=remove_at, db=db)
|
|
1114
1134
|
|
|
1115
1135
|
# - Create a new rel of type DELETED if the existing relationship is on a different branch
|
|
1116
|
-
|
|
1117
|
-
if peer_data.rels:
|
|
1118
|
-
rel_branches = {r.branch for r in peer_data.rels}
|
|
1119
|
-
if rel_branches == {peer_data.branch}:
|
|
1136
|
+
if peer_data.rels and {r.branch for r in peer_data.rels} == {peer_data.branch}:
|
|
1120
1137
|
return
|
|
1121
1138
|
|
|
1122
1139
|
query = await RelationshipDataDeleteQuery.init(
|
|
@@ -1130,18 +1147,22 @@ class RelationshipManager:
|
|
|
1130
1147
|
)
|
|
1131
1148
|
await query.execute(db=db)
|
|
1132
1149
|
|
|
1133
|
-
async def save(
|
|
1150
|
+
async def save(
|
|
1151
|
+
self, db: InfrahubDatabase, at: Optional[Timestamp] = None
|
|
1152
|
+
) -> RelationshipCardinalityManyChangelog | RelationshipCardinalityOneChangelog:
|
|
1134
1153
|
"""Create or Update the Relationship in the database."""
|
|
1135
1154
|
|
|
1136
1155
|
await self.resolve(db=db)
|
|
1137
1156
|
|
|
1138
1157
|
save_at = Timestamp(at)
|
|
1139
1158
|
details = await self.fetch_relationship_ids(db=db, force_refresh=True)
|
|
1159
|
+
relationship_mapper = ChangelogRelationshipMapper(schema=self.schema)
|
|
1140
1160
|
|
|
1141
1161
|
# If we have previously fetched the relationships from the database
|
|
1142
1162
|
# Update the one in the database that shouldn't be here.
|
|
1143
1163
|
if self.has_fetched_relationships:
|
|
1144
1164
|
for peer_id in details.peer_ids_present_database_only:
|
|
1165
|
+
relationship_mapper.remove_peer(peer_data=details.peers_database[peer_id])
|
|
1145
1166
|
await self.remove_in_db(peer_data=details.peers_database[peer_id], at=save_at, db=db)
|
|
1146
1167
|
|
|
1147
1168
|
# Create the new relationship that are not present in the database
|
|
@@ -1150,6 +1171,8 @@ class RelationshipManager:
|
|
|
1150
1171
|
if rel.peer_id in details.peer_ids_present_local_only:
|
|
1151
1172
|
await rel.save(at=save_at, db=db)
|
|
1152
1173
|
|
|
1174
|
+
relationship_mapper.add_peer_from_relationship(relationship=rel)
|
|
1175
|
+
|
|
1153
1176
|
elif rel.peer_id in details.peer_ids_present_both:
|
|
1154
1177
|
if properties_not_matching := rel.compare_properties_with_data(
|
|
1155
1178
|
data=details.peers_database[rel.peer_id]
|
|
@@ -1160,19 +1183,34 @@ class RelationshipManager:
|
|
|
1160
1183
|
data=details.peers_database[rel.peer_id],
|
|
1161
1184
|
db=db,
|
|
1162
1185
|
)
|
|
1186
|
+
relationship_mapper.add_updated_relationship(
|
|
1187
|
+
relationship=rel,
|
|
1188
|
+
old_data=details.peers_database[rel.peer_id],
|
|
1189
|
+
properties_to_update=properties_not_matching,
|
|
1190
|
+
)
|
|
1191
|
+
elif rel.schema.kind == RelationshipKind.PARENT:
|
|
1192
|
+
relationship_mapper.add_parent_from_relationship(relationship=rel)
|
|
1163
1193
|
|
|
1164
|
-
return
|
|
1194
|
+
return relationship_mapper.changelog
|
|
1165
1195
|
|
|
1166
|
-
async def delete(
|
|
1196
|
+
async def delete(
|
|
1197
|
+
self, db: InfrahubDatabase, at: Optional[Timestamp] = None
|
|
1198
|
+
) -> RelationshipCardinalityManyChangelog | RelationshipCardinalityOneChangelog:
|
|
1167
1199
|
"""Delete all the relationships."""
|
|
1168
1200
|
|
|
1169
1201
|
delete_at = Timestamp(at)
|
|
1202
|
+
relationship_mapper = ChangelogRelationshipMapper(schema=self.schema)
|
|
1170
1203
|
|
|
1171
1204
|
await self._fetch_relationships(at=delete_at, db=db, force_refresh=True)
|
|
1172
1205
|
|
|
1173
1206
|
for rel in await self.get_relationships(db=db):
|
|
1207
|
+
relationship_mapper.delete_relationship(
|
|
1208
|
+
peer_kind=rel.get_peer_kind(), peer_id=rel.get_peer_id(), rel_schema=rel.schema
|
|
1209
|
+
)
|
|
1174
1210
|
await rel.delete(at=delete_at, db=db)
|
|
1175
1211
|
|
|
1212
|
+
return relationship_mapper.changelog
|
|
1213
|
+
|
|
1176
1214
|
async def to_graphql(
|
|
1177
1215
|
self, db: InfrahubDatabase, fields: Optional[dict] = None, related_node_ids: Optional[set] = None
|
|
1178
1216
|
) -> Union[dict, None]:
|
|
@@ -1188,7 +1226,7 @@ class RelationshipManager:
|
|
|
1188
1226
|
|
|
1189
1227
|
async def _validate_hierarchy(self) -> None:
|
|
1190
1228
|
schema = self.node.get_schema()
|
|
1191
|
-
if schema.is_profile_schema or not schema.hierarchy: # type: ignore[union-attr]
|
|
1229
|
+
if schema.is_profile_schema or schema.is_template_schema or not schema.hierarchy: # type: ignore[union-attr]
|
|
1192
1230
|
return
|
|
1193
1231
|
|
|
1194
1232
|
if self.name == "parent" and not schema.parent: # type: ignore[union-attr]
|
infrahub/core/schema/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import uuid
|
|
4
|
-
from typing import Any,
|
|
4
|
+
from typing import Any, TypeAlias
|
|
5
5
|
|
|
6
6
|
from infrahub_sdk.utils import deep_merge_dict
|
|
7
7
|
from pydantic import BaseModel, ConfigDict, Field
|
|
@@ -19,8 +19,9 @@ from .generic_schema import GenericSchema
|
|
|
19
19
|
from .node_schema import NodeSchema
|
|
20
20
|
from .profile_schema import ProfileSchema
|
|
21
21
|
from .relationship_schema import RelationshipSchema
|
|
22
|
+
from .template_schema import TemplateSchema
|
|
22
23
|
|
|
23
|
-
MainSchemaTypes: TypeAlias =
|
|
24
|
+
MainSchemaTypes: TypeAlias = NodeSchema | GenericSchema | ProfileSchema | TemplateSchema
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
# -----------------------------------------------------
|
|
@@ -44,7 +45,7 @@ class SchemaExtension(HashableModel):
|
|
|
44
45
|
|
|
45
46
|
class SchemaRoot(BaseModel):
|
|
46
47
|
model_config = ConfigDict(extra="forbid")
|
|
47
|
-
version:
|
|
48
|
+
version: str | None = Field(default=None)
|
|
48
49
|
generics: list[GenericSchema] = Field(default_factory=list)
|
|
49
50
|
nodes: list[NodeSchema] = Field(default_factory=list)
|
|
50
51
|
extensions: SchemaExtension = SchemaExtension()
|
|
@@ -59,7 +60,7 @@ class SchemaRoot(BaseModel):
|
|
|
59
60
|
|
|
60
61
|
return True
|
|
61
62
|
|
|
62
|
-
def get(self, name: str) ->
|
|
63
|
+
def get(self, name: str) -> NodeSchema | GenericSchema:
|
|
63
64
|
"""Check if a schema exist locally as a node or as a generic."""
|
|
64
65
|
|
|
65
66
|
for item in self.nodes + self.generics:
|
|
@@ -107,6 +108,7 @@ __all__ = [
|
|
|
107
108
|
"SchemaAttributePath",
|
|
108
109
|
"SchemaAttributePathValue",
|
|
109
110
|
"SchemaRoot",
|
|
111
|
+
"TemplateSchema",
|
|
110
112
|
"core_models",
|
|
111
113
|
"internal_schema",
|
|
112
114
|
]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import enum
|
|
4
|
+
from enum import Enum
|
|
4
5
|
from typing import TYPE_CHECKING, Any, Optional, Union
|
|
5
6
|
|
|
6
7
|
from pydantic import field_validator, model_validator
|
|
@@ -36,6 +37,13 @@ class AttributeSchema(GeneratedAttributeSchema):
|
|
|
36
37
|
def is_deprecated(self) -> bool:
|
|
37
38
|
return bool(self.deprecation)
|
|
38
39
|
|
|
40
|
+
def to_dict(self) -> dict:
|
|
41
|
+
data = self.model_dump(exclude_unset=True, exclude_none=True, exclude_defaults=True)
|
|
42
|
+
for field_name, value in data.items():
|
|
43
|
+
if isinstance(value, Enum):
|
|
44
|
+
data[field_name] = value.value
|
|
45
|
+
return data
|
|
46
|
+
|
|
39
47
|
@field_validator("kind")
|
|
40
48
|
@classmethod
|
|
41
49
|
def kind_options(cls, v: str) -> str:
|
|
@@ -4,6 +4,7 @@ import hashlib
|
|
|
4
4
|
import keyword
|
|
5
5
|
import os
|
|
6
6
|
from dataclasses import asdict, dataclass
|
|
7
|
+
from enum import Enum
|
|
7
8
|
from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, Optional, Union, overload
|
|
8
9
|
|
|
9
10
|
from infrahub_sdk.utils import compare_lists, intersection
|
|
@@ -22,13 +23,11 @@ if TYPE_CHECKING:
|
|
|
22
23
|
from infrahub.core.schema import GenericSchema, NodeSchema
|
|
23
24
|
from infrahub.core.schema.schema_branch import SchemaBranch
|
|
24
25
|
|
|
25
|
-
# pylint: disable=redefined-builtin
|
|
26
|
-
|
|
27
26
|
|
|
28
27
|
NODE_METADATA_ATTRIBUTES = ["_source", "_owner"]
|
|
29
28
|
|
|
30
29
|
|
|
31
|
-
class BaseNodeSchema(GeneratedBaseNodeSchema):
|
|
30
|
+
class BaseNodeSchema(GeneratedBaseNodeSchema):
|
|
32
31
|
_exclude_from_hash: list[str] = ["attributes", "relationships"]
|
|
33
32
|
_sort_by: list[str] = ["namespace", "name"]
|
|
34
33
|
|
|
@@ -64,6 +63,17 @@ class BaseNodeSchema(GeneratedBaseNodeSchema): # pylint: disable=too-many-publi
|
|
|
64
63
|
Be careful hash generated from hash() have a salt by default and they will not be the same across run"""
|
|
65
64
|
return hash(self.get_hash())
|
|
66
65
|
|
|
66
|
+
def to_dict(self) -> dict:
|
|
67
|
+
data = self.model_dump(
|
|
68
|
+
exclude_unset=True, exclude_none=True, exclude_defaults=True, exclude={"attributes", "relationships"}
|
|
69
|
+
)
|
|
70
|
+
for field_name, value in data.items():
|
|
71
|
+
if isinstance(value, Enum):
|
|
72
|
+
data[field_name] = value.value
|
|
73
|
+
data["attributes"] = [attr.to_dict() for attr in self.attributes]
|
|
74
|
+
data["relationships"] = [rel.to_dict() for rel in self.relationships]
|
|
75
|
+
return data
|
|
76
|
+
|
|
67
77
|
def get_hash(self, display_values: bool = False) -> str:
|
|
68
78
|
"""Extend the Hash Calculation to account for attributes and relationships."""
|
|
69
79
|
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from .account import (
|
|
4
|
+
core_account,
|
|
5
|
+
core_account_token,
|
|
6
|
+
core_credential,
|
|
7
|
+
core_generic_account,
|
|
8
|
+
core_password_credential,
|
|
9
|
+
core_refresh_token,
|
|
10
|
+
)
|
|
11
|
+
from .artifact import core_artifact, core_artifact_definition, core_artifact_target
|
|
12
|
+
from .builtin import builtin_tag
|
|
13
|
+
from .check import core_check_definition
|
|
14
|
+
from .generator import core_generator_definition, core_generator_instance
|
|
15
|
+
from .graphql_query import core_graphql_query
|
|
16
|
+
from .group import core_generator_group, core_graphql_query_group, core_group, core_standard_group
|
|
17
|
+
from .ipam import builtin_ip_address, builtin_ip_prefix, builtin_ipam, core_ipam_namespace
|
|
18
|
+
from .lineage import lineage_owner, lineage_source
|
|
19
|
+
from .menu import generic_menu_item, menu_item
|
|
20
|
+
from .permission import (
|
|
21
|
+
core_account_group,
|
|
22
|
+
core_account_role,
|
|
23
|
+
core_base_permission,
|
|
24
|
+
core_global_permission,
|
|
25
|
+
core_object_permission,
|
|
26
|
+
)
|
|
27
|
+
from .profile import core_profile_schema_definition
|
|
28
|
+
from .propose_change import core_proposed_change
|
|
29
|
+
from .propose_change_comment import (
|
|
30
|
+
core_artifact_thread,
|
|
31
|
+
core_change_comment,
|
|
32
|
+
core_change_thread,
|
|
33
|
+
core_file_thread,
|
|
34
|
+
core_object_thread,
|
|
35
|
+
core_propose_change_comment,
|
|
36
|
+
core_thread,
|
|
37
|
+
core_thread_comment,
|
|
38
|
+
)
|
|
39
|
+
from .propose_change_validator import (
|
|
40
|
+
core_artifact_check,
|
|
41
|
+
core_artifact_validator,
|
|
42
|
+
core_check,
|
|
43
|
+
core_data_check,
|
|
44
|
+
core_data_validator,
|
|
45
|
+
core_file_check,
|
|
46
|
+
core_generator_check,
|
|
47
|
+
core_generator_validator,
|
|
48
|
+
core_propose_change_validator,
|
|
49
|
+
core_repository_validator,
|
|
50
|
+
core_schema_check,
|
|
51
|
+
core_schema_validator,
|
|
52
|
+
core_standard_check,
|
|
53
|
+
core_user_validator,
|
|
54
|
+
)
|
|
55
|
+
from .repository import core_generic_repository, core_read_only_repository, core_repository
|
|
56
|
+
from .resource_pool import core_ip_address_pool, core_ip_prefix_pool, core_number_pool, core_resource_pool
|
|
57
|
+
from .template import core_object_template
|
|
58
|
+
from .transform import core_transform, core_transform_jinja2, core_transform_python
|
|
59
|
+
from .webhook import core_custom_webhook, core_standard_webhook, core_webhook
|
|
60
|
+
|
|
61
|
+
core_node = {
|
|
62
|
+
"name": "Node",
|
|
63
|
+
"namespace": "Core",
|
|
64
|
+
"include_in_menu": False,
|
|
65
|
+
"description": "Base Node in Infrahub.",
|
|
66
|
+
"label": "Node",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
core_task_target = {
|
|
70
|
+
"name": "TaskTarget",
|
|
71
|
+
"include_in_menu": False,
|
|
72
|
+
"namespace": "Core",
|
|
73
|
+
"description": "Extend a node to be associated with tasks",
|
|
74
|
+
"label": "Task Target",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
core_models: dict[str, Any] = {
|
|
78
|
+
"generics": [
|
|
79
|
+
core_node,
|
|
80
|
+
lineage_owner,
|
|
81
|
+
core_profile_schema_definition,
|
|
82
|
+
lineage_source,
|
|
83
|
+
core_propose_change_comment,
|
|
84
|
+
core_thread,
|
|
85
|
+
core_group,
|
|
86
|
+
core_propose_change_validator,
|
|
87
|
+
core_check,
|
|
88
|
+
core_transform,
|
|
89
|
+
core_artifact_target,
|
|
90
|
+
core_task_target,
|
|
91
|
+
core_webhook,
|
|
92
|
+
core_generic_repository,
|
|
93
|
+
builtin_ipam,
|
|
94
|
+
builtin_ip_prefix,
|
|
95
|
+
builtin_ip_address,
|
|
96
|
+
core_resource_pool,
|
|
97
|
+
core_generic_account,
|
|
98
|
+
core_base_permission,
|
|
99
|
+
core_credential,
|
|
100
|
+
core_object_template,
|
|
101
|
+
generic_menu_item,
|
|
102
|
+
],
|
|
103
|
+
"nodes": [
|
|
104
|
+
menu_item,
|
|
105
|
+
core_standard_group,
|
|
106
|
+
core_generator_group,
|
|
107
|
+
core_graphql_query_group,
|
|
108
|
+
builtin_tag,
|
|
109
|
+
core_account,
|
|
110
|
+
core_account_token,
|
|
111
|
+
core_password_credential,
|
|
112
|
+
core_refresh_token,
|
|
113
|
+
core_proposed_change,
|
|
114
|
+
core_change_thread,
|
|
115
|
+
core_file_thread,
|
|
116
|
+
core_artifact_thread,
|
|
117
|
+
core_object_thread,
|
|
118
|
+
core_change_comment,
|
|
119
|
+
core_thread_comment,
|
|
120
|
+
core_repository.to_dict(),
|
|
121
|
+
core_read_only_repository,
|
|
122
|
+
core_transform_jinja2,
|
|
123
|
+
core_data_check,
|
|
124
|
+
core_standard_check,
|
|
125
|
+
core_schema_check,
|
|
126
|
+
core_file_check,
|
|
127
|
+
core_artifact_check,
|
|
128
|
+
core_generator_check,
|
|
129
|
+
core_data_validator,
|
|
130
|
+
core_repository_validator,
|
|
131
|
+
core_user_validator,
|
|
132
|
+
core_schema_validator,
|
|
133
|
+
core_artifact_validator,
|
|
134
|
+
core_generator_validator,
|
|
135
|
+
core_check_definition,
|
|
136
|
+
core_transform_python,
|
|
137
|
+
core_graphql_query,
|
|
138
|
+
core_artifact,
|
|
139
|
+
core_artifact_definition,
|
|
140
|
+
core_generator_definition,
|
|
141
|
+
core_generator_instance,
|
|
142
|
+
core_standard_webhook,
|
|
143
|
+
core_custom_webhook,
|
|
144
|
+
core_ipam_namespace,
|
|
145
|
+
core_ip_prefix_pool,
|
|
146
|
+
core_ip_address_pool,
|
|
147
|
+
core_number_pool,
|
|
148
|
+
core_global_permission,
|
|
149
|
+
core_object_permission,
|
|
150
|
+
core_account_role,
|
|
151
|
+
core_account_group,
|
|
152
|
+
],
|
|
153
|
+
}
|