infrahub-server 1.6.0b0__py3-none-any.whl → 1.6.1__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 (88) hide show
  1. infrahub/api/oauth2.py +33 -6
  2. infrahub/api/oidc.py +36 -6
  3. infrahub/auth.py +11 -0
  4. infrahub/auth_pkce.py +41 -0
  5. infrahub/config.py +9 -3
  6. infrahub/core/branch/models.py +3 -2
  7. infrahub/core/changelog/models.py +2 -2
  8. infrahub/core/constants/__init__.py +1 -0
  9. infrahub/core/graph/__init__.py +1 -1
  10. infrahub/core/integrity/object_conflict/conflict_recorder.py +1 -1
  11. infrahub/core/manager.py +36 -31
  12. infrahub/core/migrations/graph/__init__.py +2 -0
  13. infrahub/core/migrations/graph/m047_backfill_or_null_display_label.py +606 -0
  14. infrahub/core/models.py +5 -6
  15. infrahub/core/node/__init__.py +16 -13
  16. infrahub/core/node/create.py +36 -8
  17. infrahub/core/node/proposed_change.py +5 -3
  18. infrahub/core/node/standard.py +1 -1
  19. infrahub/core/protocols.py +1 -7
  20. infrahub/core/query/attribute.py +1 -1
  21. infrahub/core/query/node.py +9 -5
  22. infrahub/core/relationship/model.py +21 -4
  23. infrahub/core/schema/generic_schema.py +1 -1
  24. infrahub/core/schema/manager.py +8 -3
  25. infrahub/core/schema/schema_branch.py +35 -16
  26. infrahub/core/validators/attribute/choices.py +2 -2
  27. infrahub/core/validators/determiner.py +3 -6
  28. infrahub/database/__init__.py +1 -1
  29. infrahub/git/base.py +2 -3
  30. infrahub/git/models.py +13 -0
  31. infrahub/git/tasks.py +23 -19
  32. infrahub/git/utils.py +16 -9
  33. infrahub/graphql/app.py +6 -6
  34. infrahub/graphql/loaders/peers.py +6 -0
  35. infrahub/graphql/mutations/action.py +15 -7
  36. infrahub/graphql/mutations/hfid.py +1 -1
  37. infrahub/graphql/mutations/profile.py +8 -1
  38. infrahub/graphql/mutations/repository.py +3 -3
  39. infrahub/graphql/mutations/schema.py +4 -4
  40. infrahub/graphql/mutations/webhook.py +2 -2
  41. infrahub/graphql/queries/resource_manager.py +2 -3
  42. infrahub/graphql/queries/search.py +2 -3
  43. infrahub/graphql/resolvers/ipam.py +20 -0
  44. infrahub/graphql/resolvers/many_relationship.py +12 -11
  45. infrahub/graphql/resolvers/resolver.py +6 -2
  46. infrahub/graphql/resolvers/single_relationship.py +1 -11
  47. infrahub/log.py +1 -1
  48. infrahub/message_bus/messages/__init__.py +0 -12
  49. infrahub/profiles/node_applier.py +9 -0
  50. infrahub/proposed_change/branch_diff.py +1 -1
  51. infrahub/proposed_change/tasks.py +1 -1
  52. infrahub/repositories/create_repository.py +3 -3
  53. infrahub/task_manager/models.py +1 -1
  54. infrahub/task_manager/task.py +5 -5
  55. infrahub/trigger/setup.py +6 -9
  56. infrahub/utils.py +18 -0
  57. infrahub/validators/tasks.py +1 -1
  58. infrahub/workers/infrahub_async.py +7 -6
  59. infrahub_sdk/client.py +113 -1
  60. infrahub_sdk/ctl/AGENTS.md +67 -0
  61. infrahub_sdk/ctl/branch.py +175 -1
  62. infrahub_sdk/ctl/check.py +3 -3
  63. infrahub_sdk/ctl/cli_commands.py +9 -9
  64. infrahub_sdk/ctl/generator.py +2 -2
  65. infrahub_sdk/ctl/graphql.py +1 -2
  66. infrahub_sdk/ctl/importer.py +1 -2
  67. infrahub_sdk/ctl/repository.py +6 -49
  68. infrahub_sdk/ctl/task.py +2 -4
  69. infrahub_sdk/ctl/utils.py +2 -2
  70. infrahub_sdk/ctl/validate.py +1 -2
  71. infrahub_sdk/diff.py +80 -3
  72. infrahub_sdk/graphql/constants.py +14 -1
  73. infrahub_sdk/graphql/renderers.py +5 -1
  74. infrahub_sdk/node/attribute.py +0 -1
  75. infrahub_sdk/node/constants.py +3 -1
  76. infrahub_sdk/node/node.py +303 -3
  77. infrahub_sdk/node/related_node.py +1 -2
  78. infrahub_sdk/node/relationship.py +1 -2
  79. infrahub_sdk/protocols_base.py +0 -1
  80. infrahub_sdk/pytest_plugin/AGENTS.md +67 -0
  81. infrahub_sdk/schema/__init__.py +0 -3
  82. infrahub_sdk/timestamp.py +7 -7
  83. {infrahub_server-1.6.0b0.dist-info → infrahub_server-1.6.1.dist-info}/METADATA +2 -3
  84. {infrahub_server-1.6.0b0.dist-info → infrahub_server-1.6.1.dist-info}/RECORD +88 -84
  85. {infrahub_server-1.6.0b0.dist-info → infrahub_server-1.6.1.dist-info}/WHEEL +1 -1
  86. infrahub_testcontainers/container.py +2 -2
  87. {infrahub_server-1.6.0b0.dist-info → infrahub_server-1.6.1.dist-info}/entry_points.txt +0 -0
  88. {infrahub_server-1.6.0b0.dist-info → infrahub_server-1.6.1.dist-info}/licenses/LICENSE.txt +0 -0
@@ -8,7 +8,7 @@ import platform
8
8
  import sys
9
9
  from collections.abc import Callable
10
10
  from pathlib import Path
11
- from typing import TYPE_CHECKING, Any, Optional
11
+ from typing import TYPE_CHECKING, Any
12
12
 
13
13
  import typer
14
14
  import ujson
@@ -78,13 +78,13 @@ console = Console()
78
78
  @catch_exception(console=console)
79
79
  def check(
80
80
  check_name: str = typer.Argument(default="", help="Name of the Python check"),
81
- branch: Optional[str] = None,
81
+ branch: str | None = None,
82
82
  path: str = typer.Option(".", help="Root directory"),
83
83
  debug: bool = False,
84
84
  format_json: bool = False,
85
85
  _: str = CONFIG_PARAM,
86
86
  list_available: bool = typer.Option(False, "--list", help="Show available Python checks"),
87
- variables: Optional[list[str]] = typer.Argument(
87
+ variables: list[str] | None = typer.Argument(
88
88
  None, help="Variables to pass along with the query. Format key=value key=value."
89
89
  ),
90
90
  ) -> None:
@@ -106,12 +106,12 @@ def check(
106
106
  @catch_exception(console=console)
107
107
  async def generator(
108
108
  generator_name: str = typer.Argument(default="", help="Name of the Generator"),
109
- branch: Optional[str] = None,
109
+ branch: str | None = None,
110
110
  path: str = typer.Option(".", help="Root directory"),
111
111
  debug: bool = False,
112
112
  _: str = CONFIG_PARAM,
113
113
  list_available: bool = typer.Option(False, "--list", help="Show available Generators"),
114
- variables: Optional[list[str]] = typer.Argument(
114
+ variables: list[str] | None = typer.Argument(
115
115
  None, help="Variables to pass along with the query. Format key=value key=value."
116
116
  ),
117
117
  ) -> None:
@@ -134,13 +134,13 @@ async def run(
134
134
  debug: bool = False,
135
135
  _: str = CONFIG_PARAM,
136
136
  branch: str = typer.Option(None, help="Branch on which to run the script."),
137
- concurrent: Optional[int] = typer.Option(
137
+ concurrent: int | None = typer.Option(
138
138
  None,
139
139
  help="Maximum number of requests to execute at the same time.",
140
140
  envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",
141
141
  ),
142
142
  timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUB_TIMEOUT"),
143
- variables: Optional[list[str]] = typer.Argument(
143
+ variables: list[str] | None = typer.Argument(
144
144
  None, help="Variables to pass along with the query. Format key=value key=value."
145
145
  ),
146
146
  ) -> None:
@@ -251,7 +251,7 @@ async def _run_transform(
251
251
  @catch_exception(console=console)
252
252
  async def render(
253
253
  transform_name: str = typer.Argument(default="", help="Name of the Python transformation", show_default=False),
254
- variables: Optional[list[str]] = typer.Argument(
254
+ variables: list[str] | None = typer.Argument(
255
255
  None, help="Variables to pass along with the query. Format key=value key=value."
256
256
  ),
257
257
  branch: str = typer.Option(None, help="Branch on which to render the transform."),
@@ -301,7 +301,7 @@ async def render(
301
301
  @catch_exception(console=console)
302
302
  def transform(
303
303
  transform_name: str = typer.Argument(default="", help="Name of the Python transformation", show_default=False),
304
- variables: Optional[list[str]] = typer.Argument(
304
+ variables: list[str] | None = typer.Argument(
305
305
  None, help="Variables to pass along with the query. Format key=value key=value."
306
306
  ),
307
307
  branch: str = typer.Option(None, help="Branch on which to run the transformation"),
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from pathlib import Path
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  import typer
7
7
  from rich.console import Console
@@ -22,7 +22,7 @@ async def run(
22
22
  debug: bool,
23
23
  list_available: bool,
24
24
  branch: str | None = None,
25
- variables: Optional[list[str]] = None,
25
+ variables: list[str] | None = None,
26
26
  ) -> None:
27
27
  init_logging(debug=debug)
28
28
  repository_config = get_repository_config(find_repository_config_file())
@@ -3,7 +3,6 @@ from __future__ import annotations
3
3
  import ast
4
4
  from collections import defaultdict
5
5
  from pathlib import Path
6
- from typing import Optional
7
6
 
8
7
  import typer
9
8
  from ariadne_codegen.client_generators.package import PackageGenerator, get_package_generator
@@ -115,7 +114,7 @@ async def export_schema(
115
114
  @app.command()
116
115
  @catch_exception(console=console)
117
116
  async def generate_return_types(
118
- query: Optional[Path] = typer.Argument(
117
+ query: Path | None = typer.Argument(
119
118
  None, help="Location of the GraphQL query file(s). Defaults to current directory if not specified."
120
119
  ),
121
120
  schema: Path = typer.Option("schema.graphql", help="Path to the GraphQL schema file."),
@@ -2,7 +2,6 @@ from __future__ import annotations
2
2
 
3
3
  from asyncio import run as aiorun
4
4
  from pathlib import Path
5
- from typing import Optional
6
5
 
7
6
  import typer
8
7
  from rich.console import Console
@@ -27,7 +26,7 @@ def load(
27
26
  quiet: bool = typer.Option(False, help="No console output"),
28
27
  _: str = CONFIG_PARAM,
29
28
  branch: str = typer.Option(None, help="Branch from which to export"),
30
- concurrent: Optional[int] = typer.Option(
29
+ concurrent: int | None = typer.Option(
31
30
  None,
32
31
  help="Maximum number of requests to execute at the same time.",
33
32
  envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",
@@ -1,12 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
- import asyncio
4
3
  from pathlib import Path
5
- from typing import Optional
6
4
 
7
5
  import typer
8
6
  import yaml
9
- from copier import run_copy
10
7
  from pydantic import ValidationError
11
8
  from rich.console import Console
12
9
  from rich.table import Table
@@ -109,7 +106,7 @@ async def add(
109
106
  name: str,
110
107
  location: str,
111
108
  description: str = "",
112
- username: Optional[str] = None,
109
+ username: str | None = None,
113
110
  password: str = "",
114
111
  ref: str = "",
115
112
  read_only: bool = False,
@@ -155,7 +152,7 @@ async def add(
155
152
 
156
153
  @app.command()
157
154
  async def list(
158
- branch: Optional[str] = typer.Option(None, help="Branch on which to list repositories."),
155
+ branch: str | None = typer.Option(None, help="Branch on which to list repositories."),
159
156
  debug: bool = False,
160
157
  _: str = CONFIG_PARAM,
161
158
  ) -> None:
@@ -208,49 +205,9 @@ async def list(
208
205
 
209
206
 
210
207
  @app.command()
211
- async def init(
212
- directory: Path = typer.Argument(help="Directory path for the new project."),
213
- template: str = typer.Option(
214
- default="https://github.com/opsmill/infrahub-template.git",
215
- help="Template to use for the new repository. Can be a local path or a git repository URL.",
216
- ),
217
- data: Optional[Path] = typer.Option(default=None, help="Path to YAML file containing answers to CLI prompt."),
218
- vcs_ref: Optional[str] = typer.Option(
219
- default="HEAD",
220
- help="VCS reference to use for the template. Defaults to HEAD.",
221
- ),
222
- trust: Optional[bool] = typer.Option(
223
- default=False,
224
- help="Trust the template repository. If set, the template will be cloned without verification.",
225
- ),
226
- _: str = CONFIG_PARAM,
227
- ) -> None:
208
+ async def init() -> None:
228
209
  """Initialize a new Infrahub repository."""
229
210
 
230
- config_data = None
231
- if data:
232
- try:
233
- with Path.open(data, encoding="utf-8") as file:
234
- config_data = yaml.safe_load(file)
235
- typer.echo(f"Loaded config: {config_data}")
236
- except Exception as exc:
237
- typer.echo(f"Error loading YAML file: {exc}", err=True)
238
- raise typer.Exit(code=1)
239
-
240
- # Allow template to be a local path or a URL
241
- template_source = template or ""
242
- if template and Path(template).exists():
243
- template_source = str(Path(template).resolve())
244
-
245
- try:
246
- await asyncio.to_thread(
247
- run_copy,
248
- template_source,
249
- str(directory),
250
- data=config_data,
251
- vcs_ref=vcs_ref,
252
- unsafe=trust,
253
- )
254
- except Exception as e:
255
- typer.echo(f"Error running copier: {e}", err=True)
256
- raise typer.Exit(code=1)
211
+ console.print("The copier tool is not included in the Infrahub SDK CLI due to license restrictions,")
212
+ console.print("please run the following command to create a new Infrahub repository project:\n")
213
+ console.print("uv tool run --from 'copier' copier copy https://github.com/opsmill/infrahub-template <project-name>")
infrahub_sdk/ctl/task.py CHANGED
@@ -1,7 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Optional
4
-
5
3
  import typer
6
4
  from rich.console import Console
7
5
  from rich.table import Table
@@ -75,8 +73,8 @@ async def list_tasks(
75
73
  state: list[str] = typer.Option(
76
74
  None, "--state", "-s", help="Filter by task state. Can be provided multiple times."
77
75
  ),
78
- limit: Optional[int] = typer.Option(None, help="Maximum number of tasks to retrieve."),
79
- offset: Optional[int] = typer.Option(None, help="Offset for pagination."),
76
+ limit: int | None = typer.Option(None, help="Maximum number of tasks to retrieve."),
77
+ offset: int | None = typer.Option(None, help="Offset for pagination."),
80
78
  include_related_nodes: bool = typer.Option(False, help="Include related nodes in the output."),
81
79
  include_logs: bool = typer.Option(False, help="Include task logs in the output."),
82
80
  json_output: bool = typer.Option(False, "--json", help="Output the result as JSON."),
infrahub_sdk/ctl/utils.py CHANGED
@@ -6,7 +6,7 @@ import traceback
6
6
  from collections.abc import Callable, Coroutine
7
7
  from functools import wraps
8
8
  from pathlib import Path
9
- from typing import TYPE_CHECKING, Any, NoReturn, Optional, TypeVar
9
+ from typing import TYPE_CHECKING, Any, NoReturn, TypeVar
10
10
 
11
11
  import typer
12
12
  from click.exceptions import Exit
@@ -149,7 +149,7 @@ def print_graphql_errors(console: Console, errors: list) -> None:
149
149
  console.print(f"[red]{escape(str(error))}")
150
150
 
151
151
 
152
- def parse_cli_vars(variables: Optional[list[str]]) -> dict[str, str]:
152
+ def parse_cli_vars(variables: list[str] | None) -> dict[str, str]:
153
153
  if not variables:
154
154
  return {}
155
155
 
@@ -2,7 +2,6 @@ from __future__ import annotations
2
2
 
3
3
  import sys
4
4
  from pathlib import Path
5
- from typing import Optional
6
5
 
7
6
  import typer
8
7
  import ujson
@@ -58,7 +57,7 @@ async def validate_schema(schema: Path, _: str = CONFIG_PARAM) -> None:
58
57
  @catch_exception(console=console)
59
58
  def validate_graphql(
60
59
  query: str,
61
- variables: Optional[list[str]] = typer.Argument(
60
+ variables: list[str] | None = typer.Argument(
62
61
  None, help="Variables to pass along with the query. Format key=value key=value."
63
62
  ),
64
63
  debug: bool = typer.Option(False, help="Display more troubleshooting information."),
infrahub_sdk/diff.py CHANGED
@@ -1,11 +1,12 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import (
4
- Any,
5
- )
3
+ from datetime import datetime
4
+ from typing import Any
6
5
 
7
6
  from typing_extensions import NotRequired, TypedDict
8
7
 
8
+ from infrahub_sdk.graphql.query import Query
9
+
9
10
 
10
11
  class NodeDiff(TypedDict):
11
12
  branch: str
@@ -35,6 +36,19 @@ class NodeDiffPeer(TypedDict):
35
36
  summary: NodeDiffSummary
36
37
 
37
38
 
39
+ class DiffTreeData(TypedDict):
40
+ num_added: int
41
+ num_updated: int
42
+ num_removed: int
43
+ num_conflicts: int
44
+ to_time: str
45
+ from_time: str
46
+ base_branch: str
47
+ diff_branch: str
48
+ name: NotRequired[str | None]
49
+ nodes: list[NodeDiff]
50
+
51
+
38
52
  def get_diff_summary_query() -> str:
39
53
  return """
40
54
  query GetDiffTree($branch_name: String!, $name: String, $from_time: DateTime, $to_time: DateTime) {
@@ -125,3 +139,66 @@ def diff_tree_node_to_node_diff(node_dict: dict[str, Any], branch_name: str) ->
125
139
  display_label=str(node_dict.get("label")),
126
140
  elements=element_diffs,
127
141
  )
142
+
143
+
144
+ def get_diff_tree_query() -> Query:
145
+ node_structure = {
146
+ "uuid": None,
147
+ "kind": None,
148
+ "status": None,
149
+ "label": None,
150
+ "num_added": None,
151
+ "num_updated": None,
152
+ "num_removed": None,
153
+ "attributes": {
154
+ "name": None,
155
+ "status": None,
156
+ "num_added": None,
157
+ "num_updated": None,
158
+ "num_removed": None,
159
+ },
160
+ "relationships": {
161
+ "name": None,
162
+ "status": None,
163
+ "cardinality": None,
164
+ "num_added": None,
165
+ "num_updated": None,
166
+ "num_removed": None,
167
+ "elements": {
168
+ "status": None,
169
+ "num_added": None,
170
+ "num_updated": None,
171
+ "num_removed": None,
172
+ },
173
+ },
174
+ }
175
+
176
+ return Query(
177
+ name="GetDiffTree",
178
+ query={
179
+ "DiffTree": {
180
+ "@filters": {
181
+ "branch": "$branch_name",
182
+ "name": "$name",
183
+ "from_time": "$from_time",
184
+ "to_time": "$to_time",
185
+ },
186
+ "name": None,
187
+ "to_time": None,
188
+ "from_time": None,
189
+ "base_branch": None,
190
+ "diff_branch": None,
191
+ "num_added": None,
192
+ "num_updated": None,
193
+ "num_removed": None,
194
+ "num_conflicts": None,
195
+ "nodes": node_structure,
196
+ },
197
+ },
198
+ variables={
199
+ "branch_name": str,
200
+ "name": str | None,
201
+ "from_time": datetime | None,
202
+ "to_time": datetime | None,
203
+ },
204
+ )
@@ -1 +1,14 @@
1
- VARIABLE_TYPE_MAPPING = ((str, "String!"), (int, "Int!"), (float, "Float!"), (bool, "Boolean!"))
1
+ from datetime import datetime
2
+
3
+ VARIABLE_TYPE_MAPPING = (
4
+ (str, "String!"),
5
+ (str | None, "String"),
6
+ (int, "Int!"),
7
+ (int | None, "Int"),
8
+ (float, "Float!"),
9
+ (float | None, "Float"),
10
+ (bool, "Boolean!"),
11
+ (bool | None, "Boolean"),
12
+ (datetime, "DateTime!"),
13
+ (datetime | None, "DateTime"),
14
+ )
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ from datetime import datetime
4
5
  from enum import Enum
5
6
  from typing import Any
6
7
 
@@ -66,7 +67,10 @@ def convert_to_graphql_as_string(value: Any, convert_enum: bool = False) -> str:
66
67
  return str(value)
67
68
 
68
69
 
69
- def render_variables_to_string(data: dict[str, type[str | int | float | bool]]) -> str:
70
+ GRAPHQL_VARIABLE_TYPES = type[str | int | float | bool | datetime | None]
71
+
72
+
73
+ def render_variables_to_string(data: dict[str, GRAPHQL_VARIABLE_TYPES]) -> str:
70
74
  """Render a dict into a variable string that will be used in a GraphQL Query.
71
75
 
72
76
  The $ sign will be automatically added to the name of the query.
@@ -53,7 +53,6 @@ class Attribute:
53
53
  self.is_inherited: bool | None = data.get("is_inherited")
54
54
  self.updated_at: str | None = data.get("updated_at")
55
55
 
56
- self.is_visible: bool | None = data.get("is_visible")
57
56
  self.is_protected: bool | None = data.get("is_protected")
58
57
 
59
58
  self.source: NodeProperty | None = None
@@ -1,7 +1,7 @@
1
1
  import ipaddress
2
2
  import re
3
3
 
4
- PROPERTIES_FLAG = ["is_visible", "is_protected"]
4
+ PROPERTIES_FLAG = ["is_protected", "updated_at"]
5
5
  PROPERTIES_OBJECT = ["source", "owner"]
6
6
  SAFE_VALUE = re.compile(r"(^[\. /:a-zA-Z0-9_-]+$)|(^$)")
7
7
 
@@ -17,4 +17,6 @@ ARTIFACT_DEFINITION_GENERATE_FEATURE_NOT_SUPPORTED_MESSAGE = (
17
17
  "calling generate is only supported for CoreArtifactDefinition nodes"
18
18
  )
19
19
 
20
+ HIERARCHY_FETCH_FEATURE_NOT_SUPPORTED_MESSAGE = "Hierarchical fields are not supported for this node."
21
+
20
22
  HFID_STR_SEPARATOR = "__"