infrahub-server 1.1.7__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 +50 -21
- infrahub/core/branch/models.py +4 -4
- infrahub/core/branch/tasks.py +130 -125
- 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 +1 -1
- infrahub/core/diff/enricher/cardinality_one.py +6 -1
- infrahub/core/diff/enricher/hierarchy.py +22 -7
- infrahub/core/diff/enricher/labels.py +6 -1
- infrahub/core/diff/enricher/path_identifier.py +5 -1
- infrahub/core/diff/enricher/summary_counts.py +107 -0
- infrahub/core/diff/merger/merger.py +3 -1
- infrahub/core/diff/model/path.py +34 -11
- infrahub/core/diff/parent_node_adder.py +78 -0
- infrahub/core/diff/payload_builder.py +13 -2
- infrahub/core/diff/query/all_conflicts.py +1 -1
- infrahub/core/diff/query/artifact.py +1 -1
- infrahub/core/diff/query/delete_query.py +1 -1
- infrahub/core/diff/query/diff_get.py +1 -1
- infrahub/core/diff/query/diff_summary.py +1 -1
- infrahub/core/diff/query/field_specifiers.py +1 -1
- infrahub/core/diff/query/field_summary.py +1 -1
- infrahub/core/diff/query/filters.py +2 -2
- infrahub/core/diff/query/get_conflict_query.py +1 -1
- infrahub/core/diff/query/has_conflicts_query.py +1 -1
- infrahub/core/diff/query/merge.py +3 -3
- infrahub/core/diff/query/merge_tracking_id.py +1 -1
- infrahub/core/diff/query/roots_metadata.py +1 -1
- infrahub/core/diff/query/save.py +191 -185
- infrahub/core/diff/query/summary_counts_enricher.py +52 -5
- infrahub/core/diff/query/time_range_query.py +1 -1
- infrahub/core/diff/query/update_conflict_query.py +1 -1
- infrahub/core/diff/repository/deserializer.py +9 -4
- infrahub/core/diff/repository/repository.py +156 -38
- 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 +164 -45
- infrahub/core/node/base.py +1 -1
- infrahub/core/node/delete_validator.py +4 -4
- infrahub/core/node/ipam.py +7 -7
- 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 +4 -4
- infrahub/core/query/ipam.py +4 -4
- infrahub/core/query/node.py +11 -12
- infrahub/core/query/relationship.py +211 -25
- infrahub/core/query/resource_manager.py +10 -10
- 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 +2 -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 +1 -1
- infrahub/database/__init__.py +3 -2
- infrahub/database/memgraph.py +1 -1
- infrahub/dependencies/builder/diff/combiner.py +1 -1
- infrahub/dependencies/builder/diff/conflicts_enricher.py +1 -1
- 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 +8 -0
- 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 -15
- infrahub/graphql/mutations/diff.py +33 -17
- 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 +233 -45
- infrahub/graphql/mutations/menu.py +10 -10
- infrahub/graphql/mutations/proposed_change.py +36 -28
- infrahub/graphql/mutations/relationship.py +341 -130
- 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 +10 -7
- 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 +37 -25
- 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/globals.py +15 -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/batch.py +2 -2
- infrahub_sdk/client.py +8 -0
- infrahub_sdk/config.py +1 -1
- infrahub_sdk/ctl/branch.py +3 -2
- infrahub_sdk/ctl/check.py +4 -4
- 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 +6 -21
- infrahub_sdk/ctl/validate.py +2 -1
- infrahub_sdk/data.py +1 -1
- infrahub_sdk/exceptions.py +12 -0
- infrahub_sdk/generator.py +3 -0
- infrahub_sdk/node.py +5 -8
- infrahub_sdk/protocols.py +20 -8
- infrahub_sdk/schema/__init__.py +14 -5
- 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/testing/docker.py +30 -0
- infrahub_sdk/timestamp.py +134 -33
- infrahub_sdk/transfer/exporter/json.py +1 -1
- infrahub_sdk/utils.py +39 -1
- infrahub_sdk/yaml.py +2 -3
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/METADATA +7 -6
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/RECORD +383 -339
- infrahub_testcontainers/container.py +2 -3
- infrahub_testcontainers/docker-compose.test.yml +2 -2
- 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/{schema → artifacts}/__init__.py +0 -0
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/WHEEL +0 -0
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/entry_points.txt +0 -0
infrahub/api/artifact.py
CHANGED
|
@@ -5,7 +5,14 @@ from typing import TYPE_CHECKING
|
|
|
5
5
|
from fastapi import APIRouter, Body, Depends, Request, Response
|
|
6
6
|
from pydantic import BaseModel, Field
|
|
7
7
|
|
|
8
|
-
from infrahub.api.dependencies import
|
|
8
|
+
from infrahub.api.dependencies import (
|
|
9
|
+
BranchParams,
|
|
10
|
+
get_branch_params,
|
|
11
|
+
get_context,
|
|
12
|
+
get_current_user,
|
|
13
|
+
get_db,
|
|
14
|
+
get_permission_manager,
|
|
15
|
+
)
|
|
9
16
|
from infrahub.core import registry
|
|
10
17
|
from infrahub.core.account import ObjectPermission
|
|
11
18
|
from infrahub.core.constants import GLOBAL_BRANCH_NAME, InfrahubKind, PermissionAction
|
|
@@ -19,7 +26,9 @@ from infrahub.workflows.catalogue import REQUEST_ARTIFACT_DEFINITION_GENERATE
|
|
|
19
26
|
|
|
20
27
|
if TYPE_CHECKING:
|
|
21
28
|
from infrahub.auth import AccountSession
|
|
29
|
+
from infrahub.context import InfrahubContext
|
|
22
30
|
from infrahub.permissions import PermissionManager
|
|
31
|
+
from infrahub.services import InfrahubServices
|
|
23
32
|
|
|
24
33
|
log = get_logger()
|
|
25
34
|
router = APIRouter(prefix="/artifact")
|
|
@@ -57,12 +66,13 @@ async def generate_artifact(
|
|
|
57
66
|
request: Request,
|
|
58
67
|
artifact_definition_id: str,
|
|
59
68
|
payload: ArtifactGeneratePayload = Body(
|
|
60
|
-
ArtifactGeneratePayload(),
|
|
69
|
+
ArtifactGeneratePayload(), # noqa: B008
|
|
61
70
|
description="Payload of the request, can be used to limit the scope of the query to a specific list of hosts",
|
|
62
71
|
),
|
|
63
72
|
db: InfrahubDatabase = Depends(get_db),
|
|
64
73
|
branch_params: BranchParams = Depends(get_branch_params),
|
|
65
74
|
permission_manager: PermissionManager = Depends(get_permission_manager),
|
|
75
|
+
context: InfrahubContext = Depends(get_context),
|
|
66
76
|
) -> None:
|
|
67
77
|
permission_decision = (
|
|
68
78
|
PermissionDecisionFlag.ALLOW_DEFAULT
|
|
@@ -83,7 +93,7 @@ async def generate_artifact(
|
|
|
83
93
|
branch=branch_params.branch,
|
|
84
94
|
)
|
|
85
95
|
|
|
86
|
-
service = request.app.state.service
|
|
96
|
+
service: InfrahubServices = request.app.state.service
|
|
87
97
|
model = RequestArtifactDefinitionGenerate(
|
|
88
98
|
artifact_definition_id=artifact_definition.id,
|
|
89
99
|
artifact_definition_name=artifact_definition.name.value,
|
|
@@ -91,4 +101,6 @@ async def generate_artifact(
|
|
|
91
101
|
limit=payload.nodes,
|
|
92
102
|
)
|
|
93
103
|
|
|
94
|
-
await service.workflow.submit_workflow(
|
|
104
|
+
await service.workflow.submit_workflow(
|
|
105
|
+
workflow=REQUEST_ARTIFACT_DEFINITION_GENERATE, context=context, parameters={"model": model}
|
|
106
|
+
)
|
infrahub/api/dependencies.py
CHANGED
|
@@ -8,6 +8,7 @@ from pydantic import BaseModel, ConfigDict
|
|
|
8
8
|
|
|
9
9
|
from infrahub import config
|
|
10
10
|
from infrahub.auth import AccountSession, authentication_token, validate_jwt_access_token, validate_jwt_refresh_token
|
|
11
|
+
from infrahub.context import InfrahubContext
|
|
11
12
|
from infrahub.core.branch import Branch # noqa: TC001
|
|
12
13
|
from infrahub.core.registry import registry
|
|
13
14
|
from infrahub.core.timestamp import Timestamp
|
|
@@ -133,3 +134,10 @@ async def get_permission_manager(
|
|
|
133
134
|
await permission_manager.load_permissions(db=db, branch=branch_params.branch)
|
|
134
135
|
|
|
135
136
|
return permission_manager
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
async def get_context(
|
|
140
|
+
branch: Branch = Depends(get_branch_dep),
|
|
141
|
+
account_session: AccountSession = Depends(get_current_user),
|
|
142
|
+
) -> InfrahubContext:
|
|
143
|
+
return InfrahubContext.init(branch=branch, account=account_session)
|
infrahub/api/oauth2.py
CHANGED
infrahub/api/oidc.py
CHANGED
infrahub/api/query.py
CHANGED
|
@@ -7,6 +7,7 @@ from graphql import graphql
|
|
|
7
7
|
from pydantic import BaseModel, Field
|
|
8
8
|
|
|
9
9
|
from infrahub.api.dependencies import BranchParams, get_branch_params, get_current_user, get_db
|
|
10
|
+
from infrahub.context import InfrahubContext
|
|
10
11
|
from infrahub.core import registry
|
|
11
12
|
from infrahub.core.constants import InfrahubKind
|
|
12
13
|
from infrahub.core.protocols import CoreGraphQLQuery
|
|
@@ -57,12 +58,21 @@ async def execute_query(
|
|
|
57
58
|
db=db, id=query_id, kind=CoreGraphQLQuery, branch=branch_params.branch, at=branch_params.at
|
|
58
59
|
)
|
|
59
60
|
|
|
61
|
+
context = InfrahubContext.init(branch=branch_params.branch, account=account_session)
|
|
62
|
+
|
|
60
63
|
gql_params = await prepare_graphql_params(
|
|
61
|
-
db=db,
|
|
64
|
+
db=db,
|
|
65
|
+
branch=branch_params.branch,
|
|
66
|
+
at=branch_params.at,
|
|
67
|
+
account_session=account_session,
|
|
68
|
+
service=request.app.state.service,
|
|
62
69
|
)
|
|
70
|
+
schema_branch = db.schema.get_schema_branch(name=branch_params.branch.name)
|
|
71
|
+
|
|
63
72
|
analyzed_query = InfrahubGraphQLQueryAnalyzer(
|
|
64
73
|
query=gql_query.query.value,
|
|
65
74
|
schema=gql_params.schema,
|
|
75
|
+
schema_branch=schema_branch,
|
|
66
76
|
branch=branch_params.branch,
|
|
67
77
|
)
|
|
68
78
|
await permission_checker.check(
|
|
@@ -97,9 +107,7 @@ async def execute_query(
|
|
|
97
107
|
GRAPHQL_QUERY_HEIGHT_METRICS.labels(**labels).observe(await analyzed_query.calculate_height())
|
|
98
108
|
GRAPHQL_QUERY_VARS_METRICS.labels(**labels).observe(len(analyzed_query.variables))
|
|
99
109
|
GRAPHQL_TOP_LEVEL_QUERIES_METRICS.labels(**labels).observe(analyzed_query.nbr_queries)
|
|
100
|
-
GRAPHQL_QUERY_OBJECTS_METRICS.labels(**labels).observe(
|
|
101
|
-
len(await analyzed_query.get_models_in_use(types=gql_params.context.types))
|
|
102
|
-
)
|
|
110
|
+
GRAPHQL_QUERY_OBJECTS_METRICS.labels(**labels).observe(len(analyzed_query.query_report.impacted_models))
|
|
103
111
|
|
|
104
112
|
response_payload: dict[str, Any] = {"data": data}
|
|
105
113
|
|
|
@@ -111,11 +119,13 @@ async def execute_query(
|
|
|
111
119
|
branch=branch_params.branch.name,
|
|
112
120
|
query_id=gql_query.id,
|
|
113
121
|
query_name=gql_query.name.value,
|
|
114
|
-
related_node_ids=sorted(
|
|
122
|
+
related_node_ids=sorted(related_node_ids),
|
|
115
123
|
subscribers=sorted(subscribers),
|
|
116
124
|
params=params,
|
|
117
125
|
)
|
|
118
|
-
await service.workflow.submit_workflow(
|
|
126
|
+
await service.workflow.submit_workflow(
|
|
127
|
+
workflow=GRAPHQL_QUERY_GROUP_UPDATE, context=context, parameters={"model": model}
|
|
128
|
+
)
|
|
119
129
|
|
|
120
130
|
return response_payload
|
|
121
131
|
|
|
@@ -124,7 +134,8 @@ async def execute_query(
|
|
|
124
134
|
async def graphql_query_post(
|
|
125
135
|
request: Request,
|
|
126
136
|
payload: QueryPayload = Body(
|
|
127
|
-
QueryPayload(),
|
|
137
|
+
QueryPayload(), # noqa: B008
|
|
138
|
+
description="Payload of the request, must be used to provide the variables",
|
|
128
139
|
),
|
|
129
140
|
query_id: str = Path(description="ID or Name of the GraphQL query to execute"),
|
|
130
141
|
subscribers: list[str] = Query(
|
infrahub/api/schema.py
CHANGED
|
@@ -13,7 +13,7 @@ from pydantic import (
|
|
|
13
13
|
from starlette.responses import JSONResponse
|
|
14
14
|
|
|
15
15
|
from infrahub import lock
|
|
16
|
-
from infrahub.api.dependencies import get_branch_dep, get_current_user, get_db, get_permission_manager
|
|
16
|
+
from infrahub.api.dependencies import get_branch_dep, get_context, get_current_user, get_db, get_permission_manager
|
|
17
17
|
from infrahub.api.exceptions import SchemaNotValidError
|
|
18
18
|
from infrahub.core import registry
|
|
19
19
|
from infrahub.core.account import GlobalPermission
|
|
@@ -25,7 +25,7 @@ from infrahub.core.models import ( # noqa: TC001
|
|
|
25
25
|
SchemaDiff,
|
|
26
26
|
SchemaUpdateValidationResult,
|
|
27
27
|
)
|
|
28
|
-
from infrahub.core.schema import GenericSchema, MainSchemaTypes, NodeSchema, ProfileSchema, SchemaRoot
|
|
28
|
+
from infrahub.core.schema import GenericSchema, MainSchemaTypes, NodeSchema, ProfileSchema, SchemaRoot, TemplateSchema
|
|
29
29
|
from infrahub.core.schema.constants import SchemaNamespace # noqa: TC001
|
|
30
30
|
from infrahub.core.validators.models.validate_migration import (
|
|
31
31
|
SchemaValidateMigrationData,
|
|
@@ -44,6 +44,7 @@ if TYPE_CHECKING:
|
|
|
44
44
|
from typing_extensions import Self
|
|
45
45
|
|
|
46
46
|
from infrahub.auth import AccountSession
|
|
47
|
+
from infrahub.context import InfrahubContext
|
|
47
48
|
from infrahub.core.schema.schema_branch import SchemaBranch
|
|
48
49
|
from infrahub.permissions import PermissionManager
|
|
49
50
|
from infrahub.services import InfrahubServices
|
|
@@ -86,11 +87,17 @@ class APIProfileSchema(ProfileSchema, APISchemaMixin):
|
|
|
86
87
|
hash: str
|
|
87
88
|
|
|
88
89
|
|
|
90
|
+
class APITemplateSchema(TemplateSchema, APISchemaMixin):
|
|
91
|
+
api_kind: str | None = Field(default=None, alias="kind", validate_default=True)
|
|
92
|
+
hash: str
|
|
93
|
+
|
|
94
|
+
|
|
89
95
|
class SchemaReadAPI(BaseModel):
|
|
90
96
|
main: str = Field(description="Main hash for the entire schema")
|
|
91
97
|
nodes: list[APINodeSchema] = Field(default_factory=list)
|
|
92
98
|
generics: list[APIGenericSchema] = Field(default_factory=list)
|
|
93
99
|
profiles: list[APIProfileSchema] = Field(default_factory=list)
|
|
100
|
+
templates: list[APITemplateSchema] = Field(default_factory=list)
|
|
94
101
|
namespaces: list[SchemaNamespace] = Field(default_factory=list)
|
|
95
102
|
|
|
96
103
|
|
|
@@ -190,6 +197,11 @@ async def get_schema(
|
|
|
190
197
|
for value in all_schemas
|
|
191
198
|
if isinstance(value, ProfileSchema) and value.namespace != "Internal"
|
|
192
199
|
],
|
|
200
|
+
templates=[
|
|
201
|
+
APITemplateSchema.from_schema(value)
|
|
202
|
+
for value in all_schemas
|
|
203
|
+
if isinstance(value, TemplateSchema) and value.namespace != "Internal"
|
|
204
|
+
],
|
|
193
205
|
namespaces=schema_branch.get_namespaces(),
|
|
194
206
|
)
|
|
195
207
|
|
|
@@ -206,15 +218,16 @@ async def get_schema_summary(
|
|
|
206
218
|
@router.get("/{schema_kind}")
|
|
207
219
|
async def get_schema_by_kind(
|
|
208
220
|
schema_kind: str, branch: Branch = Depends(get_branch_dep), _: AccountSession = Depends(get_current_user)
|
|
209
|
-
) -> APIProfileSchema | APINodeSchema | APIGenericSchema:
|
|
221
|
+
) -> APIProfileSchema | APINodeSchema | APIGenericSchema | APITemplateSchema:
|
|
210
222
|
log.debug("schema_kind_request", branch=branch.name)
|
|
211
223
|
|
|
212
224
|
schema = registry.schema.get(name=schema_kind, branch=branch, duplicate=False)
|
|
213
225
|
|
|
214
|
-
api_schema: dict[str, type[APIProfileSchema | APINodeSchema | APIGenericSchema]] = {
|
|
226
|
+
api_schema: dict[str, type[APIProfileSchema | APINodeSchema | APIGenericSchema | APITemplateSchema]] = {
|
|
215
227
|
"profile": APIProfileSchema,
|
|
216
228
|
"node": APINodeSchema,
|
|
217
229
|
"generic": APIGenericSchema,
|
|
230
|
+
"template": APITemplateSchema,
|
|
218
231
|
}
|
|
219
232
|
key = ""
|
|
220
233
|
|
|
@@ -224,6 +237,8 @@ async def get_schema_by_kind(
|
|
|
224
237
|
key = "node"
|
|
225
238
|
if isinstance(schema, GenericSchema):
|
|
226
239
|
key = "generic"
|
|
240
|
+
if isinstance(schema, TemplateSchema):
|
|
241
|
+
key = "template"
|
|
227
242
|
|
|
228
243
|
return api_schema[key].from_schema(schema=schema)
|
|
229
244
|
|
|
@@ -269,6 +284,7 @@ async def load_schema(
|
|
|
269
284
|
branch: Branch = Depends(get_branch_dep),
|
|
270
285
|
account_session: AccountSession = Depends(get_current_user),
|
|
271
286
|
permission_manager: PermissionManager = Depends(get_permission_manager),
|
|
287
|
+
context: InfrahubContext = Depends(get_context),
|
|
272
288
|
) -> SchemaUpdate:
|
|
273
289
|
permission_manager.raise_for_permission(
|
|
274
290
|
permission=GlobalPermission(
|
|
@@ -317,6 +333,7 @@ async def load_schema(
|
|
|
317
333
|
)
|
|
318
334
|
responses = await service.workflow.execute_workflow(
|
|
319
335
|
workflow=SCHEMA_VALIDATE_MIGRATION,
|
|
336
|
+
context=context,
|
|
320
337
|
expected_return=list[SchemaValidatorPathResponseData],
|
|
321
338
|
parameters={"message": validate_migration_data},
|
|
322
339
|
)
|
|
@@ -361,6 +378,7 @@ async def load_schema(
|
|
|
361
378
|
)
|
|
362
379
|
migration_error_msgs = await service.workflow.execute_workflow(
|
|
363
380
|
workflow=SCHEMA_APPLY_MIGRATION,
|
|
381
|
+
context=context,
|
|
364
382
|
expected_return=list[str],
|
|
365
383
|
parameters={"message": apply_migration_data},
|
|
366
384
|
)
|
|
@@ -373,9 +391,15 @@ async def load_schema(
|
|
|
373
391
|
log_data = get_log_data()
|
|
374
392
|
request_id = log_data.get("request_id", "")
|
|
375
393
|
event = SchemaUpdatedEvent(
|
|
376
|
-
|
|
394
|
+
branch_name=branch.name,
|
|
377
395
|
schema_hash=branch.active_schema_hash.main,
|
|
378
|
-
meta=EventMeta(
|
|
396
|
+
meta=EventMeta(
|
|
397
|
+
initiator_id=WORKER_IDENTITY,
|
|
398
|
+
request_id=request_id,
|
|
399
|
+
account_id=account_session.account_id,
|
|
400
|
+
branch=branch,
|
|
401
|
+
context=context,
|
|
402
|
+
),
|
|
379
403
|
)
|
|
380
404
|
await service.event.send(event=event)
|
|
381
405
|
|
|
@@ -387,6 +411,7 @@ async def check_schema(
|
|
|
387
411
|
request: Request,
|
|
388
412
|
schemas: SchemasLoadAPI,
|
|
389
413
|
branch: Branch = Depends(get_branch_dep),
|
|
414
|
+
context: InfrahubContext = Depends(get_context),
|
|
390
415
|
_: AccountSession = Depends(get_current_user),
|
|
391
416
|
) -> JSONResponse:
|
|
392
417
|
service: InfrahubServices = request.app.state.service
|
|
@@ -413,6 +438,7 @@ async def check_schema(
|
|
|
413
438
|
)
|
|
414
439
|
responses = await service.workflow.execute_workflow(
|
|
415
440
|
workflow=SCHEMA_VALIDATE_MIGRATION,
|
|
441
|
+
context=context,
|
|
416
442
|
expected_return=list[SchemaValidatorPathResponseData],
|
|
417
443
|
parameters={"message": validate_migration_data},
|
|
418
444
|
)
|
infrahub/api/transformation.py
CHANGED
|
@@ -9,6 +9,7 @@ from starlette.responses import JSONResponse, PlainTextResponse
|
|
|
9
9
|
from infrahub.api.dependencies import (
|
|
10
10
|
BranchParams,
|
|
11
11
|
get_branch_params,
|
|
12
|
+
get_context,
|
|
12
13
|
get_current_user,
|
|
13
14
|
get_db,
|
|
14
15
|
)
|
|
@@ -28,8 +29,8 @@ from infrahub.workflows.catalogue import TRANSFORM_JINJA2_RENDER, TRANSFORM_PYTH
|
|
|
28
29
|
|
|
29
30
|
if TYPE_CHECKING:
|
|
30
31
|
from infrahub.auth import AccountSession
|
|
32
|
+
from infrahub.context import InfrahubContext
|
|
31
33
|
from infrahub.services import InfrahubServices
|
|
32
|
-
|
|
33
34
|
router = APIRouter()
|
|
34
35
|
|
|
35
36
|
|
|
@@ -38,6 +39,7 @@ async def transform_python(
|
|
|
38
39
|
request: Request,
|
|
39
40
|
transform_id: str,
|
|
40
41
|
db: InfrahubDatabase = Depends(get_db),
|
|
42
|
+
context: InfrahubContext = Depends(get_context),
|
|
41
43
|
branch_params: BranchParams = Depends(get_branch_params),
|
|
42
44
|
_: AccountSession = Depends(get_current_user),
|
|
43
45
|
) -> JSONResponse:
|
|
@@ -62,7 +64,9 @@ async def transform_python(
|
|
|
62
64
|
message="Repository doesn't have a commit",
|
|
63
65
|
)
|
|
64
66
|
|
|
65
|
-
gql_params = await prepare_graphql_params(
|
|
67
|
+
gql_params = await prepare_graphql_params(
|
|
68
|
+
db=request.app.state.db, branch=branch_params.branch, at=branch_params.at, service=request.app.state.service
|
|
69
|
+
)
|
|
66
70
|
|
|
67
71
|
result = await graphql(
|
|
68
72
|
schema=gql_params.schema,
|
|
@@ -88,7 +92,7 @@ async def transform_python(
|
|
|
88
92
|
)
|
|
89
93
|
|
|
90
94
|
response = await service.workflow.execute_workflow(
|
|
91
|
-
workflow=TRANSFORM_PYTHON_RENDER, parameters={"message": message}
|
|
95
|
+
workflow=TRANSFORM_PYTHON_RENDER, context=context, parameters={"message": message}
|
|
92
96
|
)
|
|
93
97
|
return JSONResponse(content=response)
|
|
94
98
|
|
|
@@ -99,6 +103,7 @@ async def transform_jinja2(
|
|
|
99
103
|
transform_id: str = Path(description="ID or Name of the Jinja2 Transform to render"),
|
|
100
104
|
db: InfrahubDatabase = Depends(get_db),
|
|
101
105
|
branch_params: BranchParams = Depends(get_branch_params),
|
|
106
|
+
context: InfrahubContext = Depends(get_context),
|
|
102
107
|
_: AccountSession = Depends(get_current_user),
|
|
103
108
|
) -> PlainTextResponse:
|
|
104
109
|
params = {key: value for key, value in request.query_params.items() if key not in ["branch", "at"]}
|
|
@@ -122,7 +127,9 @@ async def transform_jinja2(
|
|
|
122
127
|
message="Repository doesn't have a commit",
|
|
123
128
|
)
|
|
124
129
|
|
|
125
|
-
gql_params = await prepare_graphql_params(
|
|
130
|
+
gql_params = await prepare_graphql_params(
|
|
131
|
+
db=request.app.state.db, branch=branch_params.branch, at=branch_params.at, service=request.app.state.service
|
|
132
|
+
)
|
|
126
133
|
|
|
127
134
|
result = await graphql(
|
|
128
135
|
schema=gql_params.schema,
|
|
@@ -148,6 +155,6 @@ async def transform_jinja2(
|
|
|
148
155
|
service: InfrahubServices = request.app.state.service
|
|
149
156
|
|
|
150
157
|
response = await service.workflow.execute_workflow(
|
|
151
|
-
workflow=TRANSFORM_JINJA2_RENDER, expected_return=str, parameters={"message": message}
|
|
158
|
+
workflow=TRANSFORM_JINJA2_RENDER, context=context, expected_return=str, parameters={"message": message}
|
|
152
159
|
)
|
|
153
160
|
return PlainTextResponse(content=response)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
|
|
3
|
-
from pydantic import Field
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
4
|
|
|
5
|
-
from infrahub.
|
|
5
|
+
from infrahub.context import InfrahubContext
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
class CheckArtifactCreate(
|
|
8
|
+
class CheckArtifactCreate(BaseModel):
|
|
9
9
|
"""Runs a check to verify the creation of an artifact."""
|
|
10
10
|
|
|
11
11
|
artifact_name: str = Field(..., description="Name of the artifact")
|
|
@@ -19,9 +19,11 @@ class CheckArtifactCreate(InfrahubMessage):
|
|
|
19
19
|
repository_kind: str = Field(..., description="The kind of the Repository")
|
|
20
20
|
branch_name: str = Field(..., description="The branch where the check is run")
|
|
21
21
|
target_id: str = Field(..., description="The ID of the target object for this artifact")
|
|
22
|
+
target_kind: str = Field(..., description="The kind of the target object for this artifact")
|
|
22
23
|
target_name: str = Field(..., description="Name of the artifact target")
|
|
23
24
|
artifact_id: Optional[str] = Field(default=None, description="The id of the artifact if it previously existed")
|
|
24
25
|
query: str = Field(..., description="The name of the query to use when collecting data")
|
|
25
26
|
timeout: int = Field(..., description="Timeout for requests used to generate this artifact")
|
|
26
27
|
variables: dict = Field(..., description="Input variables when generating the artifact")
|
|
27
28
|
validator_id: str = Field(..., description="The ID of the validator")
|
|
29
|
+
context: InfrahubContext = Field(..., description="The context of the task")
|
|
@@ -2,38 +2,38 @@ from typing import Union
|
|
|
2
2
|
|
|
3
3
|
from prefect import flow
|
|
4
4
|
|
|
5
|
+
from infrahub.artifacts.models import CheckArtifactCreate
|
|
5
6
|
from infrahub.core.constants import InfrahubKind, ValidatorConclusion
|
|
6
7
|
from infrahub.core.timestamp import Timestamp
|
|
7
|
-
from infrahub.git
|
|
8
|
-
from infrahub.log import get_logger
|
|
9
|
-
from infrahub.message_bus import messages
|
|
8
|
+
from infrahub.git import InfrahubReadOnlyRepository, InfrahubRepository
|
|
10
9
|
from infrahub.services import InfrahubServices
|
|
11
10
|
from infrahub.tasks.artifact import define_artifact
|
|
12
|
-
from infrahub.tasks.check import set_check_status
|
|
13
11
|
from infrahub.workflows.utils import add_tags
|
|
14
12
|
|
|
15
|
-
log = get_logger()
|
|
16
|
-
|
|
17
13
|
|
|
18
14
|
@flow(name="git-repository-check-artifact-create", flow_run_name="Check artifact creation")
|
|
19
|
-
async def create(
|
|
20
|
-
await add_tags(branches=[
|
|
21
|
-
validator = await service.client.get(
|
|
22
|
-
kind=InfrahubKind.ARTIFACTVALIDATOR, id=message.validator_id, include=["checks"]
|
|
23
|
-
)
|
|
15
|
+
async def create(model: CheckArtifactCreate, service: InfrahubServices) -> ValidatorConclusion:
|
|
16
|
+
await add_tags(branches=[model.branch_name], nodes=[model.target_id])
|
|
17
|
+
validator = await service.client.get(kind=InfrahubKind.ARTIFACTVALIDATOR, id=model.validator_id, include=["checks"])
|
|
24
18
|
|
|
19
|
+
repo: InfrahubReadOnlyRepository | InfrahubRepository
|
|
25
20
|
if InfrahubKind.READONLYREPOSITORY:
|
|
26
21
|
repo = await InfrahubReadOnlyRepository.init(
|
|
27
|
-
id=
|
|
22
|
+
id=model.repository_id,
|
|
23
|
+
name=model.repository_name,
|
|
24
|
+
client=service.client,
|
|
25
|
+
service=service,
|
|
28
26
|
)
|
|
29
27
|
else:
|
|
30
28
|
repo = await InfrahubRepository.init(
|
|
31
|
-
id=
|
|
29
|
+
id=model.repository_id,
|
|
30
|
+
name=model.repository_name,
|
|
31
|
+
client=service.client,
|
|
32
|
+
service=service,
|
|
32
33
|
)
|
|
33
34
|
|
|
34
|
-
artifact = await define_artifact(
|
|
35
|
+
artifact, artifact_created = await define_artifact(model=model, service=service)
|
|
35
36
|
|
|
36
|
-
conclusion = ValidatorConclusion.SUCCESS.value
|
|
37
37
|
severity = "info"
|
|
38
38
|
artifact_result: dict[str, Union[str, bool, None]] = {
|
|
39
39
|
"changed": None,
|
|
@@ -44,22 +44,23 @@ async def create(message: messages.CheckArtifactCreate, service: InfrahubService
|
|
|
44
44
|
check_message = "Failed to render artifact"
|
|
45
45
|
|
|
46
46
|
try:
|
|
47
|
-
result = await repo.render_artifact(artifact=artifact, message=
|
|
47
|
+
result = await repo.render_artifact(artifact=artifact, artifact_created=artifact_created, message=model)
|
|
48
48
|
artifact_result["changed"] = result.changed
|
|
49
49
|
artifact_result["checksum"] = result.checksum
|
|
50
50
|
artifact_result["artifact_id"] = result.artifact_id
|
|
51
51
|
artifact_result["storage_id"] = result.storage_id
|
|
52
52
|
check_message = "Artifact rendered successfully"
|
|
53
|
+
conclusion = ValidatorConclusion.SUCCESS
|
|
53
54
|
|
|
54
|
-
except Exception as exc:
|
|
55
|
-
conclusion = ValidatorConclusion.FAILURE.value
|
|
55
|
+
except Exception as exc:
|
|
56
56
|
artifact.status.value = "Error"
|
|
57
|
+
await artifact.save()
|
|
57
58
|
severity = "critical"
|
|
59
|
+
conclusion = ValidatorConclusion.FAILURE
|
|
58
60
|
check_message += f": {str(exc)}"
|
|
59
|
-
await artifact.save()
|
|
60
61
|
|
|
61
62
|
check = None
|
|
62
|
-
check_name = f"{
|
|
63
|
+
check_name = f"{model.artifact_name}: {model.target_name}"
|
|
63
64
|
existing_check = await service.client.filters(
|
|
64
65
|
kind=InfrahubKind.ARTIFACTCHECK, validator__ids=validator.id, name__value=check_name
|
|
65
66
|
)
|
|
@@ -68,7 +69,7 @@ async def create(message: messages.CheckArtifactCreate, service: InfrahubService
|
|
|
68
69
|
|
|
69
70
|
if check:
|
|
70
71
|
check.created_at.value = Timestamp().to_string()
|
|
71
|
-
check.conclusion.value = conclusion
|
|
72
|
+
check.conclusion.value = conclusion.value
|
|
72
73
|
check.severity.value = severity
|
|
73
74
|
check.changed.value = artifact_result["changed"]
|
|
74
75
|
check.checksum.value = artifact_result["checksum"]
|
|
@@ -80,12 +81,12 @@ async def create(message: messages.CheckArtifactCreate, service: InfrahubService
|
|
|
80
81
|
kind=InfrahubKind.ARTIFACTCHECK,
|
|
81
82
|
data={
|
|
82
83
|
"name": check_name,
|
|
83
|
-
"origin":
|
|
84
|
+
"origin": model.repository_id,
|
|
84
85
|
"kind": "ArtifactDefinition",
|
|
85
|
-
"validator":
|
|
86
|
+
"validator": model.validator_id,
|
|
86
87
|
"created_at": Timestamp().to_string(),
|
|
87
88
|
"message": check_message,
|
|
88
|
-
"conclusion": conclusion,
|
|
89
|
+
"conclusion": conclusion.value,
|
|
89
90
|
"severity": severity,
|
|
90
91
|
"changed": artifact_result["changed"],
|
|
91
92
|
"checksum": artifact_result["checksum"],
|
|
@@ -95,4 +96,4 @@ async def create(message: messages.CheckArtifactCreate, service: InfrahubService
|
|
|
95
96
|
)
|
|
96
97
|
await check.save()
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
return conclusion
|
infrahub/cli/__init__.py
CHANGED
|
@@ -12,8 +12,6 @@ from infrahub.cli.tasks import app as tasks_app
|
|
|
12
12
|
from infrahub.core.initialization import initialization
|
|
13
13
|
from infrahub.database import InfrahubDatabase, get_db
|
|
14
14
|
|
|
15
|
-
# pylint: disable=import-outside-toplevel
|
|
16
|
-
|
|
17
15
|
app = typer.Typer(name="Infrahub CLI", pretty_exceptions_enable=False)
|
|
18
16
|
|
|
19
17
|
|
infrahub/cli/db.py
CHANGED
|
@@ -44,7 +44,7 @@ from infrahub.core.validators.models.validate_migration import SchemaValidateMig
|
|
|
44
44
|
from infrahub.core.validators.tasks import schema_validate_migrations
|
|
45
45
|
from infrahub.database import DatabaseType
|
|
46
46
|
from infrahub.log import get_logger
|
|
47
|
-
from infrahub.services import InfrahubServices
|
|
47
|
+
from infrahub.services import InfrahubServices
|
|
48
48
|
from infrahub.services.adapters.message_bus.local import BusSimulator
|
|
49
49
|
from infrahub.services.adapters.workflow.local import WorkflowLocalExecution
|
|
50
50
|
|
|
@@ -193,7 +193,7 @@ async def migrate(
|
|
|
193
193
|
|
|
194
194
|
|
|
195
195
|
@app.command()
|
|
196
|
-
async def update_core_schema(
|
|
196
|
+
async def update_core_schema(
|
|
197
197
|
ctx: typer.Context,
|
|
198
198
|
debug: bool = typer.Option(False, help="Enable advanced logging and troubleshooting"),
|
|
199
199
|
config_file: str = typer.Argument("infrahub.toml", envvar="INFRAHUB_CONFIG"),
|
|
@@ -216,10 +216,9 @@ async def update_core_schema( # pylint: disable=too-many-statements
|
|
|
216
216
|
# ----------------------------------------------------------
|
|
217
217
|
# Initialize Schema and Registry
|
|
218
218
|
# ----------------------------------------------------------
|
|
219
|
-
service = InfrahubServices(
|
|
220
|
-
database=db, message_bus=BusSimulator(
|
|
219
|
+
service = await InfrahubServices.new(
|
|
220
|
+
database=db, message_bus=BusSimulator(), workflow=WorkflowLocalExecution()
|
|
221
221
|
)
|
|
222
|
-
services.prepare(service)
|
|
223
222
|
await initialize_registry(db=db)
|
|
224
223
|
|
|
225
224
|
default_branch = registry.get_branch_from_registry(branch=registry.default_branch)
|
|
@@ -269,7 +268,7 @@ async def update_core_schema( # pylint: disable=too-many-statements
|
|
|
269
268
|
schema_branch=candidate_schema,
|
|
270
269
|
constraints=result.constraints,
|
|
271
270
|
)
|
|
272
|
-
responses = await schema_validate_migrations(message=validate_migration_data)
|
|
271
|
+
responses = await schema_validate_migrations(message=validate_migration_data, service=service)
|
|
273
272
|
error_messages = [violation.message for response in responses for violation in response.violations]
|
|
274
273
|
if error_messages:
|
|
275
274
|
rprint(f"{error_badge} | Unable to update the schema, due to failed validations")
|
|
@@ -311,7 +310,7 @@ async def update_core_schema( # pylint: disable=too-many-statements
|
|
|
311
310
|
previous_schema=origin_schema,
|
|
312
311
|
migrations=result.migrations,
|
|
313
312
|
)
|
|
314
|
-
migration_error_msgs = await schema_apply_migrations(message=apply_migration_data)
|
|
313
|
+
migration_error_msgs = await schema_apply_migrations(message=apply_migration_data, service=service)
|
|
315
314
|
|
|
316
315
|
if migration_error_msgs:
|
|
317
316
|
rprint(f"{error_badge} | Some error(s) happened while running the schema migrations")
|
infrahub/cli/events.py
CHANGED
|
@@ -7,6 +7,7 @@ from infrahub_sdk.async_typer import AsyncTyper
|
|
|
7
7
|
from rich import print as rprint
|
|
8
8
|
|
|
9
9
|
from infrahub import config
|
|
10
|
+
from infrahub.components import ComponentType
|
|
10
11
|
from infrahub.services import InfrahubServices
|
|
11
12
|
from infrahub.services.adapters.message_bus.rabbitmq import RabbitMQMessageBus
|
|
12
13
|
|
|
@@ -24,9 +25,13 @@ async def listen(
|
|
|
24
25
|
) -> None:
|
|
25
26
|
"""Listen to event in the Events bus and print them."""
|
|
26
27
|
config.load_and_exit(config_file)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
|
|
29
|
+
# Below code seems to be a duplicate of `RabbitMQMessageBus._initialize_api_server`.
|
|
30
|
+
# Also, here we are using ComponentType.NONE so RabbitMQMessageBus will NOT instantiate connection.
|
|
31
|
+
# We might want to factorize here and use ComponentType.GitAgent so broker instantiates connection correctly.
|
|
32
|
+
component_type = ComponentType.NONE
|
|
33
|
+
broker = await RabbitMQMessageBus.new(component_type=component_type)
|
|
34
|
+
_ = await InfrahubServices.new(message_bus=broker, component_type=component_type)
|
|
30
35
|
|
|
31
36
|
queue = await broker.channel.declare_queue(exclusive=True)
|
|
32
37
|
exchange_name = f"{config.SETTINGS.broker.namespace}.events"
|
infrahub/cli/git_agent.py
CHANGED
|
@@ -36,7 +36,7 @@ log = get_logger()
|
|
|
36
36
|
shutdown_event = asyncio.Event()
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
def signal_handler(*args: Any, **kwargs: Any) -> None: #
|
|
39
|
+
def signal_handler(*args: Any, **kwargs: Any) -> None: # noqa: ARG001
|
|
40
40
|
shutdown_event.set()
|
|
41
41
|
|
|
42
42
|
|
|
@@ -99,7 +99,7 @@ async def start(
|
|
|
99
99
|
await client.branch.all()
|
|
100
100
|
except SdkError as exc:
|
|
101
101
|
log.error(f"Error in communication with Infrahub: {exc.message}")
|
|
102
|
-
raise typer.Exit(1)
|
|
102
|
+
raise typer.Exit(1) from None
|
|
103
103
|
|
|
104
104
|
# Initialize trace
|
|
105
105
|
if config.SETTINGS.trace.enable:
|
|
@@ -119,22 +119,24 @@ async def start(
|
|
|
119
119
|
else WorkflowLocalExecution()
|
|
120
120
|
)
|
|
121
121
|
|
|
122
|
+
component_type = ComponentType.GIT_AGENT
|
|
122
123
|
message_bus = config.OVERRIDE.message_bus or (
|
|
123
|
-
NATSMessageBus
|
|
124
|
+
await NATSMessageBus.new(component_type=component_type)
|
|
125
|
+
if config.SETTINGS.broker.driver == config.BrokerDriver.NATS
|
|
126
|
+
else await RabbitMQMessageBus.new(component_type=component_type)
|
|
124
127
|
)
|
|
125
128
|
cache = config.OVERRIDE.cache or (
|
|
126
|
-
NATSCache() if config.SETTINGS.cache.driver == config.CacheDriver.NATS else RedisCache()
|
|
129
|
+
await NATSCache.new() if config.SETTINGS.cache.driver == config.CacheDriver.NATS else RedisCache()
|
|
127
130
|
)
|
|
128
131
|
|
|
129
|
-
service = InfrahubServices(
|
|
132
|
+
service = await InfrahubServices.new(
|
|
130
133
|
cache=cache,
|
|
131
134
|
client=client,
|
|
132
135
|
database=database,
|
|
133
136
|
workflow=workflow,
|
|
134
137
|
message_bus=message_bus,
|
|
135
|
-
component_type=
|
|
138
|
+
component_type=component_type,
|
|
136
139
|
)
|
|
137
|
-
await service.initialize()
|
|
138
140
|
|
|
139
141
|
# Initialize the lock
|
|
140
142
|
initialize_lock(service=service)
|