infrahub-server 1.3.5__py3-none-any.whl → 1.4.0b0__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/internal.py +5 -0
- infrahub/artifacts/tasks.py +17 -22
- infrahub/branch/merge_mutation_checker.py +38 -0
- infrahub/cli/__init__.py +2 -2
- infrahub/cli/context.py +7 -3
- infrahub/cli/db.py +5 -16
- infrahub/cli/upgrade.py +7 -29
- infrahub/computed_attribute/tasks.py +36 -46
- infrahub/config.py +53 -2
- infrahub/constants/environment.py +1 -0
- infrahub/core/attribute.py +9 -7
- infrahub/core/branch/tasks.py +43 -41
- infrahub/core/constants/__init__.py +20 -6
- infrahub/core/constants/infrahubkind.py +2 -0
- infrahub/core/diff/coordinator.py +3 -1
- infrahub/core/diff/repository/repository.py +0 -8
- infrahub/core/diff/tasks.py +11 -8
- infrahub/core/graph/__init__.py +1 -1
- infrahub/core/graph/index.py +1 -2
- infrahub/core/graph/schema.py +50 -29
- infrahub/core/initialization.py +62 -33
- infrahub/core/ipam/tasks.py +4 -3
- infrahub/core/merge.py +8 -10
- infrahub/core/migrations/graph/__init__.py +2 -0
- infrahub/core/migrations/graph/m035_drop_attr_value_index.py +45 -0
- infrahub/core/migrations/query/attribute_add.py +27 -2
- infrahub/core/migrations/schema/tasks.py +6 -5
- infrahub/core/node/proposed_change.py +43 -0
- infrahub/core/protocols.py +12 -0
- infrahub/core/query/attribute.py +32 -14
- infrahub/core/query/diff.py +11 -0
- infrahub/core/query/ipam.py +13 -7
- infrahub/core/query/node.py +51 -10
- infrahub/core/query/resource_manager.py +3 -3
- infrahub/core/schema/basenode_schema.py +8 -0
- infrahub/core/schema/definitions/core/__init__.py +10 -1
- infrahub/core/schema/definitions/core/ipam.py +28 -2
- infrahub/core/schema/definitions/core/propose_change.py +15 -0
- infrahub/core/schema/definitions/core/webhook.py +3 -0
- infrahub/core/schema/generic_schema.py +10 -0
- infrahub/core/schema/manager.py +10 -1
- infrahub/core/schema/node_schema.py +22 -17
- infrahub/core/schema/profile_schema.py +8 -0
- infrahub/core/schema/schema_branch.py +9 -5
- infrahub/core/schema/template_schema.py +8 -0
- infrahub/core/validators/checks_runner.py +5 -5
- infrahub/core/validators/tasks.py +6 -7
- infrahub/core/validators/uniqueness/checker.py +4 -2
- infrahub/core/validators/uniqueness/model.py +1 -0
- infrahub/core/validators/uniqueness/query.py +57 -7
- infrahub/database/__init__.py +2 -1
- infrahub/events/__init__.py +18 -0
- infrahub/events/constants.py +7 -0
- infrahub/events/generator.py +29 -2
- infrahub/events/proposed_change_action.py +181 -0
- infrahub/generators/tasks.py +24 -20
- infrahub/git/base.py +4 -7
- infrahub/git/integrator.py +21 -12
- infrahub/git/repository.py +15 -30
- infrahub/git/tasks.py +121 -106
- infrahub/graphql/field_extractor.py +69 -0
- infrahub/graphql/manager.py +15 -11
- infrahub/graphql/mutations/account.py +2 -2
- infrahub/graphql/mutations/action.py +8 -2
- infrahub/graphql/mutations/artifact_definition.py +4 -1
- infrahub/graphql/mutations/branch.py +10 -5
- infrahub/graphql/mutations/graphql_query.py +2 -1
- infrahub/graphql/mutations/main.py +14 -8
- infrahub/graphql/mutations/menu.py +2 -1
- infrahub/graphql/mutations/proposed_change.py +225 -8
- infrahub/graphql/mutations/relationship.py +5 -0
- infrahub/graphql/mutations/repository.py +2 -1
- infrahub/graphql/mutations/tasks.py +7 -9
- infrahub/graphql/mutations/webhook.py +4 -1
- infrahub/graphql/parser.py +15 -6
- infrahub/graphql/queries/__init__.py +10 -1
- infrahub/graphql/queries/account.py +3 -3
- infrahub/graphql/queries/branch.py +2 -2
- infrahub/graphql/queries/diff/tree.py +3 -3
- infrahub/graphql/queries/event.py +13 -3
- infrahub/graphql/queries/ipam.py +23 -1
- infrahub/graphql/queries/proposed_change.py +84 -0
- infrahub/graphql/queries/relationship.py +2 -2
- infrahub/graphql/queries/resource_manager.py +3 -3
- infrahub/graphql/queries/search.py +3 -2
- infrahub/graphql/queries/status.py +3 -2
- infrahub/graphql/queries/task.py +2 -2
- infrahub/graphql/resolvers/ipam.py +440 -0
- infrahub/graphql/resolvers/many_relationship.py +4 -3
- infrahub/graphql/resolvers/resolver.py +5 -5
- infrahub/graphql/resolvers/single_relationship.py +3 -2
- infrahub/graphql/schema.py +25 -5
- infrahub/graphql/types/__init__.py +2 -2
- infrahub/graphql/types/attribute.py +3 -3
- infrahub/graphql/types/event.py +60 -0
- infrahub/groups/tasks.py +6 -6
- infrahub/lock.py +3 -2
- infrahub/menu/generator.py +8 -0
- infrahub/message_bus/operations/__init__.py +9 -12
- infrahub/message_bus/operations/git/file.py +6 -5
- infrahub/message_bus/operations/git/repository.py +12 -20
- infrahub/message_bus/operations/refresh/registry.py +15 -9
- infrahub/message_bus/operations/send/echo.py +7 -4
- infrahub/message_bus/types.py +1 -0
- infrahub/permissions/globals.py +1 -4
- infrahub/permissions/manager.py +8 -5
- infrahub/pools/prefix.py +7 -5
- infrahub/prefect_server/app.py +31 -0
- infrahub/prefect_server/bootstrap.py +18 -0
- infrahub/proposed_change/action_checker.py +206 -0
- infrahub/proposed_change/approval_revoker.py +40 -0
- infrahub/proposed_change/branch_diff.py +3 -1
- infrahub/proposed_change/checker.py +45 -0
- infrahub/proposed_change/constants.py +32 -2
- infrahub/proposed_change/tasks.py +182 -150
- infrahub/py.typed +0 -0
- infrahub/server.py +29 -17
- infrahub/services/__init__.py +13 -28
- infrahub/services/adapters/cache/__init__.py +4 -0
- infrahub/services/adapters/cache/nats.py +2 -0
- infrahub/services/adapters/cache/redis.py +3 -0
- infrahub/services/adapters/message_bus/__init__.py +0 -2
- infrahub/services/adapters/message_bus/local.py +1 -2
- infrahub/services/adapters/message_bus/nats.py +6 -8
- infrahub/services/adapters/message_bus/rabbitmq.py +7 -9
- infrahub/services/adapters/workflow/__init__.py +1 -0
- infrahub/services/adapters/workflow/local.py +1 -8
- infrahub/services/component.py +2 -1
- infrahub/task_manager/event.py +52 -0
- infrahub/task_manager/models.py +9 -0
- infrahub/tasks/artifact.py +6 -7
- infrahub/tasks/check.py +4 -7
- infrahub/telemetry/tasks.py +15 -18
- infrahub/transformations/tasks.py +10 -6
- infrahub/trigger/tasks.py +4 -3
- infrahub/types.py +4 -0
- infrahub/validators/events.py +7 -7
- infrahub/validators/tasks.py +6 -7
- infrahub/webhook/models.py +45 -45
- infrahub/webhook/tasks.py +25 -24
- infrahub/workers/dependencies.py +143 -0
- infrahub/workers/infrahub_async.py +19 -43
- infrahub/workflows/catalogue.py +16 -2
- infrahub/workflows/initialization.py +5 -4
- infrahub/workflows/models.py +2 -0
- infrahub_sdk/client.py +6 -6
- infrahub_sdk/ctl/repository.py +51 -0
- infrahub_sdk/ctl/schema.py +9 -9
- infrahub_sdk/protocols.py +40 -6
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/METADATA +5 -4
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/RECORD +158 -144
- infrahub_testcontainers/container.py +17 -0
- infrahub_testcontainers/docker-compose-cluster.test.yml +56 -1
- infrahub_testcontainers/docker-compose.test.yml +56 -1
- infrahub_testcontainers/helpers.py +4 -1
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/WHEEL +0 -0
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/entry_points.txt +0 -0
infrahub/api/internal.py
CHANGED
|
@@ -18,6 +18,7 @@ from infrahub.config import ( # noqa: TC001
|
|
|
18
18
|
)
|
|
19
19
|
from infrahub.core import registry
|
|
20
20
|
from infrahub.exceptions import NodeNotFoundError
|
|
21
|
+
from infrahub.workers.dependencies import get_installation_type
|
|
21
22
|
|
|
22
23
|
if TYPE_CHECKING:
|
|
23
24
|
from infrahub.auth import AccountSession
|
|
@@ -31,6 +32,8 @@ class ConfigAPI(BaseModel):
|
|
|
31
32
|
analytics: AnalyticsSettings
|
|
32
33
|
experimental_features: ExperimentalFeaturesSettings
|
|
33
34
|
sso: config.SSOInfo
|
|
35
|
+
installation_type: str
|
|
36
|
+
policy: config.PolicySettings
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
class InfoAPI(BaseModel):
|
|
@@ -46,6 +49,8 @@ async def get_config() -> ConfigAPI:
|
|
|
46
49
|
analytics=config.SETTINGS.analytics,
|
|
47
50
|
experimental_features=config.SETTINGS.experimental_features,
|
|
48
51
|
sso=config.SETTINGS.security.public_sso_config,
|
|
52
|
+
installation_type=get_installation_type(),
|
|
53
|
+
policy=config.SETTINGS.policy,
|
|
49
54
|
)
|
|
50
55
|
|
|
51
56
|
|
infrahub/artifacts/tasks.py
CHANGED
|
@@ -3,34 +3,29 @@ from prefect import flow
|
|
|
3
3
|
from infrahub.artifacts.models import CheckArtifactCreate
|
|
4
4
|
from infrahub.core.constants import InfrahubKind, ValidatorConclusion
|
|
5
5
|
from infrahub.core.timestamp import Timestamp
|
|
6
|
-
from infrahub.git import
|
|
7
|
-
from infrahub.services import InfrahubServices
|
|
6
|
+
from infrahub.git.repository import get_initialized_repo
|
|
8
7
|
from infrahub.tasks.artifact import define_artifact
|
|
8
|
+
from infrahub.workers.dependencies import get_client
|
|
9
9
|
from infrahub.workflows.utils import add_tags
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
@flow(name="git-repository-check-artifact-create", flow_run_name="Check artifact creation")
|
|
13
|
-
async def create(model: CheckArtifactCreate
|
|
13
|
+
async def create(model: CheckArtifactCreate) -> ValidatorConclusion:
|
|
14
14
|
await add_tags(branches=[model.branch_name], nodes=[model.target_id])
|
|
15
|
-
validator = await service.client.get(kind=InfrahubKind.ARTIFACTVALIDATOR, id=model.validator_id, include=["checks"])
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
name=model.repository_name,
|
|
29
|
-
client=service.client,
|
|
30
|
-
service=service,
|
|
31
|
-
)
|
|
16
|
+
client = get_client()
|
|
17
|
+
|
|
18
|
+
validator = await client.get(kind=InfrahubKind.ARTIFACTVALIDATOR, id=model.validator_id, include=["checks"])
|
|
19
|
+
|
|
20
|
+
repo = await get_initialized_repo(
|
|
21
|
+
client=client,
|
|
22
|
+
repository_id=model.repository_id,
|
|
23
|
+
name=model.repository_name,
|
|
24
|
+
repository_kind=model.repository_kind,
|
|
25
|
+
commit=model.commit,
|
|
26
|
+
)
|
|
32
27
|
|
|
33
|
-
artifact, artifact_created = await define_artifact(model=model
|
|
28
|
+
artifact, artifact_created = await define_artifact(model=model)
|
|
34
29
|
|
|
35
30
|
severity = "info"
|
|
36
31
|
artifact_result: dict[str, str | bool | None] = {
|
|
@@ -59,7 +54,7 @@ async def create(model: CheckArtifactCreate, service: InfrahubServices) -> Valid
|
|
|
59
54
|
|
|
60
55
|
check = None
|
|
61
56
|
check_name = f"{model.artifact_name}: {model.target_name}"
|
|
62
|
-
existing_check = await
|
|
57
|
+
existing_check = await client.filters(
|
|
63
58
|
kind=InfrahubKind.ARTIFACTCHECK, validator__ids=validator.id, name__value=check_name
|
|
64
59
|
)
|
|
65
60
|
if existing_check:
|
|
@@ -75,7 +70,7 @@ async def create(model: CheckArtifactCreate, service: InfrahubServices) -> Valid
|
|
|
75
70
|
check.storage_id.value = artifact_result["storage_id"]
|
|
76
71
|
await check.save()
|
|
77
72
|
else:
|
|
78
|
-
check = await
|
|
73
|
+
check = await client.create(
|
|
79
74
|
kind=InfrahubKind.ARTIFACTCHECK,
|
|
80
75
|
data={
|
|
81
76
|
"name": check_name,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
from fast_depends import Depends, inject
|
|
4
|
+
|
|
5
|
+
from infrahub.auth import AccountSession
|
|
6
|
+
from infrahub.database import InfrahubDatabase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BranchMergeMutationChecker(ABC):
|
|
10
|
+
@abstractmethod
|
|
11
|
+
async def verify_branch_merge_mutation_allowed(
|
|
12
|
+
self,
|
|
13
|
+
db: InfrahubDatabase,
|
|
14
|
+
account_session: AccountSession,
|
|
15
|
+
) -> None:
|
|
16
|
+
raise NotImplementedError()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BranchMergeMutationCheckerCommunity(BranchMergeMutationChecker):
|
|
20
|
+
async def verify_branch_merge_mutation_allowed(
|
|
21
|
+
self,
|
|
22
|
+
db: InfrahubDatabase,
|
|
23
|
+
account_session: AccountSession,
|
|
24
|
+
) -> None:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_branch_merge_mutation_checker() -> BranchMergeMutationChecker:
|
|
29
|
+
return BranchMergeMutationCheckerCommunity()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@inject
|
|
33
|
+
async def verify_branch_merge_mutation_allowed(
|
|
34
|
+
db: InfrahubDatabase,
|
|
35
|
+
account_session: AccountSession,
|
|
36
|
+
branch_merge_mutation_checker: BranchMergeMutationChecker = Depends(get_branch_merge_mutation_checker), # noqa: B008
|
|
37
|
+
) -> None:
|
|
38
|
+
await branch_merge_mutation_checker.verify_branch_merge_mutation_allowed(db=db, account_session=account_session)
|
infrahub/cli/__init__.py
CHANGED
|
@@ -5,8 +5,8 @@ from infrahub_sdk.async_typer import AsyncTyper
|
|
|
5
5
|
|
|
6
6
|
from infrahub import config
|
|
7
7
|
from infrahub.core.initialization import initialization
|
|
8
|
-
from infrahub.database import InfrahubDatabase, get_db
|
|
9
8
|
|
|
9
|
+
from ..workers.dependencies import get_database
|
|
10
10
|
from .context import CliContext
|
|
11
11
|
from .db import app as db_app
|
|
12
12
|
from .events import app as events_app
|
|
@@ -36,7 +36,7 @@ async def _init_shell(config_file: str) -> None:
|
|
|
36
36
|
"""Launch a Python Interactive shell."""
|
|
37
37
|
config.load_and_exit(config_file_name=config_file)
|
|
38
38
|
|
|
39
|
-
db =
|
|
39
|
+
db = await get_database()
|
|
40
40
|
|
|
41
41
|
async with db.start_session() as db:
|
|
42
42
|
await initialization(db=db)
|
infrahub/cli/context.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
4
5
|
|
|
5
|
-
from infrahub.
|
|
6
|
+
from infrahub.workers.dependencies import get_database
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from infrahub.database import InfrahubDatabase
|
|
6
10
|
|
|
7
11
|
|
|
8
12
|
@dataclass
|
|
@@ -11,5 +15,5 @@ class CliContext:
|
|
|
11
15
|
|
|
12
16
|
# This method is inherited for Infrahub Enterprise.
|
|
13
17
|
@staticmethod
|
|
14
|
-
async def init_db(retry: int) -> InfrahubDatabase:
|
|
15
|
-
return
|
|
18
|
+
async def init_db(retry: int) -> InfrahubDatabase: # type:ignore # noqa
|
|
19
|
+
return await get_database()
|
infrahub/cli/db.py
CHANGED
|
@@ -23,7 +23,7 @@ from infrahub import config
|
|
|
23
23
|
from infrahub.core import registry
|
|
24
24
|
from infrahub.core.graph import GRAPH_VERSION
|
|
25
25
|
from infrahub.core.graph.constraints import ConstraintManagerBase, ConstraintManagerMemgraph, ConstraintManagerNeo4j
|
|
26
|
-
from infrahub.core.graph.index import
|
|
26
|
+
from infrahub.core.graph.index import node_indexes, rel_indexes
|
|
27
27
|
from infrahub.core.graph.schema import (
|
|
28
28
|
GRAPH_SCHEMA,
|
|
29
29
|
GraphAttributeProperties,
|
|
@@ -51,9 +51,6 @@ from infrahub.database import DatabaseType
|
|
|
51
51
|
from infrahub.database.memgraph import IndexManagerMemgraph
|
|
52
52
|
from infrahub.database.neo4j import IndexManagerNeo4j
|
|
53
53
|
from infrahub.log import get_logger
|
|
54
|
-
from infrahub.services import InfrahubServices
|
|
55
|
-
from infrahub.services.adapters.message_bus.local import BusSimulator
|
|
56
|
-
from infrahub.services.adapters.workflow.local import WorkflowLocalExecution
|
|
57
54
|
|
|
58
55
|
from .constants import ERROR_BADGE, FAILED_BADGE, SUCCESS_BADGE
|
|
59
56
|
from .patch import patch_app
|
|
@@ -195,12 +192,8 @@ async def update_core_schema_cmd(
|
|
|
195
192
|
context: CliContext = ctx.obj
|
|
196
193
|
dbdriver = await context.init_db(retry=1)
|
|
197
194
|
|
|
198
|
-
service = await InfrahubServices.new(
|
|
199
|
-
database=dbdriver, message_bus=BusSimulator(), workflow=WorkflowLocalExecution()
|
|
200
|
-
)
|
|
201
|
-
|
|
202
195
|
with prefect_test_harness():
|
|
203
|
-
await update_core_schema(db=dbdriver,
|
|
196
|
+
await update_core_schema(db=dbdriver, initialize=True, debug=debug)
|
|
204
197
|
|
|
205
198
|
await dbdriver.close()
|
|
206
199
|
|
|
@@ -264,8 +257,6 @@ async def index(
|
|
|
264
257
|
index_manager: IndexManagerBase = IndexManagerMemgraph(db=dbdriver)
|
|
265
258
|
index_manager = IndexManagerNeo4j(db=dbdriver)
|
|
266
259
|
|
|
267
|
-
if config.SETTINGS.experimental_features.value_db_index:
|
|
268
|
-
node_indexes.append(attr_value_index)
|
|
269
260
|
index_manager.init(nodes=node_indexes, rels=rel_indexes)
|
|
270
261
|
|
|
271
262
|
if action == IndexAction.ADD:
|
|
@@ -368,9 +359,7 @@ async def initialize_internal_schema() -> None:
|
|
|
368
359
|
registry.schema.register_schema(schema=schema)
|
|
369
360
|
|
|
370
361
|
|
|
371
|
-
async def update_core_schema(
|
|
372
|
-
db: InfrahubDatabase, service: InfrahubServices, initialize: bool = True, debug: bool = False
|
|
373
|
-
) -> None:
|
|
362
|
+
async def update_core_schema(db: InfrahubDatabase, initialize: bool = True, debug: bool = False) -> None:
|
|
374
363
|
"""Update the core schema of Infrahub to the latest version"""
|
|
375
364
|
# ----------------------------------------------------------
|
|
376
365
|
# Initialize Schema and Registry
|
|
@@ -419,7 +408,7 @@ async def update_core_schema(
|
|
|
419
408
|
schema_branch=candidate_schema,
|
|
420
409
|
constraints=result.constraints,
|
|
421
410
|
)
|
|
422
|
-
responses = await schema_validate_migrations(message=validate_migration_data
|
|
411
|
+
responses = await schema_validate_migrations(message=validate_migration_data)
|
|
423
412
|
error_messages = [violation.message for response in responses for violation in response.violations]
|
|
424
413
|
if error_messages:
|
|
425
414
|
rprint(f"{ERROR_BADGE} | Unable to update the schema, due to failed validations")
|
|
@@ -461,7 +450,7 @@ async def update_core_schema(
|
|
|
461
450
|
previous_schema=origin_schema,
|
|
462
451
|
migrations=result.migrations,
|
|
463
452
|
)
|
|
464
|
-
migration_error_msgs = await schema_apply_migrations(message=apply_migration_data
|
|
453
|
+
migration_error_msgs = await schema_apply_migrations(message=apply_migration_data)
|
|
465
454
|
|
|
466
455
|
if migration_error_msgs:
|
|
467
456
|
rprint(f"{ERROR_BADGE} | Some error(s) happened while running the schema migrations")
|
infrahub/cli/upgrade.py
CHANGED
|
@@ -11,22 +11,13 @@ from prefect.client.orchestration import get_client
|
|
|
11
11
|
from rich import print as rprint
|
|
12
12
|
|
|
13
13
|
from infrahub import config
|
|
14
|
-
from infrahub.core.
|
|
15
|
-
from infrahub.core.initialization import (
|
|
16
|
-
create_anonymous_role,
|
|
17
|
-
create_default_roles,
|
|
18
|
-
create_super_administrator_role,
|
|
19
|
-
create_super_administrators_group,
|
|
20
|
-
initialize_registry,
|
|
21
|
-
)
|
|
14
|
+
from infrahub.core.initialization import create_anonymous_role, create_default_account_groups, initialize_registry
|
|
22
15
|
from infrahub.core.manager import NodeManager
|
|
16
|
+
from infrahub.core.protocols import CoreAccount, CoreObjectPermission
|
|
23
17
|
from infrahub.menu.menu import default_menu
|
|
24
18
|
from infrahub.menu.models import MenuDict
|
|
25
19
|
from infrahub.menu.repository import MenuRepository
|
|
26
20
|
from infrahub.menu.utils import create_default_menu
|
|
27
|
-
from infrahub.services import InfrahubServices
|
|
28
|
-
from infrahub.services.adapters.message_bus.local import BusSimulator
|
|
29
|
-
from infrahub.services.adapters.workflow.local import WorkflowLocalExecution
|
|
30
21
|
from infrahub.trigger.tasks import trigger_configure_all
|
|
31
22
|
from infrahub.workflows.initialization import (
|
|
32
23
|
setup_blocks,
|
|
@@ -61,9 +52,6 @@ async def upgrade_cmd(
|
|
|
61
52
|
context: CliContext = ctx.obj
|
|
62
53
|
dbdriver = await context.init_db(retry=1)
|
|
63
54
|
|
|
64
|
-
service = await InfrahubServices.new(
|
|
65
|
-
database=dbdriver, message_bus=BusSimulator(), workflow=WorkflowLocalExecution()
|
|
66
|
-
)
|
|
67
55
|
await initialize_registry(db=dbdriver)
|
|
68
56
|
|
|
69
57
|
# NOTE add step to validate if the database and the task manager are reachable
|
|
@@ -83,7 +71,7 @@ async def upgrade_cmd(
|
|
|
83
71
|
return
|
|
84
72
|
|
|
85
73
|
await initialize_internal_schema()
|
|
86
|
-
await update_core_schema(db=dbdriver,
|
|
74
|
+
await update_core_schema(db=dbdriver, initialize=False)
|
|
87
75
|
|
|
88
76
|
# -------------------------------------------
|
|
89
77
|
# Upgrade Internal Objects, generated and managed by Infrahub
|
|
@@ -98,7 +86,7 @@ async def upgrade_cmd(
|
|
|
98
86
|
await setup_blocks()
|
|
99
87
|
await setup_worker_pools(client=client)
|
|
100
88
|
await setup_deployments(client=client)
|
|
101
|
-
await trigger_configure_all(
|
|
89
|
+
await trigger_configure_all()
|
|
102
90
|
|
|
103
91
|
await dbdriver.close()
|
|
104
92
|
|
|
@@ -124,11 +112,7 @@ async def upgrade_menu(db: InfrahubDatabase) -> None:
|
|
|
124
112
|
|
|
125
113
|
|
|
126
114
|
async def upgrade_permissions(db: InfrahubDatabase) -> None:
|
|
127
|
-
existing_permissions = await NodeManager.query(
|
|
128
|
-
schema=InfrahubKind.OBJECTPERMISSION,
|
|
129
|
-
db=db,
|
|
130
|
-
limit=1,
|
|
131
|
-
)
|
|
115
|
+
existing_permissions = await NodeManager.query(schema=CoreObjectPermission, db=db, limit=1)
|
|
132
116
|
if existing_permissions:
|
|
133
117
|
rprint("Permissions Up to date, nothing to update")
|
|
134
118
|
return
|
|
@@ -138,14 +122,8 @@ async def upgrade_permissions(db: InfrahubDatabase) -> None:
|
|
|
138
122
|
|
|
139
123
|
|
|
140
124
|
async def setup_permissions(db: InfrahubDatabase) -> None:
|
|
141
|
-
existing_accounts = await NodeManager.query(
|
|
142
|
-
|
|
143
|
-
db=db,
|
|
144
|
-
limit=1,
|
|
145
|
-
)
|
|
146
|
-
administrator_role = await create_super_administrator_role(db=db)
|
|
147
|
-
await create_super_administrators_group(db=db, role=administrator_role, admin_accounts=existing_accounts)
|
|
148
|
-
await create_default_roles(db=db)
|
|
125
|
+
existing_accounts = await NodeManager.query(schema=CoreAccount, db=db, limit=1)
|
|
126
|
+
await create_default_account_groups(db=db, admin_accounts=existing_accounts)
|
|
149
127
|
|
|
150
128
|
if config.SETTINGS.main.allow_anonymous_access:
|
|
151
129
|
await create_anonymous_role(db=db)
|
|
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING
|
|
|
5
5
|
from infrahub_sdk.protocols import CoreTransformPython
|
|
6
6
|
from infrahub_sdk.template import Jinja2Template
|
|
7
7
|
from prefect import flow
|
|
8
|
-
from prefect.client.orchestration import get_client
|
|
8
|
+
from prefect.client.orchestration import get_client as get_prefect_client
|
|
9
9
|
from prefect.logging import get_run_logger
|
|
10
10
|
|
|
11
11
|
from infrahub.context import InfrahubContext # noqa: TC001 needed for prefect flow
|
|
@@ -13,9 +13,9 @@ from infrahub.core.constants import ComputedAttributeKind, InfrahubKind
|
|
|
13
13
|
from infrahub.core.registry import registry
|
|
14
14
|
from infrahub.events import BranchDeletedEvent
|
|
15
15
|
from infrahub.git.repository import get_initialized_repo
|
|
16
|
-
from infrahub.services import InfrahubServices # noqa: TC001 needed for prefect flow
|
|
17
16
|
from infrahub.trigger.models import TriggerSetupReport, TriggerType
|
|
18
17
|
from infrahub.trigger.setup import setup_triggers, setup_triggers_specific
|
|
18
|
+
from infrahub.workers.dependencies import get_client, get_component, get_database, get_workflow
|
|
19
19
|
from infrahub.workflows.catalogue import (
|
|
20
20
|
COMPUTED_ATTRIBUTE_PROCESS_JINJA2,
|
|
21
21
|
COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
|
|
@@ -61,10 +61,10 @@ async def process_transform(
|
|
|
61
61
|
computed_attribute_name: str, # noqa: ARG001
|
|
62
62
|
computed_attribute_kind: str, # noqa: ARG001
|
|
63
63
|
context: InfrahubContext, # noqa: ARG001
|
|
64
|
-
service: InfrahubServices,
|
|
65
64
|
updated_fields: list[str] | None = None, # noqa: ARG001
|
|
66
65
|
) -> None:
|
|
67
66
|
await add_tags(branches=[branch_name], nodes=[object_id])
|
|
67
|
+
client = get_client()
|
|
68
68
|
|
|
69
69
|
schema_branch = registry.schema.get_schema_branch(name=branch_name)
|
|
70
70
|
node_schema = schema_branch.get_node(name=node_kind, duplicate=False)
|
|
@@ -77,7 +77,7 @@ async def process_transform(
|
|
|
77
77
|
return
|
|
78
78
|
|
|
79
79
|
for attribute_name, transform_attribute in transform_attributes.items():
|
|
80
|
-
transform = await
|
|
80
|
+
transform = await client.get(
|
|
81
81
|
kind=CoreTransformPython,
|
|
82
82
|
branch=branch_name,
|
|
83
83
|
id=transform_attribute.transform,
|
|
@@ -88,7 +88,7 @@ async def process_transform(
|
|
|
88
88
|
if not transform:
|
|
89
89
|
continue
|
|
90
90
|
|
|
91
|
-
repo_node = await
|
|
91
|
+
repo_node = await client.get(
|
|
92
92
|
kind=str(transform.repository.peer.typename),
|
|
93
93
|
branch=branch_name,
|
|
94
94
|
id=transform.repository.peer.id,
|
|
@@ -96,14 +96,14 @@ async def process_transform(
|
|
|
96
96
|
)
|
|
97
97
|
|
|
98
98
|
repo = await get_initialized_repo(
|
|
99
|
+
client=client,
|
|
99
100
|
repository_id=transform.repository.peer.id,
|
|
100
101
|
name=transform.repository.peer.name.value,
|
|
101
|
-
service=service,
|
|
102
102
|
repository_kind=str(transform.repository.peer.typename),
|
|
103
103
|
commit=repo_node.commit.value,
|
|
104
104
|
) # type: ignore[misc]
|
|
105
105
|
|
|
106
|
-
data = await
|
|
106
|
+
data = await client.query_gql_query(
|
|
107
107
|
name=transform.query.peer.name.value,
|
|
108
108
|
branch_name=branch_name,
|
|
109
109
|
variables={"id": object_id},
|
|
@@ -112,22 +112,17 @@ async def process_transform(
|
|
|
112
112
|
)
|
|
113
113
|
|
|
114
114
|
transformed_data = await repo.execute_python_transform.with_options(timeout_seconds=transform.timeout.value)(
|
|
115
|
+
client=client,
|
|
115
116
|
branch_name=branch_name,
|
|
116
117
|
commit=repo_node.commit.value,
|
|
117
118
|
location=f"{transform.file_path.value}::{transform.class_name.value}",
|
|
118
119
|
data=data,
|
|
119
|
-
client=service.client,
|
|
120
120
|
convert_query_response=transform.convert_query_response.value,
|
|
121
121
|
) # type: ignore[misc]
|
|
122
122
|
|
|
123
|
-
await
|
|
123
|
+
await client.execute_graphql(
|
|
124
124
|
query=UPDATE_ATTRIBUTE,
|
|
125
|
-
variables={
|
|
126
|
-
"id": object_id,
|
|
127
|
-
"kind": node_kind,
|
|
128
|
-
"attribute": attribute_name,
|
|
129
|
-
"value": transformed_data,
|
|
130
|
-
},
|
|
125
|
+
variables={"id": object_id, "kind": node_kind, "attribute": attribute_name, "value": transformed_data},
|
|
131
126
|
branch_name=branch_name,
|
|
132
127
|
)
|
|
133
128
|
|
|
@@ -141,14 +136,13 @@ async def trigger_update_python_computed_attributes(
|
|
|
141
136
|
computed_attribute_name: str,
|
|
142
137
|
computed_attribute_kind: str,
|
|
143
138
|
context: InfrahubContext,
|
|
144
|
-
service: InfrahubServices,
|
|
145
139
|
) -> None:
|
|
146
140
|
await add_tags(branches=[branch_name])
|
|
147
141
|
|
|
148
|
-
nodes = await
|
|
142
|
+
nodes = await get_client().all(kind=computed_attribute_kind, branch=branch_name)
|
|
149
143
|
|
|
150
144
|
for node in nodes:
|
|
151
|
-
await
|
|
145
|
+
await get_workflow().submit_workflow(
|
|
152
146
|
workflow=COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
|
|
153
147
|
context=context,
|
|
154
148
|
parameters={
|
|
@@ -172,9 +166,9 @@ async def computed_attribute_jinja2_update_value(
|
|
|
172
166
|
node_kind: str,
|
|
173
167
|
attribute_name: str,
|
|
174
168
|
template: Jinja2Template,
|
|
175
|
-
service: InfrahubServices,
|
|
176
169
|
) -> None:
|
|
177
170
|
log = get_run_logger()
|
|
171
|
+
client = get_client()
|
|
178
172
|
|
|
179
173
|
await add_tags(branches=[branch_name], nodes=[obj.node_id], db_change=True)
|
|
180
174
|
|
|
@@ -183,14 +177,9 @@ async def computed_attribute_jinja2_update_value(
|
|
|
183
177
|
log.debug(f"Ignoring to update {obj} with existing value on {attribute_name}={value}")
|
|
184
178
|
return
|
|
185
179
|
|
|
186
|
-
await
|
|
180
|
+
await client.execute_graphql(
|
|
187
181
|
query=UPDATE_ATTRIBUTE,
|
|
188
|
-
variables={
|
|
189
|
-
"id": obj.node_id,
|
|
190
|
-
"kind": node_kind,
|
|
191
|
-
"attribute": attribute_name,
|
|
192
|
-
"value": value,
|
|
193
|
-
},
|
|
182
|
+
variables={"id": obj.node_id, "kind": node_kind, "attribute": attribute_name, "value": value},
|
|
194
183
|
branch_name=branch_name,
|
|
195
184
|
)
|
|
196
185
|
log.info(f"Updating computed attribute {node_kind}.{attribute_name}='{value}' ({obj.node_id})")
|
|
@@ -207,10 +196,10 @@ async def process_jinja2(
|
|
|
207
196
|
computed_attribute_name: str,
|
|
208
197
|
computed_attribute_kind: str,
|
|
209
198
|
context: InfrahubContext, # noqa: ARG001
|
|
210
|
-
service: InfrahubServices,
|
|
211
199
|
updated_fields: list[str] | None = None,
|
|
212
200
|
) -> None:
|
|
213
201
|
log = get_run_logger()
|
|
202
|
+
client = get_client()
|
|
214
203
|
|
|
215
204
|
await add_tags(branches=[branch_name])
|
|
216
205
|
updates: list[str] = updated_fields or []
|
|
@@ -240,14 +229,14 @@ async def process_jinja2(
|
|
|
240
229
|
|
|
241
230
|
for id_filter in computed_macro.node_filters:
|
|
242
231
|
query = attribute_graphql.render_graphql_query(query_filter=id_filter, filter_id=object_id)
|
|
243
|
-
response = await
|
|
232
|
+
response = await client.execute_graphql(query=query, branch_name=branch_name)
|
|
244
233
|
output = attribute_graphql.parse_response(response=response)
|
|
245
234
|
found.extend(output)
|
|
246
235
|
|
|
247
236
|
if not found:
|
|
248
237
|
log.debug("No nodes found that requires updates")
|
|
249
238
|
|
|
250
|
-
batch = await
|
|
239
|
+
batch = await client.create_batch()
|
|
251
240
|
for node in found:
|
|
252
241
|
batch.add(
|
|
253
242
|
task=computed_attribute_jinja2_update_value,
|
|
@@ -256,7 +245,6 @@ async def process_jinja2(
|
|
|
256
245
|
node_kind=node_schema.kind,
|
|
257
246
|
attribute_name=computed_macro.attribute.name,
|
|
258
247
|
template=jinja_template,
|
|
259
|
-
service=service,
|
|
260
248
|
)
|
|
261
249
|
|
|
262
250
|
_ = [response async for _, response in batch.execute()]
|
|
@@ -271,15 +259,16 @@ async def trigger_update_jinja2_computed_attributes(
|
|
|
271
259
|
computed_attribute_name: str,
|
|
272
260
|
computed_attribute_kind: str,
|
|
273
261
|
context: InfrahubContext,
|
|
274
|
-
service: InfrahubServices,
|
|
275
262
|
) -> None:
|
|
276
263
|
await add_tags(branches=[branch_name])
|
|
277
264
|
|
|
265
|
+
client = get_client()
|
|
266
|
+
|
|
278
267
|
# NOTE we only need the id of the nodes, we need to ooptimize the query here
|
|
279
|
-
nodes = await
|
|
268
|
+
nodes = await client.all(kind=computed_attribute_kind, branch=branch_name)
|
|
280
269
|
|
|
281
270
|
for node in nodes:
|
|
282
|
-
await
|
|
271
|
+
await get_workflow().submit_workflow(
|
|
283
272
|
workflow=COMPUTED_ATTRIBUTE_PROCESS_JINJA2,
|
|
284
273
|
context=context,
|
|
285
274
|
parameters={
|
|
@@ -295,14 +284,16 @@ async def trigger_update_jinja2_computed_attributes(
|
|
|
295
284
|
|
|
296
285
|
@flow(name="computed-attribute-setup-jinja2", flow_run_name="Setup computed attributes in task-manager")
|
|
297
286
|
async def computed_attribute_setup_jinja2(
|
|
298
|
-
|
|
287
|
+
context: InfrahubContext, branch_name: str | None = None, event_name: str | None = None
|
|
299
288
|
) -> None:
|
|
300
|
-
|
|
289
|
+
database = await get_database()
|
|
290
|
+
async with database.start_session() as db:
|
|
301
291
|
log = get_run_logger()
|
|
302
292
|
|
|
303
293
|
if branch_name:
|
|
304
294
|
await add_tags(branches=[branch_name])
|
|
305
|
-
|
|
295
|
+
component = await get_component()
|
|
296
|
+
await wait_for_schema_to_converge(branch_name=branch_name, component=component, db=db, log=log)
|
|
306
297
|
|
|
307
298
|
report: TriggerSetupReport = await setup_triggers_specific(
|
|
308
299
|
gatherer=gather_trigger_computed_attribute_jinja2, trigger_type=TriggerType.COMPUTED_ATTR_JINJA2
|
|
@@ -317,7 +308,7 @@ async def computed_attribute_setup_jinja2(
|
|
|
317
308
|
}
|
|
318
309
|
for branch, kind, attribute_name in unique_nodes:
|
|
319
310
|
if event_name != BranchDeletedEvent.event_name and branch == branch_name:
|
|
320
|
-
await
|
|
311
|
+
await get_workflow().submit_workflow(
|
|
321
312
|
workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES,
|
|
322
313
|
context=context,
|
|
323
314
|
parameters={
|
|
@@ -335,20 +326,20 @@ async def computed_attribute_setup_jinja2(
|
|
|
335
326
|
flow_run_name="Setup computed attributes for Python transforms in task-manager",
|
|
336
327
|
)
|
|
337
328
|
async def computed_attribute_setup_python(
|
|
338
|
-
service: InfrahubServices,
|
|
339
329
|
context: InfrahubContext,
|
|
340
330
|
branch_name: str | None = None,
|
|
341
331
|
event_name: str | None = None,
|
|
342
332
|
commit: str | None = None, # noqa: ARG001
|
|
343
333
|
) -> None:
|
|
344
|
-
|
|
334
|
+
database = await get_database()
|
|
335
|
+
async with database.start_session() as db:
|
|
345
336
|
log = get_run_logger()
|
|
346
337
|
|
|
347
338
|
branch_name = branch_name or registry.default_branch
|
|
348
|
-
|
|
349
339
|
if branch_name:
|
|
350
340
|
await add_tags(branches=[branch_name])
|
|
351
|
-
|
|
341
|
+
component = await get_component()
|
|
342
|
+
await wait_for_schema_to_converge(branch_name=branch_name, component=component, db=db, log=log)
|
|
352
343
|
|
|
353
344
|
triggers_python, triggers_python_query = await gather_trigger_computed_attribute_python(db=db)
|
|
354
345
|
|
|
@@ -368,7 +359,7 @@ async def computed_attribute_setup_python(
|
|
|
368
359
|
for branch, kind, attribute_name in unique_nodes:
|
|
369
360
|
if event_name != BranchDeletedEvent.event_name and branch == branch_name:
|
|
370
361
|
log.info(f"Triggering update for {kind}.{attribute_name} on {branch}")
|
|
371
|
-
await
|
|
362
|
+
await get_workflow().submit_workflow(
|
|
372
363
|
workflow=TRIGGER_UPDATE_PYTHON_COMPUTED_ATTRIBUTES,
|
|
373
364
|
context=context,
|
|
374
365
|
parameters={
|
|
@@ -378,7 +369,7 @@ async def computed_attribute_setup_python(
|
|
|
378
369
|
},
|
|
379
370
|
)
|
|
380
371
|
|
|
381
|
-
async with
|
|
372
|
+
async with get_prefect_client(sync_client=False) as prefect_client:
|
|
382
373
|
await setup_triggers(
|
|
383
374
|
client=prefect_client,
|
|
384
375
|
triggers=triggers_python,
|
|
@@ -405,11 +396,10 @@ async def query_transform_targets(
|
|
|
405
396
|
node_kind: str, # noqa: ARG001
|
|
406
397
|
object_id: str,
|
|
407
398
|
context: InfrahubContext,
|
|
408
|
-
service: InfrahubServices,
|
|
409
399
|
) -> None:
|
|
410
400
|
await add_tags(branches=[branch_name])
|
|
411
401
|
schema_branch = registry.schema.get_schema_branch(name=branch_name)
|
|
412
|
-
targets = await
|
|
402
|
+
targets = await get_client().execute_graphql(
|
|
413
403
|
query=GATHER_GRAPHQL_QUERY_SUBSCRIBERS, variables={"members": [object_id]}, branch_name=branch_name
|
|
414
404
|
)
|
|
415
405
|
|
|
@@ -425,7 +415,7 @@ async def query_transform_targets(
|
|
|
425
415
|
for subscriber in subscribers:
|
|
426
416
|
if subscriber.kind in nodes_with_computed_attributes:
|
|
427
417
|
for computed_attribute in nodes_with_computed_attributes[subscriber.kind]:
|
|
428
|
-
await
|
|
418
|
+
await get_workflow().submit_workflow(
|
|
429
419
|
workflow=COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM,
|
|
430
420
|
context=context,
|
|
431
421
|
parameters={
|