infrahub-server 1.2.11__py3-none-any.whl → 1.3.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.
Files changed (147) hide show
  1. infrahub/actions/constants.py +86 -0
  2. infrahub/actions/gather.py +114 -0
  3. infrahub/actions/models.py +241 -0
  4. infrahub/actions/parsers.py +104 -0
  5. infrahub/actions/schema.py +382 -0
  6. infrahub/actions/tasks.py +126 -0
  7. infrahub/actions/triggers.py +21 -0
  8. infrahub/cli/db.py +1 -2
  9. infrahub/core/account.py +24 -47
  10. infrahub/core/attribute.py +13 -15
  11. infrahub/core/constants/__init__.py +5 -0
  12. infrahub/core/constants/infrahubkind.py +9 -0
  13. infrahub/core/convert_object_type/__init__.py +0 -0
  14. infrahub/core/convert_object_type/conversion.py +122 -0
  15. infrahub/core/convert_object_type/schema_mapping.py +56 -0
  16. infrahub/core/diff/query/all_conflicts.py +1 -5
  17. infrahub/core/diff/query/artifact.py +10 -20
  18. infrahub/core/diff/query/diff_get.py +3 -6
  19. infrahub/core/diff/query/field_summary.py +2 -4
  20. infrahub/core/diff/query/merge.py +70 -123
  21. infrahub/core/diff/query/save.py +20 -32
  22. infrahub/core/diff/query/summary_counts_enricher.py +34 -54
  23. infrahub/core/manager.py +14 -11
  24. infrahub/core/migrations/graph/m003_relationship_parent_optional.py +1 -2
  25. infrahub/core/migrations/graph/m013_convert_git_password_credential.py +2 -4
  26. infrahub/core/migrations/graph/m019_restore_rels_to_time.py +11 -22
  27. infrahub/core/migrations/graph/m020_duplicate_edges.py +3 -6
  28. infrahub/core/migrations/graph/m021_missing_hierarchy_merge.py +1 -2
  29. infrahub/core/migrations/graph/m024_missing_hierarchy_backfill.py +1 -2
  30. infrahub/core/migrations/query/attribute_add.py +1 -2
  31. infrahub/core/migrations/query/attribute_rename.py +5 -10
  32. infrahub/core/migrations/query/delete_element_in_schema.py +19 -17
  33. infrahub/core/migrations/query/node_duplicate.py +19 -21
  34. infrahub/core/migrations/query/relationship_duplicate.py +19 -17
  35. infrahub/core/migrations/schema/node_attribute_remove.py +4 -8
  36. infrahub/core/migrations/schema/node_remove.py +19 -19
  37. infrahub/core/models.py +29 -2
  38. infrahub/core/node/__init__.py +90 -18
  39. infrahub/core/node/create.py +211 -0
  40. infrahub/core/node/resource_manager/number_pool.py +31 -5
  41. infrahub/core/node/standard.py +6 -1
  42. infrahub/core/protocols.py +56 -0
  43. infrahub/core/protocols_base.py +3 -0
  44. infrahub/core/query/__init__.py +2 -2
  45. infrahub/core/query/diff.py +19 -32
  46. infrahub/core/query/ipam.py +10 -20
  47. infrahub/core/query/node.py +28 -46
  48. infrahub/core/query/relationship.py +53 -32
  49. infrahub/core/query/resource_manager.py +1 -2
  50. infrahub/core/query/subquery.py +2 -4
  51. infrahub/core/relationship/model.py +3 -0
  52. infrahub/core/schema/__init__.py +2 -1
  53. infrahub/core/schema/attribute_parameters.py +160 -0
  54. infrahub/core/schema/attribute_schema.py +111 -8
  55. infrahub/core/schema/basenode_schema.py +25 -1
  56. infrahub/core/schema/definitions/core/__init__.py +29 -1
  57. infrahub/core/schema/definitions/core/group.py +45 -0
  58. infrahub/core/schema/definitions/internal.py +27 -4
  59. infrahub/core/schema/generated/attribute_schema.py +16 -3
  60. infrahub/core/schema/manager.py +3 -0
  61. infrahub/core/schema/schema_branch.py +67 -7
  62. infrahub/core/validators/__init__.py +13 -1
  63. infrahub/core/validators/attribute/choices.py +1 -3
  64. infrahub/core/validators/attribute/enum.py +1 -3
  65. infrahub/core/validators/attribute/kind.py +1 -3
  66. infrahub/core/validators/attribute/length.py +13 -7
  67. infrahub/core/validators/attribute/min_max.py +118 -0
  68. infrahub/core/validators/attribute/number_pool.py +106 -0
  69. infrahub/core/validators/attribute/optional.py +1 -4
  70. infrahub/core/validators/attribute/regex.py +5 -6
  71. infrahub/core/validators/attribute/unique.py +1 -3
  72. infrahub/core/validators/determiner.py +18 -2
  73. infrahub/core/validators/enum.py +12 -0
  74. infrahub/core/validators/node/hierarchy.py +3 -6
  75. infrahub/core/validators/query.py +1 -3
  76. infrahub/core/validators/relationship/count.py +6 -12
  77. infrahub/core/validators/relationship/optional.py +2 -4
  78. infrahub/core/validators/relationship/peer.py +3 -8
  79. infrahub/core/validators/uniqueness/query.py +5 -9
  80. infrahub/database/__init__.py +11 -2
  81. infrahub/events/group_action.py +1 -0
  82. infrahub/git/base.py +5 -3
  83. infrahub/git/integrator.py +102 -3
  84. infrahub/graphql/analyzer.py +139 -18
  85. infrahub/graphql/manager.py +4 -0
  86. infrahub/graphql/mutations/action.py +164 -0
  87. infrahub/graphql/mutations/convert_object_type.py +62 -0
  88. infrahub/graphql/mutations/main.py +24 -175
  89. infrahub/graphql/mutations/proposed_change.py +20 -17
  90. infrahub/graphql/mutations/resource_manager.py +62 -6
  91. infrahub/graphql/queries/convert_object_type_mapping.py +36 -0
  92. infrahub/graphql/queries/resource_manager.py +7 -1
  93. infrahub/graphql/schema.py +6 -0
  94. infrahub/menu/menu.py +31 -0
  95. infrahub/message_bus/messages/__init__.py +0 -10
  96. infrahub/message_bus/operations/__init__.py +0 -8
  97. infrahub/patch/queries/consolidate_duplicated_nodes.py +3 -6
  98. infrahub/patch/queries/delete_duplicated_edges.py +5 -10
  99. infrahub/pools/number.py +5 -3
  100. infrahub/prefect_server/models.py +1 -19
  101. infrahub/proposed_change/models.py +68 -3
  102. infrahub/proposed_change/tasks.py +907 -30
  103. infrahub/task_manager/models.py +10 -6
  104. infrahub/trigger/catalogue.py +2 -0
  105. infrahub/trigger/models.py +18 -2
  106. infrahub/trigger/tasks.py +3 -1
  107. infrahub/types.py +6 -0
  108. infrahub/workflows/catalogue.py +76 -0
  109. infrahub_sdk/client.py +43 -10
  110. infrahub_sdk/node/__init__.py +39 -0
  111. infrahub_sdk/node/attribute.py +122 -0
  112. infrahub_sdk/node/constants.py +21 -0
  113. infrahub_sdk/{node.py → node/node.py} +50 -749
  114. infrahub_sdk/node/parsers.py +15 -0
  115. infrahub_sdk/node/property.py +24 -0
  116. infrahub_sdk/node/related_node.py +266 -0
  117. infrahub_sdk/node/relationship.py +302 -0
  118. infrahub_sdk/protocols.py +112 -0
  119. infrahub_sdk/protocols_base.py +34 -2
  120. infrahub_sdk/query_groups.py +13 -2
  121. infrahub_sdk/schema/main.py +1 -0
  122. infrahub_sdk/schema/repository.py +16 -0
  123. infrahub_sdk/spec/object.py +1 -1
  124. infrahub_sdk/store.py +1 -1
  125. infrahub_sdk/testing/schemas/car_person.py +1 -0
  126. {infrahub_server-1.2.11.dist-info → infrahub_server-1.3.0b1.dist-info}/METADATA +4 -4
  127. {infrahub_server-1.2.11.dist-info → infrahub_server-1.3.0b1.dist-info}/RECORD +134 -122
  128. {infrahub_server-1.2.11.dist-info → infrahub_server-1.3.0b1.dist-info}/WHEEL +1 -1
  129. infrahub_testcontainers/container.py +0 -1
  130. infrahub_testcontainers/docker-compose.test.yml +1 -1
  131. infrahub_testcontainers/helpers.py +8 -2
  132. infrahub/message_bus/messages/check_generator_run.py +0 -26
  133. infrahub/message_bus/messages/finalize_validator_execution.py +0 -15
  134. infrahub/message_bus/messages/proposed_change/base_with_diff.py +0 -16
  135. infrahub/message_bus/messages/proposed_change/request_proposedchange_refreshartifacts.py +0 -11
  136. infrahub/message_bus/messages/request_generatordefinition_check.py +0 -20
  137. infrahub/message_bus/messages/request_proposedchange_pipeline.py +0 -23
  138. infrahub/message_bus/operations/check/__init__.py +0 -3
  139. infrahub/message_bus/operations/check/generator.py +0 -156
  140. infrahub/message_bus/operations/finalize/__init__.py +0 -3
  141. infrahub/message_bus/operations/finalize/validator.py +0 -133
  142. infrahub/message_bus/operations/requests/__init__.py +0 -9
  143. infrahub/message_bus/operations/requests/generator_definition.py +0 -140
  144. infrahub/message_bus/operations/requests/proposed_change.py +0 -629
  145. /infrahub/{message_bus/messages/proposed_change → actions}/__init__.py +0 -0
  146. {infrahub_server-1.2.11.dist-info → infrahub_server-1.3.0b1.dist-info}/LICENSE.txt +0 -0
  147. {infrahub_server-1.2.11.dist-info → infrahub_server-1.3.0b1.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,106 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any
4
+
5
+ from infrahub.core.constants import PathType
6
+ from infrahub.core.path import DataPath, GroupedDataPaths
7
+ from infrahub.core.schema.attribute_parameters import NumberPoolParameters
8
+ from infrahub.core.validators.enum import ConstraintIdentifier
9
+
10
+ from ..interface import ConstraintCheckerInterface
11
+ from ..shared import AttributeSchemaValidatorQuery
12
+
13
+ if TYPE_CHECKING:
14
+ from infrahub.core.branch import Branch
15
+ from infrahub.database import InfrahubDatabase
16
+
17
+ from ..model import SchemaConstraintValidatorRequest
18
+
19
+
20
+ class AttributeNumberPoolUpdateValidatorQuery(AttributeSchemaValidatorQuery):
21
+ name: str = "attribute_constraints_numberpool_validator"
22
+
23
+ async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
24
+ branch_filter, branch_params = self.branch.get_query_filter_path(at=self.at.to_string())
25
+ self.params.update(branch_params)
26
+
27
+ if not isinstance(self.attribute_schema.parameters, NumberPoolParameters):
28
+ raise ValueError("attribute parameters are not a NumberPoolParameters")
29
+
30
+ self.params["attr_name"] = self.attribute_schema.name
31
+ self.params["start_range"] = self.attribute_schema.parameters.start_range
32
+ self.params["end_range"] = self.attribute_schema.parameters.end_range
33
+
34
+ query = """
35
+ MATCH (n:%(node_kind)s)
36
+ CALL (n) {
37
+ MATCH path = (root:Root)<-[rr:IS_PART_OF]-(n)-[ra:HAS_ATTRIBUTE]-(:Attribute { name: $attr_name } )-[rv:HAS_VALUE]-(av:AttributeValue)
38
+ WHERE all(
39
+ r in relationships(path)
40
+ WHERE %(branch_filter)s
41
+ )
42
+ RETURN path as full_path, n as node, rv as value_relationship, av.value as attribute_value
43
+ ORDER BY rv.branch_level DESC, ra.branch_level DESC, rr.branch_level DESC, rv.from DESC, ra.from DESC, rr.from DESC
44
+ LIMIT 1
45
+ }
46
+ WITH full_path, node, attribute_value, value_relationship
47
+ WHERE all(r in relationships(full_path) WHERE r.status = "active")
48
+ AND (
49
+ (toInteger($start_range) IS NOT NULL AND attribute_value < toInteger($start_range))
50
+ OR (toInteger($end_range) IS NOT NULL AND attribute_value > toInteger($end_range))
51
+ )
52
+ """ % {"branch_filter": branch_filter, "node_kind": self.node_schema.kind}
53
+
54
+ self.add_to_query(query)
55
+ self.return_labels = ["node.uuid", "value_relationship", "attribute_value"]
56
+
57
+ async def get_paths(self) -> GroupedDataPaths:
58
+ grouped_data_paths = GroupedDataPaths()
59
+ for result in self.results:
60
+ grouped_data_paths.add_data_path(
61
+ DataPath(
62
+ branch=str(result.get("value_relationship").get("branch")),
63
+ path_type=PathType.ATTRIBUTE,
64
+ node_id=str(result.get("node.uuid")),
65
+ field_name=self.attribute_schema.name,
66
+ kind=self.node_schema.kind,
67
+ value=result.get("attribute_value"),
68
+ ),
69
+ )
70
+
71
+ return grouped_data_paths
72
+
73
+
74
+ class AttributeNumberPoolChecker(ConstraintCheckerInterface):
75
+ query_classes = [AttributeNumberPoolUpdateValidatorQuery]
76
+
77
+ def __init__(self, db: InfrahubDatabase, branch: Branch | None = None):
78
+ self.db = db
79
+ self.branch = branch
80
+
81
+ @property
82
+ def name(self) -> str:
83
+ return "attribute.number.update"
84
+
85
+ def supports(self, request: SchemaConstraintValidatorRequest) -> bool:
86
+ return request.constraint_name in (
87
+ ConstraintIdentifier.ATTRIBUTE_PARAMETERS_START_RANGE_UPDATE.value,
88
+ ConstraintIdentifier.ATTRIBUTE_PARAMETERS_END_RANGE_UPDATE.value,
89
+ )
90
+
91
+ async def check(self, request: SchemaConstraintValidatorRequest) -> list[GroupedDataPaths]:
92
+ grouped_data_paths_list: list[GroupedDataPaths] = []
93
+ if not request.schema_path.field_name:
94
+ raise ValueError("field_name is not defined")
95
+ attribute_schema = request.node_schema.get_attribute(name=request.schema_path.field_name)
96
+ if not isinstance(attribute_schema.parameters, NumberPoolParameters):
97
+ raise ValueError("attribute parameters are not a NumberPoolParameters")
98
+
99
+ for query_class in self.query_classes:
100
+ # TODO add exception handling
101
+ query = await query_class.init(
102
+ db=self.db, branch=self.branch, node_schema=request.node_schema, schema_path=request.schema_path
103
+ )
104
+ await query.execute(db=self.db)
105
+ grouped_data_paths_list.append(await query.get_paths())
106
+ return grouped_data_paths_list
@@ -27,8 +27,7 @@ class AttributeOptionalUpdateValidatorQuery(AttributeSchemaValidatorQuery):
27
27
 
28
28
  query = """
29
29
  MATCH (n:%(node_kind)s)
30
- CALL {
31
- WITH n
30
+ CALL (n) {
32
31
  MATCH path = (root:Root)<-[rr:IS_PART_OF]-(n)-[ra:HAS_ATTRIBUTE]-(:Attribute { name: $attr_name } )-[rv:HAS_VALUE]-(av:AttributeValue)
33
32
  WHERE all(
34
33
  r in relationships(path)
@@ -39,7 +38,6 @@ class AttributeOptionalUpdateValidatorQuery(AttributeSchemaValidatorQuery):
39
38
  LIMIT 1
40
39
  }
41
40
  WITH full_path, node, attribute_value, value_relationship
42
- WITH full_path, node, attribute_value, value_relationship
43
41
  WHERE all(r in relationships(full_path) WHERE r.status = "active")
44
42
  AND (attribute_value IS NULL OR attribute_value = $null_value)
45
43
  """ % {"branch_filter": branch_filter, "node_kind": self.node_schema.kind}
@@ -86,7 +84,6 @@ class AttributeOptionalChecker(ConstraintCheckerInterface):
86
84
  return grouped_data_paths_list
87
85
 
88
86
  for query_class in self.query_classes:
89
- # TODO add exception handling
90
87
  query = await query_class.init(
91
88
  db=self.db, branch=self.branch, node_schema=request.node_schema, schema_path=request.schema_path
92
89
  )
@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Any
4
4
 
5
5
  from infrahub.core.constants import NULL_VALUE, PathType
6
6
  from infrahub.core.path import DataPath, GroupedDataPaths
7
+ from infrahub.core.validators.enum import ConstraintIdentifier
7
8
 
8
9
  from ..interface import ConstraintCheckerInterface
9
10
  from ..shared import AttributeSchemaValidatorQuery
@@ -23,12 +24,11 @@ class AttributeRegexUpdateValidatorQuery(AttributeSchemaValidatorQuery):
23
24
  self.params.update(branch_params)
24
25
 
25
26
  self.params["attr_name"] = self.attribute_schema.name
26
- self.params["attr_value_regex"] = self.attribute_schema.regex
27
+ self.params["attr_value_regex"] = self.attribute_schema.get_regex()
27
28
  self.params["null_value"] = NULL_VALUE
28
29
  query = """
29
30
  MATCH p = (n:%(node_kind)s)
30
- CALL {
31
- WITH n
31
+ CALL (n) {
32
32
  MATCH path = (root:Root)<-[rr:IS_PART_OF]-(n)-[ra:HAS_ATTRIBUTE]-(:Attribute { name: $attr_name } )-[rv:HAS_VALUE]-(av:AttributeValue)
33
33
  WHERE all(
34
34
  r in relationships(path)
@@ -39,7 +39,6 @@ class AttributeRegexUpdateValidatorQuery(AttributeSchemaValidatorQuery):
39
39
  LIMIT 1
40
40
  }
41
41
  WITH full_path, node, attribute_value, value_relationship
42
- WITH full_path, node, attribute_value, value_relationship
43
42
  WHERE all(r in relationships(full_path) WHERE r.status = "active")
44
43
  AND attribute_value <> $null_value
45
44
  AND NOT attribute_value =~ $attr_value_regex
@@ -79,14 +78,14 @@ class AttributeRegexChecker(ConstraintCheckerInterface):
79
78
  return "attribute.regex.update"
80
79
 
81
80
  def supports(self, request: SchemaConstraintValidatorRequest) -> bool:
82
- return request.constraint_name == self.name
81
+ return request.constraint_name in (self.name, ConstraintIdentifier.ATTRIBUTE_PARAMETERS_REGEX_UPDATE.value)
83
82
 
84
83
  async def check(self, request: SchemaConstraintValidatorRequest) -> list[GroupedDataPaths]:
85
84
  grouped_data_paths_list: list[GroupedDataPaths] = []
86
85
  if not request.schema_path.field_name:
87
86
  raise ValueError("field_name is not defined")
88
87
  attribute_schema = request.node_schema.get_attribute(name=request.schema_path.field_name)
89
- if not attribute_schema.regex:
88
+ if not attribute_schema.get_regex():
90
89
  return grouped_data_paths_list
91
90
 
92
91
  for query_class in self.query_classes:
@@ -31,12 +31,10 @@ class AttributeUniqueUpdateValidatorQuery(AttributeSchemaValidatorQuery):
31
31
  query = """
32
32
  MATCH (potential_node:Node)
33
33
  WHERE $node_kind IN LABELS(potential_node)
34
- CALL {
35
- WITH potential_node
34
+ CALL (potential_node) {
36
35
  MATCH potential_path = (potential_node)-[:HAS_ATTRIBUTE]-(:Attribute { name: $attr_name })-[potential_value_relationship:HAS_VALUE]-(potential_value:AttributeValue)
37
36
  WHERE all(r IN relationships(potential_path) WHERE (%(branch_filter)s))
38
37
  WITH
39
- potential_node,
40
38
  potential_value,
41
39
  potential_value_relationship,
42
40
  potential_path,
@@ -1,14 +1,20 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
1
3
  from infrahub.core.constants import RelationshipKind, SchemaPathType
2
4
  from infrahub.core.constants.schema import UpdateSupport
3
5
  from infrahub.core.diff.model.path import NodeDiffFieldSummary
4
6
  from infrahub.core.models import SchemaUpdateConstraintInfo
5
7
  from infrahub.core.path import SchemaPath
6
8
  from infrahub.core.schema import AttributeSchema, MainSchemaTypes
9
+ from infrahub.core.schema.attribute_parameters import AttributeParameters
7
10
  from infrahub.core.schema.relationship_schema import RelationshipSchema
8
11
  from infrahub.core.schema.schema_branch import SchemaBranch
9
12
  from infrahub.core.validators import CONSTRAINT_VALIDATOR_MAP
10
13
  from infrahub.log import get_logger
11
14
 
15
+ if TYPE_CHECKING:
16
+ from pydantic.fields import FieldInfo
17
+
12
18
  LOG = get_logger(__name__)
13
19
 
14
20
 
@@ -133,7 +139,17 @@ class ConstraintValidatorDeterminer:
133
139
  self, schema: MainSchemaTypes, field: AttributeSchema | RelationshipSchema
134
140
  ) -> list[SchemaUpdateConstraintInfo]:
135
141
  constraints: list[SchemaUpdateConstraintInfo] = []
136
- for prop_name, prop_field_info in field.model_fields.items():
142
+ prop_details_list: list[tuple[str, FieldInfo, Any]] = []
143
+ for p_name, p_info in field.model_fields.items():
144
+ p_value = getattr(field, p_name)
145
+ if isinstance(p_value, AttributeParameters):
146
+ for parameter_name, parameter_field_info in p_value.model_fields.items():
147
+ parameter_value = getattr(p_value, parameter_name)
148
+ prop_details_list.append((f"{p_name}.{parameter_name}", parameter_field_info, parameter_value))
149
+ else:
150
+ prop_details_list.append((p_name, p_info, p_value))
151
+
152
+ for prop_name, prop_field_info, prop_value in prop_details_list:
137
153
  if not prop_field_info.json_schema_extra or not isinstance(prop_field_info.json_schema_extra, dict):
138
154
  continue
139
155
 
@@ -141,7 +157,7 @@ class ConstraintValidatorDeterminer:
141
157
  if prop_field_update != UpdateSupport.VALIDATE_CONSTRAINT.value:
142
158
  continue
143
159
 
144
- if getattr(field, prop_name) is None:
160
+ if prop_value is None:
145
161
  continue
146
162
 
147
163
  path_type = SchemaPathType.ATTRIBUTE
@@ -0,0 +1,12 @@
1
+ from enum import Enum
2
+
3
+
4
+ class ConstraintIdentifier(str, Enum):
5
+ ATTRIBUTE_PARAMETERS_REGEX_UPDATE = "attribute.parameters.regex.update"
6
+ ATTRIBUTE_PARAMETERS_MIN_LENGTH_UPDATE = "attribute.parameters.min_length.update"
7
+ ATTRIBUTE_PARAMETERS_MAX_LENGTH_UPDATE = "attribute.parameters.max_length.update"
8
+ ATTRIBUTE_PARAMETERS_MIN_VALUE_UPDATE = "attribute.parameters.min_value.update"
9
+ ATTRIBUTE_PARAMETERS_MAX_VALUE_UPDATE = "attribute.parameters.max_value.update"
10
+ ATTRIBUTE_PARAMETERS_EXCLUDED_VALUES_UPDATE = "attribute.parameters.excluded_values.update"
11
+ ATTRIBUTE_PARAMETERS_END_RANGE_UPDATE = "attribute.parameters.end_range.update"
12
+ ATTRIBUTE_PARAMETERS_START_RANGE_UPDATE = "attribute.parameters.start_range.update"
@@ -59,8 +59,7 @@ class NodeHierarchyUpdateValidatorQuery(SchemaValidatorQuery):
59
59
  # ruff: noqa: E501
60
60
  query = """
61
61
  MATCH (n:%(node_kind)s)
62
- CALL {
63
- WITH n
62
+ CALL (n) {
64
63
  MATCH path = (root:Root)<-[rroot:IS_PART_OF]-(n)
65
64
  WHERE all(r in relationships(path) WHERE %(branch_filter)s)
66
65
  RETURN path as full_path, n as active_node
@@ -70,8 +69,7 @@ class NodeHierarchyUpdateValidatorQuery(SchemaValidatorQuery):
70
69
  WITH full_path, active_node
71
70
  WITH full_path, active_node
72
71
  WHERE all(r in relationships(full_path) WHERE r.status = "active")
73
- CALL {
74
- WITH active_node
72
+ CALL (active_node) {
75
73
  MATCH path = (active_node)%(to_children)s-[hrel1:IS_RELATED]-%(to_parent)s(:Relationship {name: "parent__child"})%(to_children)s-[hrel2:IS_RELATED]-%(to_parent)s(peer:Node)
76
74
  WHERE all(
77
75
  r in relationships(path)
@@ -91,8 +89,7 @@ class NodeHierarchyUpdateValidatorQuery(SchemaValidatorQuery):
91
89
  collect([branch_level_sum, from_times, active_relationship_count, hierarchy_path, deepest_branch_name]) as enriched_paths,
92
90
  start_node,
93
91
  peer_node
94
- CALL {
95
- WITH enriched_paths, peer_node
92
+ CALL (enriched_paths, peer_node) {
96
93
  UNWIND enriched_paths as path_to_check
97
94
  RETURN path_to_check[3] as current_path, path_to_check[4] as branch_name, peer_node as current_peer
98
95
  ORDER BY
@@ -20,8 +20,7 @@ class NodeNotPresentValidatorQuery(SchemaValidatorQuery):
20
20
 
21
21
  query = """
22
22
  MATCH (n:%(node_kind)s)
23
- CALL {
24
- WITH n
23
+ CALL (n) {
25
24
  MATCH path = (root:Root)<-[rr:IS_PART_OF]-(n)
26
25
  WHERE all(
27
26
  r in relationships(path)
@@ -32,7 +31,6 @@ class NodeNotPresentValidatorQuery(SchemaValidatorQuery):
32
31
  LIMIT 1
33
32
  }
34
33
  WITH full_path, node, root_relationship
35
- WITH full_path, node, root_relationship
36
34
  WHERE all(r in relationships(full_path) WHERE r.status = "active")
37
35
  """ % {"branch_filter": branch_filter, "node_kind": self.node_schema.kind}
38
36
 
@@ -50,8 +50,7 @@ class RelationshipCountUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
50
50
  query = """
51
51
  // get the nodes on these branches nodes
52
52
  MATCH (n:%(node_kind)s)
53
- CALL {
54
- WITH n
53
+ CALL (n) {
55
54
  MATCH path = (root:Root)<-[rroot:IS_PART_OF]-(n)
56
55
  WHERE all(r in relationships(path) WHERE %(branch_filter)s)
57
56
  RETURN path as full_path, n as active_node
@@ -60,11 +59,9 @@ class RelationshipCountUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
60
59
  }
61
60
  // filter to only the active nodes
62
61
  WITH full_path, active_node
63
- WITH full_path, active_node
64
62
  WHERE all(r in relationships(full_path) WHERE r.status = "active")
65
63
  // get the relationships using the given identifier for each node
66
- CALL {
67
- WITH active_node
64
+ CALL (active_node) {
68
65
  MATCH path = (active_node)-[rrel1:IS_RELATED]-(rel:Relationship { name: $relationship_id })-[rrel2:IS_RELATED]-(peer:Node)
69
66
  WHERE ($relationship_direction <> "outbound" OR (startNode(rrel1) = active_node AND startNode(rrel2) = rel))
70
67
  AND ($relationship_direction <> "inbound" OR (startNode(rrel1) = rel AND startNode(rrel2) = peer))
@@ -87,8 +84,7 @@ class RelationshipCountUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
87
84
  start_node,
88
85
  peer_node
89
86
  // make sure to only use the latest version of this particular path
90
- CALL {
91
- WITH enriched_paths, peer_node
87
+ CALL (enriched_paths, peer_node) {
92
88
  UNWIND enriched_paths as path_to_check
93
89
  RETURN path_to_check[3] as current_path, path_to_check[4] as branch_name, peer_node as current_peer
94
90
  ORDER BY
@@ -100,8 +96,7 @@ class RelationshipCountUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
100
96
  }
101
97
  // filter to only the current active paths
102
98
  WITH collect([current_peer, current_path]) as peers_and_paths, start_node, branch_name
103
- CALL {
104
- WITH peers_and_paths
99
+ CALL (peers_and_paths) {
105
100
  UNWIND peers_and_paths AS peer_and_path
106
101
  WITH peer_and_path
107
102
  WHERE all(r in relationships(peer_and_path[1]) WHERE r.status = "active")
@@ -109,9 +104,8 @@ class RelationshipCountUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
109
104
  }
110
105
  // sum all the relationships across branches and identify the violators
111
106
  WITH collect([branch_name, num_relationships_on_branch]) as branches_and_counts, start_node
112
- CALL {
113
- WITH start_node, branches_and_counts
114
- WITH start_node, branches_and_counts, reduce(rel_total = 0, bnc in branches_and_counts | rel_total + bnc[1]) AS total_relationships_count
107
+ CALL (start_node, branches_and_counts) {
108
+ WITH reduce(rel_total = 0, bnc in branches_and_counts | rel_total + bnc[1]) AS total_relationships_count
115
109
  WHERE
116
110
  (toInteger($min_count) IS NOT NULL AND total_relationships_count < toInteger($min_count))
117
111
  OR (toInteger($max_count) IS NOT NULL AND total_relationships_count > toInteger($max_count))
@@ -30,8 +30,7 @@ class RelationshipOptionalUpdateValidatorQuery(RelationshipSchemaValidatorQuery)
30
30
  // Query all Active Nodes of type
31
31
  // and store their UUID in uuids_active_node
32
32
  MATCH (n:%(node_kind)s)
33
- CALL {
34
- WITH n
33
+ CALL (n) {
35
34
  MATCH (root:Root)<-[r:IS_PART_OF]-(n)
36
35
  WHERE %(branch_filter)s
37
36
  RETURN n as n1, r as r1
@@ -44,8 +43,7 @@ class RelationshipOptionalUpdateValidatorQuery(RelationshipSchemaValidatorQuery)
44
43
  // identifier all nodes with at least one active member for this relationship
45
44
  // and store their UUID in uuids_with_rel
46
45
  MATCH (n:%(node_kind)s)
47
- CALL {
48
- WITH n, uuids_active_node
46
+ CALL (n, uuids_active_node) {
49
47
  MATCH path = (n)-[r:IS_RELATED]-(:Relationship { name: $relationship_id })
50
48
  WHERE %(branch_filter)s
51
49
  RETURN n as n1, r as r1
@@ -36,8 +36,7 @@ class RelationshipPeerUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
36
36
  # ruff: noqa: E501
37
37
  query = """
38
38
  MATCH (n:%(node_kind)s)
39
- CALL {
40
- WITH n
39
+ CALL (n) {
41
40
  MATCH path = (root:Root)<-[rroot:IS_PART_OF]-(n)
42
41
  WHERE all(r in relationships(path) WHERE %(branch_filter)s)
43
42
  RETURN path as full_path, n as active_node
@@ -45,10 +44,8 @@ class RelationshipPeerUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
45
44
  LIMIT 1
46
45
  }
47
46
  WITH full_path, active_node
48
- WITH full_path, active_node
49
47
  WHERE all(r in relationships(full_path) WHERE r.status = "active")
50
- CALL {
51
- WITH active_node
48
+ CALL (active_node) {
52
49
  MATCH path = (active_node)-[rrel1:IS_RELATED]-(rel:Relationship { name: $relationship_id })-[rrel2:IS_RELATED]-(peer:Node)
53
50
  WHERE all(
54
51
  r in relationships(path)
@@ -68,8 +65,7 @@ class RelationshipPeerUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
68
65
  collect([branch_level_sum, from_times, active_relationship_count, relationship_path, deepest_branch_name]) as enriched_paths,
69
66
  start_node,
70
67
  peer_node
71
- CALL {
72
- WITH enriched_paths, peer_node
68
+ CALL (enriched_paths, peer_node) {
73
69
  UNWIND enriched_paths as path_to_check
74
70
  RETURN path_to_check[3] as current_path, path_to_check[4] as branch_name, peer_node as current_peer
75
71
  ORDER BY
@@ -80,7 +76,6 @@ class RelationshipPeerUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
80
76
  LIMIT 1
81
77
  }
82
78
  WITH start_node, current_peer, branch_name, current_path
83
- WITH start_node, current_peer, branch_name, current_path
84
79
  WHERE all(r in relationships(current_path) WHERE r.status = "active")
85
80
  AND NOT any(label IN LABELS(current_peer) WHERE label IN $allowed_peer_kinds)
86
81
  """ % {"branch_filter": branch_filter, "node_kind": self.node_schema.kind}
@@ -158,12 +158,11 @@ class NodeUniqueAttributeConstraintQuery(Query):
158
158
  # ruff: noqa: E501
159
159
  query = """
160
160
  // get attributes for node and its relationships
161
- CALL {
161
+ CALL () {
162
162
  %(select_subqueries_str)s
163
163
  }
164
- CALL {
164
+ CALL (potential_path) {
165
165
  WITH potential_path
166
- WITH potential_path // workaround for neo4j not allowing WHERE in a WITH of a subquery
167
166
  // only the branches and times we care about
168
167
  WHERE all(
169
168
  r IN relationships(potential_path) WHERE (
@@ -183,8 +182,7 @@ class NodeUniqueAttributeConstraintQuery(Query):
183
182
  start_node,
184
183
  rel_identifier,
185
184
  potential_attr
186
- CALL {
187
- WITH enriched_paths
185
+ CALL (enriched_paths) {
188
186
  UNWIND enriched_paths as path_to_check
189
187
  RETURN path_to_check[0] as current_path, path_to_check[4] as latest_value
190
188
  ORDER BY
@@ -194,16 +192,14 @@ class NodeUniqueAttributeConstraintQuery(Query):
194
192
  path_to_check[3] DESC
195
193
  LIMIT 1
196
194
  }
197
- CALL {
195
+ CALL (current_path) {
198
196
  // only active paths
199
197
  WITH current_path
200
- WITH current_path // workaround for neo4j not allowing WHERE in a WITH of a subquery
201
198
  WHERE all(r IN relationships(current_path) WHERE r.status = "active")
202
199
  RETURN current_path as active_path
203
200
  }
204
- CALL {
201
+ CALL (active_path) {
205
202
  // get deepest branch name
206
- WITH active_path
207
203
  UNWIND %(branch_name_and_level)s as branch_name_and_level
208
204
  RETURN branch_name_and_level[0] as branch_name
209
205
  ORDER BY branch_name_and_level[1] DESC
@@ -39,7 +39,7 @@ if TYPE_CHECKING:
39
39
  from types import TracebackType
40
40
 
41
41
  from infrahub.core.branch import Branch
42
- from infrahub.core.schema import MainSchemaTypes, NodeSchema
42
+ from infrahub.core.schema import GenericSchema, MainSchemaTypes, NodeSchema
43
43
  from infrahub.core.schema.schema_branch import SchemaBranch
44
44
 
45
45
  validated_database = {}
@@ -91,6 +91,15 @@ class DatabaseSchemaManager:
91
91
 
92
92
  raise ValueError("The selected node is not of type NodeSchema")
93
93
 
94
+ def get_generic_schema(
95
+ self, name: str, branch: Branch | str | None = None, duplicate: bool = True
96
+ ) -> GenericSchema:
97
+ schema = self.get(name=name, branch=branch, duplicate=duplicate)
98
+ if schema.is_generic_schema:
99
+ return schema
100
+
101
+ raise ValueError("The selected node is not of type GenericSchema")
102
+
94
103
  def set(self, name: str, schema: MainSchemaTypes, branch: str | None = None) -> int:
95
104
  branch_name = get_branch_name(branch=branch)
96
105
  if branch_name not in self._db._schemas:
@@ -284,7 +293,7 @@ class InfrahubDatabase:
284
293
  exc_type: type[BaseException] | None,
285
294
  exc_value: BaseException | None,
286
295
  traceback: TracebackType | None,
287
- ):
296
+ ) -> None:
288
297
  if self._mode == InfrahubDatabaseMode.SESSION:
289
298
  return await self._session.close()
290
299
 
@@ -89,6 +89,7 @@ class GroupMutatedEvent(InfrahubEvent):
89
89
  "infrahub.node.id": self.node_id,
90
90
  "infrahub.node.action": self.action.value,
91
91
  "infrahub.node.root_id": self.node_id,
92
+ "infrahub.branch.name": self.meta.context.branch.name,
92
93
  }
93
94
 
94
95
 
infrahub/git/base.py CHANGED
@@ -162,6 +162,11 @@ class InfrahubRepositoryBase(BaseModel, ABC):
162
162
  infrahub_branch_name: str | None = Field(None, description="Infrahub branch on which to sync the remote repository")
163
163
  model_config = ConfigDict(arbitrary_types_allowed=True, ignored_types=(Flow, Task))
164
164
 
165
+ def get_client(self) -> InfrahubClient:
166
+ if self.client is None:
167
+ raise ValueError("Client is not set")
168
+ return self.client
169
+
165
170
  @property
166
171
  def sdk(self) -> InfrahubClient:
167
172
  if self.client:
@@ -445,9 +450,6 @@ class InfrahubRepositoryBase(BaseModel, ABC):
445
450
 
446
451
  return [Worktree.init(response) for response in responses]
447
452
 
448
- def get_client(self) -> InfrahubClient:
449
- return self.sdk
450
-
451
453
  def get_location(self) -> str:
452
454
  if self.location:
453
455
  return self.location