infrahub-server 1.5.0b1__py3-none-any.whl → 1.5.0b2__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 +2 -0
- infrahub/api/oauth2.py +13 -19
- infrahub/api/oidc.py +15 -21
- infrahub/api/schema.py +24 -3
- infrahub/artifacts/models.py +2 -1
- infrahub/auth.py +137 -3
- infrahub/cli/__init__.py +2 -0
- infrahub/cli/db.py +83 -102
- infrahub/cli/dev.py +118 -0
- infrahub/cli/tasks.py +46 -0
- infrahub/cli/upgrade.py +30 -3
- infrahub/computed_attribute/tasks.py +20 -8
- infrahub/core/attribute.py +10 -2
- infrahub/core/branch/enums.py +1 -1
- infrahub/core/branch/models.py +7 -3
- infrahub/core/branch/tasks.py +68 -7
- infrahub/core/constants/__init__.py +3 -0
- infrahub/core/diff/query/artifact.py +1 -0
- infrahub/core/diff/query/field_summary.py +1 -0
- infrahub/core/graph/__init__.py +1 -1
- infrahub/core/initialization.py +5 -2
- infrahub/core/migrations/__init__.py +3 -0
- infrahub/core/migrations/exceptions.py +4 -0
- infrahub/core/migrations/graph/__init__.py +10 -13
- infrahub/core/migrations/graph/load_schema_branch.py +21 -0
- infrahub/core/migrations/graph/m013_convert_git_password_credential.py +1 -1
- infrahub/core/migrations/graph/m040_duplicated_attributes.py +81 -0
- infrahub/core/migrations/graph/m041_profile_attrs_in_db.py +145 -0
- infrahub/core/migrations/graph/m042_create_hfid_display_label_in_db.py +164 -0
- infrahub/core/migrations/graph/m043_backfill_hfid_display_label_in_db.py +866 -0
- infrahub/core/migrations/query/__init__.py +7 -8
- infrahub/core/migrations/query/attribute_add.py +8 -6
- infrahub/core/migrations/query/attribute_remove.py +134 -0
- infrahub/core/migrations/runner.py +54 -0
- infrahub/core/migrations/schema/attribute_kind_update.py +9 -3
- infrahub/core/migrations/schema/attribute_supports_profile.py +90 -0
- infrahub/core/migrations/schema/node_attribute_add.py +30 -2
- infrahub/core/migrations/schema/node_attribute_remove.py +13 -109
- infrahub/core/migrations/schema/node_kind_update.py +2 -1
- infrahub/core/migrations/schema/node_remove.py +2 -1
- infrahub/core/migrations/schema/placeholder_dummy.py +3 -2
- infrahub/core/migrations/shared.py +48 -14
- infrahub/core/node/__init__.py +16 -11
- infrahub/core/node/create.py +46 -63
- infrahub/core/node/lock_utils.py +70 -44
- infrahub/core/node/resource_manager/ip_address_pool.py +2 -1
- infrahub/core/node/resource_manager/ip_prefix_pool.py +2 -1
- infrahub/core/node/resource_manager/number_pool.py +2 -1
- infrahub/core/query/attribute.py +55 -0
- infrahub/core/query/ipam.py +1 -0
- infrahub/core/query/node.py +9 -3
- infrahub/core/query/relationship.py +1 -0
- infrahub/core/schema/__init__.py +56 -0
- infrahub/core/schema/attribute_schema.py +4 -0
- infrahub/core/schema/definitions/internal.py +2 -2
- infrahub/core/schema/generated/attribute_schema.py +2 -2
- infrahub/core/schema/manager.py +22 -1
- infrahub/core/schema/schema_branch.py +180 -22
- infrahub/database/graph.py +21 -0
- infrahub/display_labels/tasks.py +13 -7
- infrahub/events/branch_action.py +27 -1
- infrahub/generators/tasks.py +3 -7
- infrahub/git/base.py +4 -1
- infrahub/git/integrator.py +1 -1
- infrahub/git/models.py +2 -1
- infrahub/git/repository.py +22 -5
- infrahub/git/tasks.py +66 -10
- infrahub/git/utils.py +123 -1
- infrahub/graphql/api/endpoints.py +14 -4
- infrahub/graphql/manager.py +4 -9
- infrahub/graphql/mutations/convert_object_type.py +11 -1
- infrahub/graphql/mutations/display_label.py +17 -10
- infrahub/graphql/mutations/hfid.py +17 -10
- infrahub/graphql/mutations/ipam.py +54 -35
- infrahub/graphql/mutations/main.py +27 -28
- infrahub/graphql/schema_sort.py +170 -0
- infrahub/graphql/types/branch.py +4 -1
- infrahub/graphql/types/enums.py +3 -0
- infrahub/hfid/tasks.py +13 -7
- infrahub/lock.py +52 -12
- infrahub/message_bus/types.py +2 -1
- infrahub/permissions/constants.py +2 -0
- infrahub/proposed_change/tasks.py +25 -16
- infrahub/server.py +6 -2
- infrahub/services/__init__.py +2 -2
- infrahub/services/adapters/http/__init__.py +5 -0
- infrahub/services/adapters/workflow/worker.py +14 -3
- infrahub/task_manager/event.py +5 -0
- infrahub/task_manager/models.py +7 -0
- infrahub/task_manager/task.py +73 -0
- infrahub/trigger/setup.py +13 -4
- infrahub/trigger/tasks.py +3 -0
- infrahub/workers/dependencies.py +10 -1
- infrahub/workers/infrahub_async.py +10 -2
- infrahub/workflows/catalogue.py +8 -0
- infrahub/workflows/initialization.py +5 -0
- infrahub/workflows/utils.py +2 -1
- infrahub_sdk/client.py +13 -10
- infrahub_sdk/config.py +29 -2
- infrahub_sdk/ctl/schema.py +22 -7
- infrahub_sdk/schema/__init__.py +32 -4
- infrahub_sdk/spec/models.py +7 -0
- infrahub_sdk/spec/object.py +37 -102
- infrahub_sdk/spec/processors/__init__.py +0 -0
- infrahub_sdk/spec/processors/data_processor.py +10 -0
- infrahub_sdk/spec/processors/factory.py +34 -0
- infrahub_sdk/spec/processors/range_expand_processor.py +56 -0
- {infrahub_server-1.5.0b1.dist-info → infrahub_server-1.5.0b2.dist-info}/METADATA +3 -1
- {infrahub_server-1.5.0b1.dist-info → infrahub_server-1.5.0b2.dist-info}/RECORD +115 -101
- infrahub_testcontainers/container.py +114 -2
- infrahub_testcontainers/docker-compose-cluster.test.yml +5 -0
- infrahub_testcontainers/docker-compose.test.yml +5 -0
- infrahub/core/migrations/graph/m040_profile_attrs_in_db.py +0 -166
- infrahub/core/migrations/graph/m041_create_hfid_display_label_in_db.py +0 -97
- infrahub/core/migrations/graph/m042_backfill_hfid_display_label_in_db.py +0 -86
- {infrahub_server-1.5.0b1.dist-info → infrahub_server-1.5.0b2.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.5.0b1.dist-info → infrahub_server-1.5.0b2.dist-info}/WHEEL +0 -0
- {infrahub_server-1.5.0b1.dist-info → infrahub_server-1.5.0b2.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
|
+
|
|
5
|
+
from rich.progress import Progress
|
|
6
|
+
|
|
7
|
+
from infrahub.core import registry
|
|
8
|
+
from infrahub.core.branch import Branch
|
|
9
|
+
from infrahub.core.constants import SchemaPathType
|
|
10
|
+
from infrahub.core.initialization import get_root_node
|
|
11
|
+
from infrahub.core.migrations.schema.node_attribute_add import NodeAttributeAddMigration
|
|
12
|
+
from infrahub.core.migrations.shared import MigrationRequiringRebase, MigrationResult
|
|
13
|
+
from infrahub.core.path import SchemaPath
|
|
14
|
+
from infrahub.core.query import Query, QueryType
|
|
15
|
+
|
|
16
|
+
from .load_schema_branch import get_or_load_schema_branch
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from infrahub.database import InfrahubDatabase
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class GetAddedNodesByKindForBranchQuery(Query):
|
|
23
|
+
name = "get_added_nodes_by_kind_for_branch_query"
|
|
24
|
+
type = QueryType.READ
|
|
25
|
+
insert_return = True
|
|
26
|
+
|
|
27
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
|
|
28
|
+
self.params["branch"] = self.branch.name
|
|
29
|
+
query = """
|
|
30
|
+
MATCH (n:Node)-[e:IS_PART_OF {branch: $branch, status: "active"}]->(:Root)
|
|
31
|
+
WHERE e.to IS NULL
|
|
32
|
+
AND NOT exists((n)-[:IS_PART_OF {branch: $branch, status: "deleted"}]->(:Root))
|
|
33
|
+
WITH n.kind AS kind, collect(n.uuid) AS node_ids
|
|
34
|
+
"""
|
|
35
|
+
self.return_labels = ["kind", "node_ids"]
|
|
36
|
+
self.add_to_query(query)
|
|
37
|
+
|
|
38
|
+
def get_node_ids_by_kind(self) -> dict[str, list[str]]:
|
|
39
|
+
node_ids_by_kind: dict[str, list[str]] = {}
|
|
40
|
+
for result in self.get_results():
|
|
41
|
+
kind = result.get_as_type(label="kind", return_type=str)
|
|
42
|
+
node_ids: list[str] = result.get_as_type(label="node_ids", return_type=list)
|
|
43
|
+
node_ids_by_kind[kind] = node_ids
|
|
44
|
+
return node_ids_by_kind
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Migration042(MigrationRequiringRebase):
|
|
48
|
+
name: str = "042_create_hfid_display_label_in_db"
|
|
49
|
+
minimum_version: int = 41
|
|
50
|
+
|
|
51
|
+
async def execute(self, db: InfrahubDatabase) -> MigrationResult:
|
|
52
|
+
result = MigrationResult()
|
|
53
|
+
|
|
54
|
+
root_node = await get_root_node(db=db, initialize=False)
|
|
55
|
+
default_branch_name = root_node.default_branch
|
|
56
|
+
default_branch = await Branch.get_by_name(db=db, name=default_branch_name)
|
|
57
|
+
main_schema_branch = await get_or_load_schema_branch(db=db, branch=default_branch)
|
|
58
|
+
schema_node = main_schema_branch.get_node(name="SchemaNode")
|
|
59
|
+
schema_generic = main_schema_branch.get_node(name="SchemaGeneric")
|
|
60
|
+
|
|
61
|
+
migrations = [
|
|
62
|
+
# HFID is not needed, it was introduced at graph v8
|
|
63
|
+
NodeAttributeAddMigration(
|
|
64
|
+
new_node_schema=schema_node,
|
|
65
|
+
previous_node_schema=schema_node,
|
|
66
|
+
schema_path=SchemaPath(
|
|
67
|
+
schema_kind="SchemaNode", path_type=SchemaPathType.ATTRIBUTE, field_name="display_label"
|
|
68
|
+
),
|
|
69
|
+
),
|
|
70
|
+
NodeAttributeAddMigration(
|
|
71
|
+
new_node_schema=schema_generic,
|
|
72
|
+
previous_node_schema=schema_generic,
|
|
73
|
+
schema_path=SchemaPath(
|
|
74
|
+
schema_kind="SchemaGeneric", path_type=SchemaPathType.ATTRIBUTE, field_name="display_label"
|
|
75
|
+
),
|
|
76
|
+
),
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
for node_schema_kind in main_schema_branch.node_names:
|
|
80
|
+
schema = main_schema_branch.get(name=node_schema_kind, duplicate=False)
|
|
81
|
+
migrations.extend(
|
|
82
|
+
[
|
|
83
|
+
NodeAttributeAddMigration(
|
|
84
|
+
new_node_schema=schema,
|
|
85
|
+
previous_node_schema=schema,
|
|
86
|
+
schema_path=SchemaPath(
|
|
87
|
+
schema_kind=schema.kind, path_type=SchemaPathType.ATTRIBUTE, field_name="human_friendly_id"
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
NodeAttributeAddMigration(
|
|
91
|
+
new_node_schema=schema,
|
|
92
|
+
previous_node_schema=schema,
|
|
93
|
+
schema_path=SchemaPath(
|
|
94
|
+
schema_kind=schema.kind, path_type=SchemaPathType.ATTRIBUTE, field_name="display_label"
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
]
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
with Progress() as progress:
|
|
101
|
+
update_task = progress.add_task("Adding HFID and display label to nodes", total=len(migrations))
|
|
102
|
+
|
|
103
|
+
for migration in migrations:
|
|
104
|
+
try:
|
|
105
|
+
execution_result = await migration.execute(db=db, branch=default_branch)
|
|
106
|
+
result.errors.extend(execution_result.errors)
|
|
107
|
+
progress.update(update_task, advance=1)
|
|
108
|
+
except Exception as exc:
|
|
109
|
+
result.errors.append(str(exc))
|
|
110
|
+
return result
|
|
111
|
+
|
|
112
|
+
return result
|
|
113
|
+
|
|
114
|
+
async def execute_against_branch(self, db: InfrahubDatabase, branch: Branch) -> MigrationResult:
|
|
115
|
+
result = MigrationResult()
|
|
116
|
+
|
|
117
|
+
schema_branch = await registry.schema.load_schema_from_db(db=db, branch=branch)
|
|
118
|
+
|
|
119
|
+
migrations = []
|
|
120
|
+
get_added_nodes_by_kind_for_branch_query = await GetAddedNodesByKindForBranchQuery.init(db=db, branch=branch)
|
|
121
|
+
await get_added_nodes_by_kind_for_branch_query.execute(db=db)
|
|
122
|
+
node_ids_by_kind = get_added_nodes_by_kind_for_branch_query.get_node_ids_by_kind()
|
|
123
|
+
|
|
124
|
+
for node_kind, node_ids in node_ids_by_kind.items():
|
|
125
|
+
schema = schema_branch.get(name=node_kind, duplicate=False)
|
|
126
|
+
migrations.extend(
|
|
127
|
+
[
|
|
128
|
+
NodeAttributeAddMigration(
|
|
129
|
+
uuids=node_ids,
|
|
130
|
+
new_node_schema=schema,
|
|
131
|
+
previous_node_schema=schema,
|
|
132
|
+
schema_path=SchemaPath(
|
|
133
|
+
schema_kind=schema.kind, path_type=SchemaPathType.ATTRIBUTE, field_name="human_friendly_id"
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
NodeAttributeAddMigration(
|
|
137
|
+
uuids=node_ids,
|
|
138
|
+
new_node_schema=schema,
|
|
139
|
+
previous_node_schema=schema,
|
|
140
|
+
schema_path=SchemaPath(
|
|
141
|
+
schema_kind=schema.kind, path_type=SchemaPathType.ATTRIBUTE, field_name="display_label"
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
]
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
with Progress() as progress:
|
|
148
|
+
update_task = progress.add_task(
|
|
149
|
+
f"Adding HFID and display label to nodes on branch {branch.name}", total=len(migrations)
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
for migration in migrations:
|
|
153
|
+
try:
|
|
154
|
+
execution_result = await migration.execute(db=db, branch=branch)
|
|
155
|
+
result.errors.extend(execution_result.errors)
|
|
156
|
+
progress.update(update_task, advance=1)
|
|
157
|
+
except Exception as exc:
|
|
158
|
+
result.errors.append(str(exc))
|
|
159
|
+
return result
|
|
160
|
+
|
|
161
|
+
return result
|
|
162
|
+
|
|
163
|
+
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
164
|
+
return MigrationResult()
|