infrahub-server 1.3.3__py3-none-any.whl → 1.3.4__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 (33) hide show
  1. infrahub/api/schema.py +2 -2
  2. infrahub/core/convert_object_type/conversion.py +10 -0
  3. infrahub/core/diff/enricher/hierarchy.py +7 -3
  4. infrahub/core/diff/query_parser.py +7 -3
  5. infrahub/core/graph/__init__.py +1 -1
  6. infrahub/core/migrations/graph/__init__.py +2 -0
  7. infrahub/core/migrations/graph/m034_find_orphaned_schema_fields.py +84 -0
  8. infrahub/core/migrations/schema/node_attribute_add.py +55 -2
  9. infrahub/core/migrations/shared.py +37 -9
  10. infrahub/core/node/__init__.py +41 -21
  11. infrahub/core/node/resource_manager/number_pool.py +60 -22
  12. infrahub/core/query/resource_manager.py +117 -20
  13. infrahub/core/schema/__init__.py +5 -0
  14. infrahub/core/schema/attribute_parameters.py +6 -0
  15. infrahub/core/schema/attribute_schema.py +6 -0
  16. infrahub/core/schema/manager.py +5 -11
  17. infrahub/core/schema/relationship_schema.py +6 -0
  18. infrahub/core/schema/schema_branch.py +50 -11
  19. infrahub/core/validators/node/attribute.py +15 -0
  20. infrahub/core/validators/tasks.py +12 -4
  21. infrahub/graphql/queries/resource_manager.py +4 -4
  22. infrahub/tasks/registry.py +63 -35
  23. infrahub_sdk/client.py +7 -8
  24. infrahub_sdk/ctl/utils.py +3 -0
  25. infrahub_sdk/node/node.py +6 -6
  26. infrahub_sdk/node/relationship.py +43 -2
  27. infrahub_sdk/yaml.py +13 -7
  28. infrahub_server-1.3.4.dist-info/LICENSE.txt +201 -0
  29. {infrahub_server-1.3.3.dist-info → infrahub_server-1.3.4.dist-info}/METADATA +3 -3
  30. {infrahub_server-1.3.3.dist-info → infrahub_server-1.3.4.dist-info}/RECORD +32 -31
  31. infrahub_server-1.3.3.dist-info/LICENSE.txt +0 -661
  32. {infrahub_server-1.3.3.dist-info → infrahub_server-1.3.4.dist-info}/WHEEL +0 -0
  33. {infrahub_server-1.3.3.dist-info → infrahub_server-1.3.4.dist-info}/entry_points.txt +0 -0
infrahub_sdk/client.py CHANGED
@@ -784,7 +784,6 @@ class InfrahubClient(BaseClient):
784
784
  if at:
785
785
  at = Timestamp(at)
786
786
 
787
- node = InfrahubNode(client=self, schema=schema, branch=branch)
788
787
  filters = kwargs
789
788
  pagination_size = self.pagination_size
790
789
 
@@ -825,12 +824,12 @@ class InfrahubClient(BaseClient):
825
824
  nodes = []
826
825
  related_nodes = []
827
826
  batch_process = await self.create_batch()
828
- count = await self.count(kind=schema.kind, partial_match=partial_match, **filters)
827
+ count = await self.count(kind=schema.kind, branch=branch, partial_match=partial_match, **filters)
829
828
  total_pages = (count + pagination_size - 1) // pagination_size
830
829
 
831
830
  for page_number in range(1, total_pages + 1):
832
831
  page_offset = (page_number - 1) * pagination_size
833
- batch_process.add(task=process_page, node=node, page_offset=page_offset, page_number=page_number)
832
+ batch_process.add(task=process_page, page_offset=page_offset, page_number=page_number)
834
833
 
835
834
  async for _, response in batch_process.execute():
836
835
  nodes.extend(response[1]["nodes"])
@@ -847,7 +846,7 @@ class InfrahubClient(BaseClient):
847
846
 
848
847
  while has_remaining_items:
849
848
  page_offset = (page_number - 1) * pagination_size
850
- response, process_result = await process_page(page_offset, page_number)
849
+ response, process_result = await process_page(page_offset=page_offset, page_number=page_number)
851
850
 
852
851
  nodes.extend(process_result["nodes"])
853
852
  related_nodes.extend(process_result["related_nodes"])
@@ -1946,9 +1945,9 @@ class InfrahubClientSync(BaseClient):
1946
1945
  """
1947
1946
  branch = branch or self.default_branch
1948
1947
  schema = self.schema.get(kind=kind, branch=branch)
1949
- node = InfrahubNodeSync(client=self, schema=schema, branch=branch)
1950
1948
  if at:
1951
1949
  at = Timestamp(at)
1950
+
1952
1951
  filters = kwargs
1953
1952
  pagination_size = self.pagination_size
1954
1953
 
@@ -1990,12 +1989,12 @@ class InfrahubClientSync(BaseClient):
1990
1989
  related_nodes = []
1991
1990
  batch_process = self.create_batch()
1992
1991
 
1993
- count = self.count(kind=schema.kind, partial_match=partial_match, **filters)
1992
+ count = self.count(kind=schema.kind, branch=branch, partial_match=partial_match, **filters)
1994
1993
  total_pages = (count + pagination_size - 1) // pagination_size
1995
1994
 
1996
1995
  for page_number in range(1, total_pages + 1):
1997
1996
  page_offset = (page_number - 1) * pagination_size
1998
- batch_process.add(task=process_page, node=node, page_offset=page_offset, page_number=page_number)
1997
+ batch_process.add(task=process_page, page_offset=page_offset, page_number=page_number)
1999
1998
 
2000
1999
  for _, response in batch_process.execute():
2001
2000
  nodes.extend(response[1]["nodes"])
@@ -2012,7 +2011,7 @@ class InfrahubClientSync(BaseClient):
2012
2011
 
2013
2012
  while has_remaining_items:
2014
2013
  page_offset = (page_number - 1) * pagination_size
2015
- response, process_result = process_page(page_offset, page_number)
2014
+ response, process_result = process_page(page_offset=page_offset, page_number=page_number)
2016
2015
 
2017
2016
  nodes.extend(process_result["nodes"])
2018
2017
  related_nodes.extend(process_result["related_nodes"])
infrahub_sdk/ctl/utils.py CHANGED
@@ -187,6 +187,9 @@ def load_yamlfile_from_disk_and_exit(
187
187
  has_error = False
188
188
  try:
189
189
  data_files = file_type.load_from_disk(paths=paths)
190
+ if not data_files:
191
+ console.print("[red]No valid files found to load.")
192
+ raise typer.Exit(1)
190
193
  except FileNotValidError as exc:
191
194
  console.print(f"[red]{exc.message}")
192
195
  raise typer.Exit(1) from exc
infrahub_sdk/node/node.py CHANGED
@@ -402,10 +402,10 @@ class InfrahubNodeBase:
402
402
  if order:
403
403
  data["@filters"]["order"] = order
404
404
 
405
- if offset:
405
+ if offset is not None:
406
406
  data["@filters"]["offset"] = offset
407
407
 
408
- if limit:
408
+ if limit is not None:
409
409
  data["@filters"]["limit"] = limit
410
410
 
411
411
  if include and exclude:
@@ -1493,15 +1493,15 @@ class InfrahubNodeSync(InfrahubNodeBase):
1493
1493
  for rel_name in self._relationships:
1494
1494
  rel = getattr(self, rel_name)
1495
1495
  if rel and isinstance(rel, RelatedNodeSync):
1496
- relation = node_data["node"].get(rel_name)
1497
- if relation.get("node", None):
1496
+ relation = node_data["node"].get(rel_name, None)
1497
+ if relation and relation.get("node", None):
1498
1498
  related_node = InfrahubNodeSync.from_graphql(
1499
1499
  client=self._client, branch=branch, data=relation, timeout=timeout
1500
1500
  )
1501
1501
  related_nodes.append(related_node)
1502
1502
  elif rel and isinstance(rel, RelationshipManagerSync):
1503
- peers = node_data["node"].get(rel_name)
1504
- if peers:
1503
+ peers = node_data["node"].get(rel_name, None)
1504
+ if peers and peers["edges"]:
1505
1505
  for peer in peers["edges"]:
1506
1506
  related_node = InfrahubNodeSync.from_graphql(
1507
1507
  client=self._client, branch=branch, data=peer, timeout=timeout
@@ -1,11 +1,15 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from collections import defaultdict
3
4
  from collections.abc import Iterable
4
5
  from typing import TYPE_CHECKING, Any
5
6
 
7
+ from ..batch import InfrahubBatch
6
8
  from ..exceptions import (
9
+ Error,
7
10
  UninitializedError,
8
11
  )
12
+ from ..types import Order
9
13
  from .constants import PROPERTIES_FLAG, PROPERTIES_OBJECT
10
14
  from .related_node import RelatedNode, RelatedNodeSync
11
15
 
@@ -156,8 +160,26 @@ class RelationshipManager(RelationshipManagerBase):
156
160
  self.peers = rm.peers
157
161
  self.initialized = True
158
162
 
163
+ ids_per_kind_map = defaultdict(list)
159
164
  for peer in self.peers:
160
- await peer.fetch() # type: ignore[misc]
165
+ if not peer.id or not peer.typename:
166
+ raise Error("Unable to fetch the peer, id and/or typename are not defined")
167
+ ids_per_kind_map[peer.typename].append(peer.id)
168
+
169
+ batch = InfrahubBatch(max_concurrent_execution=self.client.max_concurrent_execution)
170
+ for kind, ids in ids_per_kind_map.items():
171
+ batch.add(
172
+ task=self.client.filters,
173
+ kind=kind,
174
+ ids=ids,
175
+ populate_store=True,
176
+ branch=self.branch,
177
+ parallel=True,
178
+ order=Order(disable=True),
179
+ )
180
+
181
+ async for _ in batch.execute():
182
+ pass
161
183
 
162
184
  def add(self, data: str | RelatedNode | dict) -> None:
163
185
  """Add a new peer to this relationship."""
@@ -261,8 +283,27 @@ class RelationshipManagerSync(RelationshipManagerBase):
261
283
  self.peers = rm.peers
262
284
  self.initialized = True
263
285
 
286
+ ids_per_kind_map = defaultdict(list)
264
287
  for peer in self.peers:
265
- peer.fetch()
288
+ if not peer.id or not peer.typename:
289
+ raise Error("Unable to fetch the peer, id and/or typename are not defined")
290
+ ids_per_kind_map[peer.typename].append(peer.id)
291
+
292
+ # Unlike Async, no need to create a new batch from scratch because we are not using a semaphore
293
+ batch = self.client.create_batch()
294
+ for kind, ids in ids_per_kind_map.items():
295
+ batch.add(
296
+ task=self.client.filters,
297
+ kind=kind,
298
+ ids=ids,
299
+ populate_store=True,
300
+ branch=self.branch,
301
+ parallel=True,
302
+ order=Order(disable=True),
303
+ )
304
+
305
+ for _ in batch.execute():
306
+ pass
266
307
 
267
308
  def add(self, data: str | RelatedNodeSync | dict) -> None:
268
309
  """Add a new peer to this relationship."""
infrahub_sdk/yaml.py CHANGED
@@ -120,16 +120,22 @@ class YamlFile(LocalFile):
120
120
  @classmethod
121
121
  def load_from_disk(cls, paths: list[Path]) -> list[Self]:
122
122
  yaml_files: list[Self] = []
123
+ file_extensions = {".yaml", ".yml", ".json"} # FIXME: .json is not a YAML file, should be removed
124
+
123
125
  for file_path in paths:
124
- if file_path.is_file() and file_path.suffix in [".yaml", ".yml", ".json"]:
125
- yaml_files.extend(cls.load_file_from_disk(path=file_path))
126
+ if not file_path.exists():
127
+ # Check if the provided path exists, relevant for the first call coming from the user
128
+ raise FileNotValidError(name=str(file_path), message=f"{file_path} does not exist!")
129
+ if file_path.is_file():
130
+ if file_path.suffix in file_extensions:
131
+ yaml_files.extend(cls.load_file_from_disk(path=file_path))
132
+ # else: silently skip files with unrelevant extensions (e.g. .md, .py...)
126
133
  elif file_path.is_dir():
134
+ # Introduce recursion to handle sub-folders
127
135
  sub_paths = [Path(sub_file_path) for sub_file_path in file_path.glob("*")]
128
- sub_files = cls.load_from_disk(paths=sub_paths)
129
- sorted_sub_files = sorted(sub_files, key=lambda x: x.location)
130
- yaml_files.extend(sorted_sub_files)
131
- else:
132
- raise FileNotValidError(name=str(file_path), message=f"{file_path} does not exist!")
136
+ sub_paths = sorted(sub_paths, key=lambda p: p.name)
137
+ yaml_files.extend(cls.load_from_disk(paths=sub_paths))
138
+ # else: skip non-file, non-dir (e.g., symlink...)
133
139
 
134
140
  return yaml_files
135
141
 
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 OpsMill SAS
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: infrahub-server
3
- Version: 1.3.3
3
+ Version: 1.3.4
4
4
  Summary: Infrahub is taking a new approach to Infrastructure Management by providing a new generation of datastore to organize and control all the data that defines how an infrastructure should run.
5
- License: AGPL-3.0-only
5
+ License: Apache-2.0
6
6
  Author: OpsMill
7
7
  Author-email: info@opsmill.com
8
8
  Requires-Python: >=3.10,<3.13
9
9
  Classifier: Intended Audience :: Developers
10
- Classifier: License :: OSI Approved :: GNU Affero General Public License v3
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11