infrahub-server 1.3.8__py3-none-any.whl → 1.4.0__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 (172) hide show
  1. infrahub/api/internal.py +5 -0
  2. infrahub/artifacts/tasks.py +17 -22
  3. infrahub/branch/merge_mutation_checker.py +38 -0
  4. infrahub/cli/__init__.py +2 -2
  5. infrahub/cli/context.py +7 -3
  6. infrahub/cli/db.py +5 -16
  7. infrahub/cli/upgrade.py +10 -29
  8. infrahub/computed_attribute/tasks.py +36 -46
  9. infrahub/config.py +57 -6
  10. infrahub/constants/environment.py +1 -0
  11. infrahub/core/attribute.py +15 -7
  12. infrahub/core/branch/tasks.py +43 -41
  13. infrahub/core/constants/__init__.py +21 -6
  14. infrahub/core/constants/infrahubkind.py +2 -0
  15. infrahub/core/diff/coordinator.py +3 -1
  16. infrahub/core/diff/repository/repository.py +0 -8
  17. infrahub/core/diff/tasks.py +11 -8
  18. infrahub/core/graph/__init__.py +1 -1
  19. infrahub/core/graph/index.py +1 -2
  20. infrahub/core/graph/schema.py +50 -29
  21. infrahub/core/initialization.py +81 -47
  22. infrahub/core/ipam/tasks.py +4 -3
  23. infrahub/core/merge.py +8 -10
  24. infrahub/core/migrations/__init__.py +2 -0
  25. infrahub/core/migrations/graph/__init__.py +4 -0
  26. infrahub/core/migrations/graph/m036_drop_attr_value_index.py +45 -0
  27. infrahub/core/migrations/graph/m037_index_attr_vals.py +577 -0
  28. infrahub/core/migrations/query/attribute_add.py +27 -2
  29. infrahub/core/migrations/schema/attribute_kind_update.py +156 -0
  30. infrahub/core/migrations/schema/tasks.py +6 -5
  31. infrahub/core/models.py +5 -1
  32. infrahub/core/node/proposed_change.py +43 -0
  33. infrahub/core/protocols.py +12 -0
  34. infrahub/core/query/attribute.py +32 -14
  35. infrahub/core/query/diff.py +11 -0
  36. infrahub/core/query/ipam.py +13 -7
  37. infrahub/core/query/node.py +51 -10
  38. infrahub/core/query/resource_manager.py +3 -3
  39. infrahub/core/schema/basenode_schema.py +8 -0
  40. infrahub/core/schema/definitions/core/__init__.py +10 -1
  41. infrahub/core/schema/definitions/core/ipam.py +28 -2
  42. infrahub/core/schema/definitions/core/propose_change.py +15 -0
  43. infrahub/core/schema/definitions/core/webhook.py +3 -0
  44. infrahub/core/schema/definitions/internal.py +1 -1
  45. infrahub/core/schema/generated/attribute_schema.py +1 -1
  46. infrahub/core/schema/generic_schema.py +10 -0
  47. infrahub/core/schema/manager.py +10 -1
  48. infrahub/core/schema/node_schema.py +22 -17
  49. infrahub/core/schema/profile_schema.py +8 -0
  50. infrahub/core/schema/schema_branch.py +9 -5
  51. infrahub/core/schema/template_schema.py +8 -0
  52. infrahub/core/validators/attribute/kind.py +5 -1
  53. infrahub/core/validators/checks_runner.py +5 -5
  54. infrahub/core/validators/determiner.py +22 -2
  55. infrahub/core/validators/tasks.py +6 -7
  56. infrahub/core/validators/uniqueness/checker.py +4 -2
  57. infrahub/core/validators/uniqueness/model.py +1 -0
  58. infrahub/core/validators/uniqueness/query.py +57 -7
  59. infrahub/database/__init__.py +2 -1
  60. infrahub/events/__init__.py +20 -0
  61. infrahub/events/constants.py +7 -0
  62. infrahub/events/generator.py +29 -2
  63. infrahub/events/proposed_change_action.py +203 -0
  64. infrahub/generators/tasks.py +24 -20
  65. infrahub/git/base.py +4 -7
  66. infrahub/git/integrator.py +21 -12
  67. infrahub/git/repository.py +15 -30
  68. infrahub/git/tasks.py +121 -106
  69. infrahub/graphql/field_extractor.py +69 -0
  70. infrahub/graphql/manager.py +15 -11
  71. infrahub/graphql/mutations/account.py +2 -2
  72. infrahub/graphql/mutations/action.py +8 -2
  73. infrahub/graphql/mutations/artifact_definition.py +4 -1
  74. infrahub/graphql/mutations/branch.py +10 -5
  75. infrahub/graphql/mutations/graphql_query.py +2 -1
  76. infrahub/graphql/mutations/main.py +14 -8
  77. infrahub/graphql/mutations/menu.py +2 -1
  78. infrahub/graphql/mutations/proposed_change.py +230 -8
  79. infrahub/graphql/mutations/relationship.py +5 -0
  80. infrahub/graphql/mutations/repository.py +2 -1
  81. infrahub/graphql/mutations/tasks.py +7 -9
  82. infrahub/graphql/mutations/webhook.py +4 -1
  83. infrahub/graphql/parser.py +15 -6
  84. infrahub/graphql/queries/__init__.py +10 -1
  85. infrahub/graphql/queries/account.py +3 -3
  86. infrahub/graphql/queries/branch.py +2 -2
  87. infrahub/graphql/queries/diff/tree.py +3 -3
  88. infrahub/graphql/queries/event.py +13 -3
  89. infrahub/graphql/queries/ipam.py +23 -1
  90. infrahub/graphql/queries/proposed_change.py +84 -0
  91. infrahub/graphql/queries/relationship.py +2 -2
  92. infrahub/graphql/queries/resource_manager.py +3 -3
  93. infrahub/graphql/queries/search.py +3 -2
  94. infrahub/graphql/queries/status.py +3 -2
  95. infrahub/graphql/queries/task.py +2 -2
  96. infrahub/graphql/resolvers/ipam.py +440 -0
  97. infrahub/graphql/resolvers/many_relationship.py +4 -3
  98. infrahub/graphql/resolvers/resolver.py +5 -5
  99. infrahub/graphql/resolvers/single_relationship.py +3 -2
  100. infrahub/graphql/schema.py +25 -5
  101. infrahub/graphql/types/__init__.py +2 -2
  102. infrahub/graphql/types/attribute.py +3 -3
  103. infrahub/graphql/types/event.py +68 -0
  104. infrahub/groups/tasks.py +6 -6
  105. infrahub/lock.py +3 -2
  106. infrahub/menu/generator.py +8 -0
  107. infrahub/message_bus/operations/__init__.py +9 -12
  108. infrahub/message_bus/operations/git/file.py +6 -5
  109. infrahub/message_bus/operations/git/repository.py +12 -20
  110. infrahub/message_bus/operations/refresh/registry.py +15 -9
  111. infrahub/message_bus/operations/send/echo.py +7 -4
  112. infrahub/message_bus/types.py +1 -0
  113. infrahub/permissions/__init__.py +2 -1
  114. infrahub/permissions/constants.py +13 -0
  115. infrahub/permissions/globals.py +31 -2
  116. infrahub/permissions/manager.py +8 -5
  117. infrahub/pools/prefix.py +7 -5
  118. infrahub/prefect_server/app.py +31 -0
  119. infrahub/prefect_server/bootstrap.py +18 -0
  120. infrahub/proposed_change/action_checker.py +206 -0
  121. infrahub/proposed_change/approval_revoker.py +40 -0
  122. infrahub/proposed_change/branch_diff.py +3 -1
  123. infrahub/proposed_change/checker.py +45 -0
  124. infrahub/proposed_change/constants.py +32 -2
  125. infrahub/proposed_change/tasks.py +182 -150
  126. infrahub/py.typed +0 -0
  127. infrahub/server.py +29 -17
  128. infrahub/services/__init__.py +13 -28
  129. infrahub/services/adapters/cache/__init__.py +4 -0
  130. infrahub/services/adapters/cache/nats.py +2 -0
  131. infrahub/services/adapters/cache/redis.py +3 -0
  132. infrahub/services/adapters/message_bus/__init__.py +0 -2
  133. infrahub/services/adapters/message_bus/local.py +1 -2
  134. infrahub/services/adapters/message_bus/nats.py +6 -8
  135. infrahub/services/adapters/message_bus/rabbitmq.py +7 -9
  136. infrahub/services/adapters/workflow/__init__.py +1 -0
  137. infrahub/services/adapters/workflow/local.py +1 -8
  138. infrahub/services/component.py +2 -1
  139. infrahub/task_manager/event.py +56 -0
  140. infrahub/task_manager/models.py +9 -0
  141. infrahub/tasks/artifact.py +6 -7
  142. infrahub/tasks/check.py +4 -7
  143. infrahub/telemetry/tasks.py +15 -18
  144. infrahub/transformations/tasks.py +10 -6
  145. infrahub/trigger/tasks.py +4 -3
  146. infrahub/types.py +4 -0
  147. infrahub/validators/events.py +7 -7
  148. infrahub/validators/tasks.py +6 -7
  149. infrahub/webhook/models.py +45 -45
  150. infrahub/webhook/tasks.py +25 -24
  151. infrahub/workers/dependencies.py +143 -0
  152. infrahub/workers/infrahub_async.py +19 -43
  153. infrahub/workflows/catalogue.py +16 -2
  154. infrahub/workflows/initialization.py +5 -4
  155. infrahub/workflows/models.py +2 -0
  156. infrahub_sdk/client.py +2 -2
  157. infrahub_sdk/ctl/repository.py +51 -0
  158. infrahub_sdk/ctl/schema.py +9 -9
  159. infrahub_sdk/node/node.py +2 -2
  160. infrahub_sdk/pytest_plugin/items/graphql_query.py +1 -1
  161. infrahub_sdk/schema/repository.py +1 -1
  162. infrahub_sdk/testing/docker.py +1 -1
  163. infrahub_sdk/utils.py +2 -2
  164. {infrahub_server-1.3.8.dist-info → infrahub_server-1.4.0.dist-info}/METADATA +7 -5
  165. {infrahub_server-1.3.8.dist-info → infrahub_server-1.4.0.dist-info}/RECORD +172 -156
  166. infrahub_testcontainers/container.py +17 -0
  167. infrahub_testcontainers/docker-compose-cluster.test.yml +56 -1
  168. infrahub_testcontainers/docker-compose.test.yml +56 -1
  169. infrahub_testcontainers/helpers.py +4 -1
  170. {infrahub_server-1.3.8.dist-info → infrahub_server-1.4.0.dist-info}/LICENSE.txt +0 -0
  171. {infrahub_server-1.3.8.dist-info → infrahub_server-1.4.0.dist-info}/WHEEL +0 -0
  172. {infrahub_server-1.3.8.dist-info → infrahub_server-1.4.0.dist-info}/entry_points.txt +0 -0
@@ -50,6 +50,7 @@ from infrahub.events.repository_action import CommitUpdatedEvent
50
50
  from infrahub.exceptions import CheckError, RepositoryInvalidFileSystemError, TransformError
51
51
  from infrahub.git.base import InfrahubRepositoryBase, extract_repo_file_information
52
52
  from infrahub.log import get_logger
53
+ from infrahub.workers.dependencies import get_event_service
53
54
  from infrahub.workflows.utils import add_tags
54
55
 
55
56
  if TYPE_CHECKING:
@@ -62,7 +63,6 @@ if TYPE_CHECKING:
62
63
 
63
64
  from infrahub.artifacts.models import CheckArtifactCreate
64
65
  from infrahub.git.models import RequestArtifactGenerate
65
- from infrahub.services import InfrahubServices
66
66
 
67
67
 
68
68
  class ArtifactGenerateResult(BaseModel):
@@ -141,8 +141,8 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
141
141
  """
142
142
 
143
143
  @classmethod
144
- async def init(cls, service: InfrahubServices, commit: str | None = None, **kwargs: Any) -> Self:
145
- self = cls(service=service, **kwargs)
144
+ async def init(cls, commit: str | None = None, **kwargs: Any) -> Self:
145
+ self = cls(**kwargs)
146
146
  log = get_logger()
147
147
  try:
148
148
  self.validate_local_directories()
@@ -216,7 +216,8 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
216
216
  raise error
217
217
 
218
218
  infrahub_branch = registry.get_branch_from_registry(branch=infrahub_branch_name)
219
- await self.service.event.send(
219
+ event_service = await get_event_service()
220
+ await event_service.send(
220
221
  CommitUpdatedEvent(
221
222
  commit=commit,
222
223
  repository_name=self.name,
@@ -436,10 +437,18 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
436
437
  branch_wt = self.get_worktree(identifier=commit or branch_name)
437
438
  log = get_run_logger()
438
439
 
439
- config_file_name = ".infrahub.yml"
440
- config_file = branch_wt.directory / config_file_name
441
- if not config_file.is_file():
442
- log.debug(f"Unable to find the configuration file {config_file_name}, skipping")
440
+ # Check for both .infrahub.yml and .infrahub.yaml, prefer .yml if both exist
441
+ config_file_yml = branch_wt.directory / ".infrahub.yml"
442
+ config_file_yaml = branch_wt.directory / ".infrahub.yaml"
443
+
444
+ if config_file_yml.is_file():
445
+ config_file = config_file_yml
446
+ config_file_name = ".infrahub.yml"
447
+ elif config_file_yaml.is_file():
448
+ config_file = config_file_yaml
449
+ config_file_name = ".infrahub.yaml"
450
+ else:
451
+ log.debug("Unable to find the configuration file (.infrahub.yml or .infrahub.yaml), skipping")
443
452
  return None
444
453
 
445
454
  config_file_content = config_file.read_text(encoding="utf-8")
@@ -1264,7 +1273,6 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
1264
1273
  infrahub_node=InfrahubNode,
1265
1274
  )
1266
1275
  return await transform.run(data=data)
1267
-
1268
1276
  except ModuleNotFoundError as exc:
1269
1277
  error_msg = f"Unable to load the transform file {location}"
1270
1278
  log.error(error_msg)
@@ -1314,11 +1322,11 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
1314
1322
  artifact_content = await self.execute_python_transform.with_options(
1315
1323
  timeout_seconds=transformation.timeout.value
1316
1324
  )(
1325
+ client=self.sdk,
1317
1326
  branch_name=branch_name,
1318
1327
  commit=commit,
1319
1328
  location=transformation_location,
1320
1329
  data=response,
1321
- client=self.sdk,
1322
1330
  convert_query_response=transformation.convert_query_response.value,
1323
1331
  ) # type: ignore[misc]
1324
1332
 
@@ -1374,11 +1382,11 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
1374
1382
  ) # type: ignore[misc]
1375
1383
  elif message.transform_type == InfrahubKind.TRANSFORMPYTHON:
1376
1384
  artifact_content = await self.execute_python_transform.with_options(timeout_seconds=message.timeout)(
1385
+ client=self.sdk,
1377
1386
  branch_name=message.branch_name,
1378
1387
  commit=message.commit,
1379
1388
  location=message.transform_location,
1380
1389
  data=response,
1381
- client=self.sdk,
1382
1390
  convert_query_response=message.convert_query_response,
1383
1391
  ) # type: ignore[misc]
1384
1392
 
@@ -1421,7 +1429,8 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
1421
1429
  storage_id_previous=previous_storage_id,
1422
1430
  )
1423
1431
 
1424
- await self.service.event.send(event=event)
1432
+ event_service = await get_event_service()
1433
+ await event_service.send(event=event)
1425
1434
  return ArtifactGenerateResult(changed=True, checksum=checksum, storage_id=storage_id, artifact_id=artifact.id)
1426
1435
 
1427
1436
 
@@ -4,6 +4,8 @@ from typing import TYPE_CHECKING, Any
4
4
 
5
5
  from git.exc import BadName, GitCommandError
6
6
  from infrahub_sdk.exceptions import GraphQLError
7
+ from prefect import task
8
+ from prefect.cache_policies import NONE
7
9
  from pydantic import Field
8
10
 
9
11
  from infrahub.core.constants import InfrahubKind, RepositoryInternalStatus
@@ -12,7 +14,7 @@ from infrahub.git.integrator import InfrahubRepositoryIntegrator
12
14
  from infrahub.log import get_logger
13
15
 
14
16
  if TYPE_CHECKING:
15
- from infrahub.services import InfrahubServices
17
+ from infrahub_sdk.client import InfrahubClient
16
18
 
17
19
  log = get_logger()
18
20
 
@@ -25,10 +27,8 @@ class InfrahubRepository(InfrahubRepositoryIntegrator):
25
27
  """
26
28
 
27
29
  @classmethod
28
- async def new(
29
- cls, service: InfrahubServices, update_commit_value: bool = True, **kwargs: Any
30
- ) -> InfrahubRepository:
31
- self = cls(service=service, **kwargs)
30
+ async def new(cls, update_commit_value: bool = True, **kwargs: Any) -> InfrahubRepository:
31
+ self = cls(**kwargs)
32
32
  await self.create_locally(
33
33
  infrahub_branch_name=self.infrahub_branch_name, update_commit_value=update_commit_value
34
34
  )
@@ -209,11 +209,11 @@ class InfrahubReadOnlyRepository(InfrahubRepositoryIntegrator):
209
209
  ref: str | None = Field(None, description="Ref to track on the external repository")
210
210
 
211
211
  @classmethod
212
- async def new(cls, service: InfrahubServices, **kwargs: Any) -> InfrahubReadOnlyRepository:
212
+ async def new(cls, **kwargs: Any) -> InfrahubReadOnlyRepository:
213
213
  if "ref" not in kwargs or "infrahub_branch_name" not in kwargs:
214
214
  raise ValueError("ref and infrahub_branch_name are mandatory to initialize a new Read-Only repository")
215
215
 
216
- self = cls(service=service, **kwargs)
216
+ self = cls(**kwargs)
217
217
  await self.create_locally(checkout_ref=self.ref, infrahub_branch_name=self.infrahub_branch_name)
218
218
  log.info("Created new repository locally.", repository=self.name)
219
219
  return self
@@ -248,33 +248,18 @@ class InfrahubReadOnlyRepository(InfrahubRepositoryIntegrator):
248
248
  await self.update_commit_value(branch_name=self.infrahub_branch_name, commit=commit)
249
249
 
250
250
 
251
+ @task(
252
+ name="Fetch repository commit",
253
+ description="Retrieve a git repository at a given commit, if it does not already exist locally",
254
+ cache_policy=NONE,
255
+ )
251
256
  async def get_initialized_repo(
252
- repository_id: str, name: str, service: InfrahubServices, repository_kind: str, commit: str | None = None
257
+ client: InfrahubClient, repository_id: str, name: str, repository_kind: str, commit: str | None = None
253
258
  ) -> InfrahubReadOnlyRepository | InfrahubRepository:
254
259
  if repository_kind == InfrahubKind.REPOSITORY:
255
- return await InfrahubRepository.init(
256
- id=repository_id, name=name, commit=commit, client=service._client, service=service
257
- )
258
-
259
- if repository_kind == InfrahubKind.READONLYREPOSITORY:
260
- return await InfrahubReadOnlyRepository.init(
261
- id=repository_id, name=name, commit=commit, client=service._client, service=service
262
- )
263
-
264
- raise NotImplementedError(f"The repository kind {repository_kind} has not been implemented")
265
-
266
-
267
- async def initialize_repo(
268
- location: str, repository_id: str, name: str, service: InfrahubServices, repository_kind: str
269
- ) -> InfrahubReadOnlyRepository | InfrahubRepository:
270
- if repository_kind == InfrahubKind.REPOSITORY:
271
- return await InfrahubRepository.new(
272
- location=location, id=repository_id, name=name, client=service._client, service=service
273
- )
260
+ return await InfrahubRepository.init(id=repository_id, name=name, commit=commit, client=client)
274
261
 
275
262
  if repository_kind == InfrahubKind.READONLYREPOSITORY:
276
- return await InfrahubReadOnlyRepository.new(
277
- location=location, id=repository_id, name=name, client=service._client, service=service
278
- )
263
+ return await InfrahubReadOnlyRepository.init(id=repository_id, name=name, commit=commit, client=client)
279
264
 
280
265
  raise NotImplementedError(f"The repository kind {repository_kind} has not been implemented")