infrahub-server 1.2.0rc0__py3-none-any.whl → 1.2.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 (365) hide show
  1. infrahub/api/dependencies.py +6 -6
  2. infrahub/api/diff/validation_models.py +7 -7
  3. infrahub/api/schema.py +1 -1
  4. infrahub/artifacts/models.py +5 -3
  5. infrahub/artifacts/tasks.py +3 -5
  6. infrahub/cli/__init__.py +13 -9
  7. infrahub/cli/constants.py +3 -0
  8. infrahub/cli/db.py +165 -183
  9. infrahub/cli/upgrade.py +146 -0
  10. infrahub/computed_attribute/gather.py +185 -0
  11. infrahub/computed_attribute/models.py +240 -12
  12. infrahub/computed_attribute/tasks.py +77 -441
  13. infrahub/computed_attribute/triggers.py +13 -47
  14. infrahub/config.py +43 -32
  15. infrahub/context.py +14 -0
  16. infrahub/core/account.py +4 -4
  17. infrahub/core/attribute.py +58 -58
  18. infrahub/core/branch/tasks.py +74 -22
  19. infrahub/core/changelog/diff.py +95 -36
  20. infrahub/core/changelog/models.py +217 -43
  21. infrahub/core/constants/__init__.py +28 -0
  22. infrahub/core/constants/infrahubkind.py +2 -0
  23. infrahub/core/constants/schema.py +2 -0
  24. infrahub/core/constraint/node/runner.py +9 -8
  25. infrahub/core/diff/branch_differ.py +10 -10
  26. infrahub/core/diff/enricher/cardinality_one.py +5 -0
  27. infrahub/core/diff/enricher/hierarchy.py +17 -4
  28. infrahub/core/diff/enricher/labels.py +5 -0
  29. infrahub/core/diff/enricher/path_identifier.py +4 -0
  30. infrahub/core/diff/ipam_diff_parser.py +4 -5
  31. infrahub/core/diff/model/diff.py +27 -27
  32. infrahub/core/diff/model/path.py +32 -9
  33. infrahub/core/diff/parent_node_adder.py +78 -0
  34. infrahub/core/diff/payload_builder.py +13 -2
  35. infrahub/core/diff/query/filters.py +2 -2
  36. infrahub/core/diff/query/merge.py +20 -17
  37. infrahub/core/diff/query/save.py +188 -182
  38. infrahub/core/diff/query/summary_counts_enricher.py +51 -4
  39. infrahub/core/diff/query_parser.py +4 -4
  40. infrahub/core/diff/repository/deserializer.py +8 -3
  41. infrahub/core/diff/repository/repository.py +156 -38
  42. infrahub/core/diff/tasks.py +4 -4
  43. infrahub/core/graph/__init__.py +1 -1
  44. infrahub/core/graph/index.py +3 -0
  45. infrahub/core/initialization.py +1 -10
  46. infrahub/core/ipam/constants.py +3 -4
  47. infrahub/core/ipam/reconciler.py +12 -12
  48. infrahub/core/ipam/utilization.py +10 -13
  49. infrahub/core/manager.py +36 -36
  50. infrahub/core/merge.py +7 -7
  51. infrahub/core/migrations/__init__.py +2 -3
  52. infrahub/core/migrations/graph/__init__.py +12 -3
  53. infrahub/core/migrations/graph/m017_add_core_profile.py +1 -5
  54. infrahub/core/migrations/graph/m018_uniqueness_nulls.py +4 -4
  55. infrahub/core/migrations/graph/m019_restore_rels_to_time.py +256 -0
  56. infrahub/core/migrations/graph/m020_duplicate_edges.py +160 -0
  57. infrahub/core/migrations/graph/m021_missing_hierarchy_merge.py +51 -0
  58. infrahub/core/migrations/graph/m022_add_generate_template_attr.py +48 -0
  59. infrahub/core/migrations/graph/m023_deduplicate_cardinality_one_relationships.py +96 -0
  60. infrahub/core/migrations/query/attribute_add.py +2 -2
  61. infrahub/core/migrations/query/node_duplicate.py +43 -26
  62. infrahub/core/migrations/query/schema_attribute_update.py +2 -2
  63. infrahub/core/migrations/schema/models.py +19 -4
  64. infrahub/core/migrations/schema/node_remove.py +26 -12
  65. infrahub/core/migrations/schema/tasks.py +2 -2
  66. infrahub/core/migrations/shared.py +16 -16
  67. infrahub/core/models.py +15 -6
  68. infrahub/core/node/__init__.py +43 -39
  69. infrahub/core/node/base.py +2 -4
  70. infrahub/core/node/constraints/attribute_uniqueness.py +2 -2
  71. infrahub/core/node/constraints/grouped_uniqueness.py +99 -47
  72. infrahub/core/node/constraints/interface.py +1 -2
  73. infrahub/core/node/delete_validator.py +3 -5
  74. infrahub/core/node/ipam.py +4 -4
  75. infrahub/core/node/permissions.py +7 -7
  76. infrahub/core/node/resource_manager/ip_address_pool.py +6 -6
  77. infrahub/core/node/resource_manager/ip_prefix_pool.py +6 -6
  78. infrahub/core/node/resource_manager/number_pool.py +3 -3
  79. infrahub/core/path.py +12 -12
  80. infrahub/core/property.py +11 -11
  81. infrahub/core/protocols.py +7 -0
  82. infrahub/core/protocols_base.py +21 -21
  83. infrahub/core/query/__init__.py +33 -33
  84. infrahub/core/query/attribute.py +6 -4
  85. infrahub/core/query/diff.py +3 -3
  86. infrahub/core/query/node.py +82 -32
  87. infrahub/core/query/relationship.py +228 -40
  88. infrahub/core/query/resource_manager.py +2 -0
  89. infrahub/core/query/standard_node.py +3 -3
  90. infrahub/core/query/subquery.py +9 -9
  91. infrahub/core/registry.py +13 -15
  92. infrahub/core/relationship/constraints/count.py +3 -4
  93. infrahub/core/relationship/constraints/peer_kind.py +3 -4
  94. infrahub/core/relationship/constraints/profiles_kind.py +2 -2
  95. infrahub/core/relationship/model.py +51 -59
  96. infrahub/core/schema/attribute_schema.py +16 -8
  97. infrahub/core/schema/basenode_schema.py +105 -44
  98. infrahub/core/schema/computed_attribute.py +3 -3
  99. infrahub/core/schema/definitions/core/__init__.py +147 -0
  100. infrahub/core/schema/definitions/core/account.py +171 -0
  101. infrahub/core/schema/definitions/core/artifact.py +136 -0
  102. infrahub/core/schema/definitions/core/builtin.py +24 -0
  103. infrahub/core/schema/definitions/core/check.py +68 -0
  104. infrahub/core/schema/definitions/core/core.py +17 -0
  105. infrahub/core/schema/definitions/core/generator.py +100 -0
  106. infrahub/core/schema/definitions/core/graphql_query.py +79 -0
  107. infrahub/core/schema/definitions/core/group.py +108 -0
  108. infrahub/core/schema/definitions/core/ipam.py +193 -0
  109. infrahub/core/schema/definitions/core/lineage.py +19 -0
  110. infrahub/core/schema/definitions/core/menu.py +48 -0
  111. infrahub/core/schema/definitions/core/permission.py +163 -0
  112. infrahub/core/schema/definitions/core/profile.py +18 -0
  113. infrahub/core/schema/definitions/core/propose_change.py +97 -0
  114. infrahub/core/schema/definitions/core/propose_change_comment.py +193 -0
  115. infrahub/core/schema/definitions/core/propose_change_validator.py +328 -0
  116. infrahub/core/schema/definitions/core/repository.py +286 -0
  117. infrahub/core/schema/definitions/core/resource_pool.py +170 -0
  118. infrahub/core/schema/definitions/core/template.py +27 -0
  119. infrahub/core/schema/definitions/core/transform.py +96 -0
  120. infrahub/core/schema/definitions/core/webhook.py +134 -0
  121. infrahub/core/schema/definitions/internal.py +16 -16
  122. infrahub/core/schema/dropdown.py +3 -4
  123. infrahub/core/schema/generated/attribute_schema.py +15 -18
  124. infrahub/core/schema/generated/base_node_schema.py +12 -14
  125. infrahub/core/schema/generated/node_schema.py +3 -5
  126. infrahub/core/schema/generated/relationship_schema.py +9 -11
  127. infrahub/core/schema/generic_schema.py +2 -2
  128. infrahub/core/schema/manager.py +20 -9
  129. infrahub/core/schema/node_schema.py +4 -2
  130. infrahub/core/schema/relationship_schema.py +14 -6
  131. infrahub/core/schema/schema_branch.py +292 -144
  132. infrahub/core/schema/schema_branch_computed.py +41 -4
  133. infrahub/core/task/task.py +3 -3
  134. infrahub/core/task/user_task.py +15 -15
  135. infrahub/core/timestamp.py +3 -3
  136. infrahub/core/utils.py +20 -18
  137. infrahub/core/validators/__init__.py +1 -3
  138. infrahub/core/validators/aggregated_checker.py +2 -2
  139. infrahub/core/validators/attribute/choices.py +2 -2
  140. infrahub/core/validators/attribute/enum.py +2 -2
  141. infrahub/core/validators/attribute/kind.py +2 -2
  142. infrahub/core/validators/attribute/length.py +2 -2
  143. infrahub/core/validators/attribute/optional.py +2 -2
  144. infrahub/core/validators/attribute/regex.py +2 -2
  145. infrahub/core/validators/attribute/unique.py +2 -2
  146. infrahub/core/validators/checks_runner.py +25 -2
  147. infrahub/core/validators/determiner.py +1 -3
  148. infrahub/core/validators/interface.py +6 -2
  149. infrahub/core/validators/model.py +22 -3
  150. infrahub/core/validators/models/validate_migration.py +17 -4
  151. infrahub/core/validators/node/attribute.py +2 -2
  152. infrahub/core/validators/node/generate_profile.py +2 -2
  153. infrahub/core/validators/node/hierarchy.py +3 -5
  154. infrahub/core/validators/node/inherit_from.py +27 -5
  155. infrahub/core/validators/node/relationship.py +2 -2
  156. infrahub/core/validators/relationship/count.py +4 -4
  157. infrahub/core/validators/relationship/optional.py +2 -2
  158. infrahub/core/validators/relationship/peer.py +2 -2
  159. infrahub/core/validators/shared.py +2 -2
  160. infrahub/core/validators/tasks.py +8 -0
  161. infrahub/core/validators/uniqueness/checker.py +22 -21
  162. infrahub/core/validators/uniqueness/index.py +2 -2
  163. infrahub/core/validators/uniqueness/model.py +11 -11
  164. infrahub/database/__init__.py +27 -22
  165. infrahub/database/metrics.py +7 -1
  166. infrahub/dependencies/builder/constraint/grouped/node_runner.py +1 -3
  167. infrahub/dependencies/builder/diff/deserializer.py +3 -1
  168. infrahub/dependencies/builder/diff/enricher/hierarchy.py +3 -1
  169. infrahub/dependencies/builder/diff/parent_node_adder.py +8 -0
  170. infrahub/dependencies/component/registry.py +2 -2
  171. infrahub/events/__init__.py +25 -2
  172. infrahub/events/artifact_action.py +64 -0
  173. infrahub/events/branch_action.py +33 -22
  174. infrahub/events/generator.py +71 -0
  175. infrahub/events/group_action.py +51 -21
  176. infrahub/events/models.py +18 -19
  177. infrahub/events/node_action.py +88 -37
  178. infrahub/events/repository_action.py +5 -18
  179. infrahub/events/schema_action.py +4 -9
  180. infrahub/events/utils.py +16 -0
  181. infrahub/events/validator_action.py +55 -0
  182. infrahub/exceptions.py +32 -24
  183. infrahub/generators/models.py +2 -3
  184. infrahub/generators/tasks.py +24 -4
  185. infrahub/git/base.py +7 -7
  186. infrahub/git/integrator.py +48 -24
  187. infrahub/git/models.py +101 -9
  188. infrahub/git/repository.py +3 -3
  189. infrahub/git/tasks.py +408 -6
  190. infrahub/git/utils.py +48 -0
  191. infrahub/git/worktree.py +1 -2
  192. infrahub/git_credential/askpass.py +1 -2
  193. infrahub/graphql/analyzer.py +12 -0
  194. infrahub/graphql/app.py +13 -15
  195. infrahub/graphql/context.py +39 -0
  196. infrahub/graphql/initialization.py +3 -0
  197. infrahub/graphql/loaders/node.py +2 -12
  198. infrahub/graphql/loaders/peers.py +77 -0
  199. infrahub/graphql/loaders/shared.py +13 -0
  200. infrahub/graphql/manager.py +17 -19
  201. infrahub/graphql/mutations/artifact_definition.py +5 -5
  202. infrahub/graphql/mutations/branch.py +26 -1
  203. infrahub/graphql/mutations/computed_attribute.py +9 -5
  204. infrahub/graphql/mutations/diff.py +23 -11
  205. infrahub/graphql/mutations/diff_conflict.py +5 -0
  206. infrahub/graphql/mutations/generator.py +83 -0
  207. infrahub/graphql/mutations/graphql_query.py +5 -5
  208. infrahub/graphql/mutations/ipam.py +54 -74
  209. infrahub/graphql/mutations/main.py +195 -132
  210. infrahub/graphql/mutations/menu.py +7 -7
  211. infrahub/graphql/mutations/models.py +2 -4
  212. infrahub/graphql/mutations/node_getter/by_default_filter.py +10 -10
  213. infrahub/graphql/mutations/node_getter/by_hfid.py +1 -3
  214. infrahub/graphql/mutations/node_getter/by_id.py +1 -3
  215. infrahub/graphql/mutations/node_getter/interface.py +1 -2
  216. infrahub/graphql/mutations/proposed_change.py +7 -7
  217. infrahub/graphql/mutations/relationship.py +93 -19
  218. infrahub/graphql/mutations/repository.py +8 -8
  219. infrahub/graphql/mutations/resource_manager.py +3 -3
  220. infrahub/graphql/mutations/schema.py +19 -4
  221. infrahub/graphql/mutations/webhook.py +137 -0
  222. infrahub/graphql/parser.py +4 -4
  223. infrahub/graphql/permissions.py +1 -10
  224. infrahub/graphql/queries/diff/tree.py +19 -14
  225. infrahub/graphql/queries/event.py +5 -2
  226. infrahub/graphql/queries/ipam.py +2 -2
  227. infrahub/graphql/queries/relationship.py +2 -2
  228. infrahub/graphql/queries/search.py +2 -2
  229. infrahub/graphql/resolvers/many_relationship.py +264 -0
  230. infrahub/graphql/resolvers/resolver.py +13 -110
  231. infrahub/graphql/schema.py +2 -0
  232. infrahub/graphql/subscription/graphql_query.py +2 -0
  233. infrahub/graphql/types/context.py +12 -0
  234. infrahub/graphql/types/event.py +84 -17
  235. infrahub/graphql/types/node.py +2 -2
  236. infrahub/graphql/utils.py +2 -2
  237. infrahub/groups/ancestors.py +29 -0
  238. infrahub/groups/parsers.py +107 -0
  239. infrahub/lock.py +20 -20
  240. infrahub/menu/constants.py +0 -1
  241. infrahub/menu/generator.py +9 -21
  242. infrahub/menu/menu.py +17 -38
  243. infrahub/menu/models.py +117 -16
  244. infrahub/menu/repository.py +111 -0
  245. infrahub/menu/utils.py +5 -8
  246. infrahub/message_bus/__init__.py +11 -13
  247. infrahub/message_bus/messages/__init__.py +1 -21
  248. infrahub/message_bus/messages/check_generator_run.py +3 -3
  249. infrahub/message_bus/messages/finalize_validator_execution.py +3 -0
  250. infrahub/message_bus/messages/proposed_change/request_proposedchange_refreshartifacts.py +6 -0
  251. infrahub/message_bus/messages/request_generatordefinition_check.py +2 -0
  252. infrahub/message_bus/messages/send_echo_request.py +1 -1
  253. infrahub/message_bus/operations/__init__.py +1 -10
  254. infrahub/message_bus/operations/check/__init__.py +2 -2
  255. infrahub/message_bus/operations/check/generator.py +1 -0
  256. infrahub/message_bus/operations/event/__init__.py +2 -2
  257. infrahub/message_bus/operations/event/worker.py +0 -3
  258. infrahub/message_bus/operations/finalize/validator.py +51 -1
  259. infrahub/message_bus/operations/requests/__init__.py +0 -2
  260. infrahub/message_bus/operations/requests/generator_definition.py +21 -23
  261. infrahub/message_bus/operations/requests/proposed_change.py +14 -10
  262. infrahub/permissions/globals.py +15 -0
  263. infrahub/pools/number.py +2 -4
  264. infrahub/proposed_change/models.py +3 -0
  265. infrahub/proposed_change/tasks.py +58 -45
  266. infrahub/pytest_plugin.py +13 -10
  267. infrahub/server.py +2 -3
  268. infrahub/services/__init__.py +2 -2
  269. infrahub/services/adapters/cache/__init__.py +4 -6
  270. infrahub/services/adapters/cache/nats.py +4 -5
  271. infrahub/services/adapters/cache/redis.py +3 -7
  272. infrahub/services/adapters/event/__init__.py +1 -1
  273. infrahub/services/adapters/message_bus/__init__.py +3 -3
  274. infrahub/services/adapters/message_bus/local.py +2 -2
  275. infrahub/services/adapters/message_bus/nats.py +4 -4
  276. infrahub/services/adapters/message_bus/rabbitmq.py +4 -4
  277. infrahub/services/adapters/workflow/local.py +2 -2
  278. infrahub/services/component.py +5 -5
  279. infrahub/services/protocols.py +7 -7
  280. infrahub/services/scheduler.py +1 -3
  281. infrahub/task_manager/event.py +102 -9
  282. infrahub/task_manager/models.py +27 -7
  283. infrahub/tasks/artifact.py +7 -6
  284. infrahub/telemetry/__init__.py +0 -0
  285. infrahub/telemetry/constants.py +9 -0
  286. infrahub/telemetry/database.py +86 -0
  287. infrahub/telemetry/models.py +65 -0
  288. infrahub/telemetry/task_manager.py +77 -0
  289. infrahub/{tasks/telemetry.py → telemetry/tasks.py} +49 -56
  290. infrahub/telemetry/utils.py +11 -0
  291. infrahub/trace.py +4 -4
  292. infrahub/transformations/tasks.py +2 -2
  293. infrahub/trigger/catalogue.py +4 -6
  294. infrahub/trigger/constants.py +0 -8
  295. infrahub/trigger/models.py +54 -5
  296. infrahub/trigger/setup.py +90 -0
  297. infrahub/trigger/tasks.py +35 -84
  298. infrahub/utils.py +11 -1
  299. infrahub/validators/__init__.py +0 -0
  300. infrahub/validators/events.py +42 -0
  301. infrahub/validators/tasks.py +41 -0
  302. infrahub/webhook/gather.py +17 -0
  303. infrahub/webhook/models.py +176 -44
  304. infrahub/webhook/tasks.py +154 -155
  305. infrahub/webhook/triggers.py +31 -7
  306. infrahub/workers/infrahub_async.py +2 -2
  307. infrahub/workers/utils.py +2 -2
  308. infrahub/workflows/catalogue.py +86 -35
  309. infrahub/workflows/initialization.py +8 -2
  310. infrahub/workflows/models.py +27 -1
  311. infrahub/workflows/utils.py +10 -1
  312. infrahub_sdk/client.py +35 -8
  313. infrahub_sdk/config.py +3 -0
  314. infrahub_sdk/context.py +13 -0
  315. infrahub_sdk/ctl/branch.py +3 -2
  316. infrahub_sdk/ctl/cli_commands.py +5 -1
  317. infrahub_sdk/ctl/utils.py +0 -16
  318. infrahub_sdk/exceptions.py +12 -0
  319. infrahub_sdk/generator.py +4 -1
  320. infrahub_sdk/graphql.py +45 -13
  321. infrahub_sdk/node.py +71 -22
  322. infrahub_sdk/protocols.py +21 -8
  323. infrahub_sdk/protocols_base.py +32 -11
  324. infrahub_sdk/query_groups.py +6 -35
  325. infrahub_sdk/schema/__init__.py +55 -26
  326. infrahub_sdk/schema/main.py +8 -0
  327. infrahub_sdk/task/__init__.py +11 -0
  328. infrahub_sdk/task/constants.py +3 -0
  329. infrahub_sdk/task/exceptions.py +25 -0
  330. infrahub_sdk/task/manager.py +551 -0
  331. infrahub_sdk/task/models.py +74 -0
  332. infrahub_sdk/testing/schemas/animal.py +9 -0
  333. infrahub_sdk/timestamp.py +142 -33
  334. infrahub_sdk/utils.py +29 -1
  335. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/METADATA +8 -6
  336. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/RECORD +349 -293
  337. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/entry_points.txt +1 -0
  338. infrahub_testcontainers/constants.py +2 -0
  339. infrahub_testcontainers/container.py +157 -12
  340. infrahub_testcontainers/docker-compose.test.yml +31 -6
  341. infrahub_testcontainers/helpers.py +18 -73
  342. infrahub_testcontainers/host.py +41 -0
  343. infrahub_testcontainers/measurements.py +93 -0
  344. infrahub_testcontainers/models.py +38 -0
  345. infrahub_testcontainers/performance_test.py +166 -0
  346. infrahub_testcontainers/plugin.py +136 -0
  347. infrahub_testcontainers/prometheus.yml +30 -0
  348. infrahub/core/schema/definitions/core.py +0 -2286
  349. infrahub/message_bus/messages/check_repository_checkdefinition.py +0 -20
  350. infrahub/message_bus/messages/check_repository_mergeconflicts.py +0 -16
  351. infrahub/message_bus/messages/check_repository_usercheck.py +0 -26
  352. infrahub/message_bus/messages/event_branch_create.py +0 -11
  353. infrahub/message_bus/messages/event_branch_delete.py +0 -11
  354. infrahub/message_bus/messages/event_branch_rebased.py +0 -9
  355. infrahub/message_bus/messages/event_node_mutated.py +0 -15
  356. infrahub/message_bus/messages/event_schema_update.py +0 -9
  357. infrahub/message_bus/messages/request_repository_checks.py +0 -12
  358. infrahub/message_bus/messages/request_repository_userchecks.py +0 -18
  359. infrahub/message_bus/operations/check/repository.py +0 -293
  360. infrahub/message_bus/operations/event/node.py +0 -20
  361. infrahub/message_bus/operations/event/schema.py +0 -17
  362. infrahub/message_bus/operations/requests/repository.py +0 -133
  363. infrahub/webhook/constants.py +0 -1
  364. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/LICENSE.txt +0 -0
  365. {infrahub_server-1.2.0rc0.dist-info → infrahub_server-1.2.1.dist-info}/WHEEL +0 -0
@@ -7,7 +7,7 @@ from pathlib import Path
7
7
  from typing import TYPE_CHECKING
8
8
 
9
9
  import pytest
10
- from infrahub_sdk.protocols import CoreGeneratorDefinition, CoreProposedChange
10
+ from infrahub_sdk.protocols import CoreArtifactValidator, CoreGeneratorDefinition, CoreProposedChange
11
11
  from prefect import flow, task
12
12
  from prefect.cache_policies import NONE
13
13
  from prefect.client.schemas.objects import (
@@ -22,7 +22,7 @@ from infrahub.context import InfrahubContext # noqa: TC001 needed for prefect
22
22
  from infrahub.core import registry
23
23
  from infrahub.core.branch import Branch
24
24
  from infrahub.core.branch.tasks import merge_branch
25
- from infrahub.core.constants import InfrahubKind, RepositoryInternalStatus, ValidatorConclusion, ValidatorState
25
+ from infrahub.core.constants import InfrahubKind, RepositoryInternalStatus, ValidatorConclusion
26
26
  from infrahub.core.diff.coordinator import DiffCoordinator
27
27
  from infrahub.core.diff.model.diff import DiffElementType, SchemaConflict
28
28
  from infrahub.core.diff.model.path import NodeDiffFieldSummary
@@ -36,6 +36,7 @@ from infrahub.core.validators.tasks import schema_validate_migrations
36
36
  from infrahub.dependencies.registry import get_component_registry
37
37
  from infrahub.exceptions import MergeFailedError
38
38
  from infrahub.generators.models import ProposedChangeGeneratorDefinition
39
+ from infrahub.git.models import TriggerRepositoryInternalChecks, TriggerRepositoryUserChecks
39
40
  from infrahub.git.repository import get_initialized_repo
40
41
  from infrahub.log import get_logger
41
42
  from infrahub.message_bus import InfrahubMessage, messages
@@ -51,9 +52,11 @@ from infrahub.proposed_change.models import (
51
52
  )
52
53
  from infrahub.pytest_plugin import InfrahubBackendPlugin
53
54
  from infrahub.services import InfrahubServices # noqa: TC001 needed for prefect flow
55
+ from infrahub.validators.tasks import start_validator
54
56
  from infrahub.workflows.catalogue import (
55
- COMPUTED_ATTRIBUTE_SETUP_PYTHON,
56
57
  GIT_REPOSITORIES_CHECK_ARTIFACT_CREATE,
58
+ GIT_REPOSITORY_INTERNAL_CHECKS_TRIGGER,
59
+ GIT_REPOSITORY_USER_CHECKS_TRIGGER,
57
60
  REQUEST_PROPOSED_CHANGE_REPOSITORY_CHECKS,
58
61
  )
59
62
  from infrahub.workflows.utils import add_tags
@@ -147,7 +150,9 @@ async def merge_proposed_change(
147
150
 
148
151
  log.info("Proposed change is eligible to be merged")
149
152
  try:
150
- await merge_branch(branch=source_branch.name, context=context, service=service)
153
+ await merge_branch(
154
+ branch=source_branch.name, context=context, service=service, proposed_change_id=proposed_change_id
155
+ )
151
156
  except MergeFailedError as exc:
152
157
  await _proposed_change_transition_state(
153
158
  proposed_change=proposed_change, state=ProposedChangeState.OPEN, service=service
@@ -159,7 +164,6 @@ async def merge_proposed_change(
159
164
  await _proposed_change_transition_state(
160
165
  proposed_change=proposed_change, state=ProposedChangeState.MERGED, service=service
161
166
  )
162
- await service.workflow.submit_workflow(workflow=COMPUTED_ATTRIBUTE_SETUP_PYTHON, context=context)
163
167
  return Completed(message="proposed change merged successfully")
164
168
 
165
169
 
@@ -272,6 +276,7 @@ async def run_generators(
272
276
 
273
277
  if select:
274
278
  msg = messages.RequestGeneratorDefinitionCheck(
279
+ context=context,
275
280
  generator_definition=generator_definition,
276
281
  branch_diff=model.branch_diff,
277
282
  proposed_change=model.proposed_change,
@@ -286,6 +291,7 @@ async def run_generators(
286
291
  if model.refresh_artifacts:
287
292
  next_messages.append(
288
293
  messages.RequestProposedChangeRefreshArtifacts(
294
+ context=context,
289
295
  proposed_change=model.proposed_change,
290
296
  source_branch=model.source_branch,
291
297
  source_branch_sync_with_git=model.source_branch_sync_with_git,
@@ -411,39 +417,43 @@ async def _get_proposed_change_schema_integrity_constraints(
411
417
  name="proposed-changed-repository-checks",
412
418
  flow_run_name="Process user defined checks",
413
419
  )
414
- async def repository_checks(model: RequestProposedChangeRepositoryChecks, service: InfrahubServices) -> None:
420
+ async def repository_checks(
421
+ model: RequestProposedChangeRepositoryChecks, service: InfrahubServices, context: InfrahubContext
422
+ ) -> None:
415
423
  await add_tags(branches=[model.source_branch], nodes=[model.proposed_change])
416
424
 
417
- events: list[InfrahubMessage] = []
418
425
  for repository in model.branch_diff.repositories:
419
426
  if (
420
427
  model.source_branch_sync_with_git
421
428
  and not repository.read_only
422
429
  and repository.internal_status == RepositoryInternalStatus.ACTIVE.value
423
430
  ):
424
- events.append(
425
- messages.RequestRepositoryChecks(
426
- proposed_change=model.proposed_change,
427
- repository=repository.repository_id,
428
- source_branch=model.source_branch,
429
- target_branch=model.destination_branch,
430
- )
431
- )
432
-
433
- events.append(
434
- messages.RequestRepositoryUserChecks(
431
+ trigger_internal_checks_model = TriggerRepositoryInternalChecks(
435
432
  proposed_change=model.proposed_change,
436
- repository_id=repository.repository_id,
437
- repository_name=repository.repository_name,
433
+ repository=repository.repository_id,
438
434
  source_branch=model.source_branch,
439
- source_branch_sync_with_git=model.source_branch_sync_with_git,
440
435
  target_branch=model.destination_branch,
441
- branch_diff=model.branch_diff,
442
436
  )
437
+ await service.workflow.submit_workflow(
438
+ workflow=GIT_REPOSITORY_INTERNAL_CHECKS_TRIGGER,
439
+ context=context,
440
+ parameters={"model": trigger_internal_checks_model},
441
+ )
442
+
443
+ trigger_user_checks_model = TriggerRepositoryUserChecks(
444
+ proposed_change=model.proposed_change,
445
+ repository_id=repository.repository_id,
446
+ repository_name=repository.repository_name,
447
+ source_branch=model.source_branch,
448
+ source_branch_sync_with_git=model.source_branch_sync_with_git,
449
+ target_branch=model.destination_branch,
450
+ branch_diff=model.branch_diff,
451
+ )
452
+ await service.workflow.submit_workflow(
453
+ workflow=GIT_REPOSITORY_USER_CHECKS_TRIGGER,
454
+ context=context,
455
+ parameters={"model": trigger_user_checks_model},
443
456
  )
444
- for event in events:
445
- event.assign_meta(parent=model)
446
- await service.message_bus.send(message=event)
447
457
 
448
458
 
449
459
  @flow(
@@ -530,31 +540,26 @@ async def validate_artifacts_generation(model: RequestArtifactDefinitionCheck, s
530
540
 
531
541
  await proposed_change.validations.fetch()
532
542
 
533
- validator = None
543
+ previous_validator: CoreArtifactValidator | None = None
534
544
  for relationship in proposed_change.validations.peers:
535
545
  existing_validator = relationship.peer
536
546
  if (
537
547
  existing_validator.typename == InfrahubKind.ARTIFACTVALIDATOR
538
548
  and existing_validator.definition.id == model.artifact_definition.definition_id
539
549
  ):
540
- validator = existing_validator
541
-
542
- if validator:
543
- validator.conclusion.value = ValidatorConclusion.UNKNOWN.value
544
- validator.state.value = ValidatorState.QUEUED.value
545
- validator.started_at.value = ""
546
- validator.completed_at.value = ""
547
- await validator.save()
548
- else:
549
- validator = await service.client.create(
550
- kind=InfrahubKind.ARTIFACTVALIDATOR,
551
- data={
552
- "label": validator_name,
553
- "proposed_change": model.proposed_change,
554
- "definition": model.artifact_definition.definition_id,
555
- },
556
- )
557
- await validator.save()
550
+ previous_validator = existing_validator
551
+
552
+ validator = await start_validator(
553
+ service=service,
554
+ validator=previous_validator,
555
+ validator_type=CoreArtifactValidator,
556
+ proposed_change=model.proposed_change,
557
+ data={
558
+ "label": validator_name,
559
+ "definition": model.artifact_definition.definition_id,
560
+ },
561
+ context=model.context,
562
+ )
558
563
 
559
564
  await artifact_definition.targets.fetch()
560
565
  group = artifact_definition.targets.peer
@@ -586,6 +591,7 @@ async def validate_artifacts_generation(model: RequestArtifactDefinitionCheck, s
586
591
  log.info(f"Trigger Artifact processing for {member.display_label}")
587
592
 
588
593
  check_model = CheckArtifactCreate(
594
+ context=model.context,
589
595
  artifact_name=model.artifact_definition.artifact_name,
590
596
  artifact_id=artifact_id,
591
597
  artifact_definition=model.artifact_definition.definition_id,
@@ -600,6 +606,7 @@ async def validate_artifacts_generation(model: RequestArtifactDefinitionCheck, s
600
606
  query=model.artifact_definition.query_name,
601
607
  variables=member.extract(params=artifact_definition.parameters.value),
602
608
  target_id=member.id,
609
+ target_kind=member.get_kind(),
603
610
  target_name=member.display_label,
604
611
  timeout=model.artifact_definition.timeout,
605
612
  validator_id=validator.id,
@@ -613,7 +620,13 @@ async def validate_artifacts_generation(model: RequestArtifactDefinitionCheck, s
613
620
  )
614
621
  )
615
622
 
616
- await run_checks_and_update_validator(checks, validator)
623
+ await run_checks_and_update_validator(
624
+ checks=checks,
625
+ validator=validator,
626
+ proposed_change_id=model.proposed_change,
627
+ context=model.context,
628
+ service=service,
629
+ )
617
630
 
618
631
 
619
632
  def _should_render_artifact(artifact_id: str | None, managed_branch: bool, impacted_artifacts: list[str]) -> bool: # noqa: ARG001
infrahub/pytest_plugin.py CHANGED
@@ -1,9 +1,7 @@
1
- from typing import Optional
2
-
1
+ import pytest
3
2
  from infrahub_sdk.client import Config as InfrahubClientConfig
4
3
  from infrahub_sdk.client import InfrahubClientSync
5
4
  from infrahub_sdk.node import InfrahubNodeSync
6
- from pytest import Config, Item, Session, TestReport
7
5
 
8
6
  from infrahub.core.constants import InfrahubKind
9
7
  from infrahub.core.timestamp import Timestamp
@@ -52,7 +50,12 @@ class InfrahubBackendPlugin:
52
50
 
53
51
  return validator, True
54
52
 
55
- def pytest_collection_modifyitems(self, session: Session, config: Config, items: list[Item]) -> None: # noqa: ARG002
53
+ def pytest_collection_modifyitems(
54
+ self,
55
+ session: pytest.Session, # noqa: ARG002
56
+ config: pytest.Config, # noqa: ARG002
57
+ items: list[pytest.Item],
58
+ ) -> None:
56
59
  """This function is called after item collection and gives the opportunity to work on the collection before sending the items for testing.
57
60
 
58
61
  All items without an "infrahub" marker will be discarded. Items will also be re-ordered to be run in a specific order:
@@ -64,7 +67,7 @@ class InfrahubBackendPlugin:
64
67
  """
65
68
  filtered_items = [i for i in items if i.get_closest_marker("infrahub")]
66
69
 
67
- def sort_key(item: Item) -> tuple[int, int]:
70
+ def sort_key(item: pytest.Item) -> tuple[int, int]:
68
71
  type_cost = 99
69
72
  for marker_name, priority in ORDER_TYPE_MAP.items():
70
73
  if item.get_closest_marker(marker_name):
@@ -82,7 +85,7 @@ class InfrahubBackendPlugin:
82
85
  filtered_items.sort(key=sort_key)
83
86
  items[:] = filtered_items
84
87
 
85
- def pytest_collection_finish(self, session: Session) -> None: # noqa: ARG002
88
+ def pytest_collection_finish(self, session: pytest.Session) -> None: # noqa: ARG002
86
89
  """This function is called when tests have been collected and modified, meaning they are ready to be run."""
87
90
  self.proposed_change = self.client.get(kind=InfrahubKind.PROPOSEDCHANGE, id=self.proposed_change_id)
88
91
  self.proposed_change.validations.fetch()
@@ -95,7 +98,7 @@ class InfrahubBackendPlugin:
95
98
  check = relationship.peer
96
99
  self.checks[check.origin.value] = check
97
100
 
98
- def pytest_runtestloop(self, session: Session) -> Optional[object]: # noqa: ARG002
101
+ def pytest_runtestloop(self, session: pytest.Session) -> object | None: # noqa: ARG002
99
102
  """This function is called when the test loop is being run."""
100
103
  self.validator.conclusion.value = "unknown"
101
104
  self.validator.state.value = "in_progress"
@@ -104,7 +107,7 @@ class InfrahubBackendPlugin:
104
107
 
105
108
  return None
106
109
 
107
- def pytest_runtest_setup(self, item: Item) -> None:
110
+ def pytest_runtest_setup(self, item: pytest.Item) -> None:
108
111
  """Create a StandardCheck for each test item to later record its details.
109
112
 
110
113
  If a check already exists, reset it to its default values.
@@ -132,7 +135,7 @@ class InfrahubBackendPlugin:
132
135
 
133
136
  check.save()
134
137
 
135
- def pytest_runtest_logreport(self, report: TestReport) -> None:
138
+ def pytest_runtest_logreport(self, report: pytest.TestReport) -> None:
136
139
  """This function is called 3 times per test: setup, call, teardown."""
137
140
  if report.when != "call":
138
141
  return
@@ -144,7 +147,7 @@ class InfrahubBackendPlugin:
144
147
  # Workaround for https://github.com/opsmill/infrahub/issues/2184
145
148
  check.update(do_full_update=True)
146
149
 
147
- def pytest_sessionfinish(self, session: Session) -> None: # noqa: ARG002
150
+ def pytest_sessionfinish(self, session: pytest.Session) -> None: # noqa: ARG002
148
151
  """Set the final RepositoryValidator details after completing the test session."""
149
152
  conclusion = "success"
150
153
 
infrahub/server.py CHANGED
@@ -14,10 +14,9 @@ from fastapi.middleware.gzip import GZipMiddleware
14
14
  from fastapi.responses import RedirectResponse
15
15
  from fastapi.staticfiles import StaticFiles
16
16
  from fastapi.templating import Jinja2Templates
17
- from infrahub_sdk.timestamp import TimestampFormatError
17
+ from infrahub_sdk.exceptions import TimestampFormatError
18
18
  from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
19
19
  from opentelemetry.trace import Span
20
- from pydantic import ValidationError
21
20
  from starlette_exporter import PrometheusMiddleware, handle_metrics
22
21
 
23
22
  from infrahub import __version__, config
@@ -28,7 +27,7 @@ from infrahub.core.graph.index import node_indexes, rel_indexes
28
27
  from infrahub.core.initialization import initialization
29
28
  from infrahub.database import InfrahubDatabase, InfrahubDatabaseMode, get_db
30
29
  from infrahub.dependencies.registry import build_component_registry
31
- from infrahub.exceptions import Error
30
+ from infrahub.exceptions import Error, ValidationError
32
31
  from infrahub.graphql.api.endpoints import router as graphql_router
33
32
  from infrahub.lock import initialize_lock
34
33
  from infrahub.log import clear_log_context, get_logger, set_log_data
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Awaitable, Callable, Optional
3
+ from typing import TYPE_CHECKING, Awaitable, Callable
4
4
 
5
5
  from infrahub.components import ComponentType
6
6
  from infrahub.exceptions import InitializationError
@@ -182,7 +182,7 @@ class InfrahubServices:
182
182
  await self.scheduler.shutdown()
183
183
  await self.message_bus.shutdown()
184
184
 
185
- async def send(self, message: InfrahubMessage, delay: Optional[MessageTTL] = None, is_retry: bool = False) -> None:
185
+ async def send(self, message: InfrahubMessage, delay: MessageTTL | None = None, is_retry: bool = False) -> None:
186
186
  routing_key = ROUTING_KEY_MAP.get(type(message))
187
187
  if not routing_key:
188
188
  raise ValueError("Unable to determine routing key")
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
- from typing import TYPE_CHECKING, Optional
4
+ from typing import TYPE_CHECKING
5
5
 
6
6
  if TYPE_CHECKING:
7
7
  from infrahub.message_bus.types import KVTTL
@@ -16,12 +16,12 @@ class InfrahubCache(ABC):
16
16
  raise NotImplementedError()
17
17
 
18
18
  @abstractmethod
19
- async def get(self, key: str) -> Optional[str]:
19
+ async def get(self, key: str) -> str | None:
20
20
  """Retrieve a value from the cache."""
21
21
  raise NotImplementedError()
22
22
 
23
23
  @abstractmethod
24
- async def get_values(self, keys: list[str]) -> list[Optional[str]]:
24
+ async def get_values(self, keys: list[str]) -> list[str | None]:
25
25
  """Return a list the values for requested keys."""
26
26
  raise NotImplementedError()
27
27
 
@@ -31,8 +31,6 @@ class InfrahubCache(ABC):
31
31
  raise NotImplementedError()
32
32
 
33
33
  @abstractmethod
34
- async def set(
35
- self, key: str, value: str, expires: Optional[KVTTL] = None, not_exists: bool = False
36
- ) -> Optional[bool]:
34
+ async def set(self, key: str, value: str, expires: KVTTL | None = None, not_exists: bool = False) -> bool | None:
37
35
  """Set a value in the cache."""
38
36
  raise NotImplementedError()
@@ -1,7 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import ssl
4
- from typing import Optional
5
4
 
6
5
  import nats
7
6
 
@@ -84,7 +83,7 @@ class NATSCache(InfrahubCache):
84
83
  key = self._tokenize_key_name(key)
85
84
  await self._get_kv(key).delete(key)
86
85
 
87
- async def get(self, key: str) -> Optional[str]:
86
+ async def get(self, key: str) -> str | None:
88
87
  key = self._tokenize_key_name(key)
89
88
  try:
90
89
  entry = await self._get_kv(key).get(key=key)
@@ -94,7 +93,7 @@ class NATSCache(InfrahubCache):
94
93
  pass
95
94
  return None
96
95
 
97
- async def get_values(self, keys: list[str]) -> list[Optional[str]]:
96
+ async def get_values(self, keys: list[str]) -> list[str | None]:
98
97
  return [await self.get(key) for key in keys]
99
98
 
100
99
  async def _keys(self, kv: nats.js.kv.KeyValue, filter_pattern: str) -> list[str]:
@@ -138,9 +137,9 @@ class NATSCache(InfrahubCache):
138
137
  self,
139
138
  key: str,
140
139
  value: str,
141
- expires: Optional[KVTTL] = None, # noqa: ARG002
140
+ expires: KVTTL | None = None, # noqa: ARG002
142
141
  not_exists: bool = False,
143
- ) -> Optional[bool]:
142
+ ) -> bool | None:
144
143
  key = self._tokenize_key_name(key)
145
144
  if not_exists:
146
145
  try:
@@ -1,5 +1,3 @@
1
- from typing import Optional
2
-
3
1
  import redis.asyncio as redis
4
2
 
5
3
  from infrahub import config
@@ -22,13 +20,13 @@ class RedisCache(InfrahubCache):
22
20
  async def delete(self, key: str) -> None:
23
21
  await self.connection.delete(key)
24
22
 
25
- async def get(self, key: str) -> Optional[str]:
23
+ async def get(self, key: str) -> str | None:
26
24
  value = await self.connection.get(name=key)
27
25
  if value is not None:
28
26
  return value.decode()
29
27
  return None
30
28
 
31
- async def get_values(self, keys: list[str]) -> list[Optional[str]]:
29
+ async def get_values(self, keys: list[str]) -> list[str | None]:
32
30
  values = await self.connection.mget(keys=keys)
33
31
  return [value.decode() if value is not None else value for value in values]
34
32
 
@@ -44,7 +42,5 @@ class RedisCache(InfrahubCache):
44
42
 
45
43
  return [key.decode() for key in keys]
46
44
 
47
- async def set(
48
- self, key: str, value: str, expires: Optional[KVTTL] = None, not_exists: bool = False
49
- ) -> Optional[bool]:
45
+ async def set(self, key: str, value: str, expires: KVTTL | None = None, not_exists: bool = False) -> bool | None:
50
46
  return await self.connection.set(name=key, value=value, ex=expires.value if expires else None, nx=not_exists)
@@ -31,7 +31,7 @@ class InfrahubEventService:
31
31
  async def _send_prefect(self, event: InfrahubEvent) -> None:
32
32
  emit_event(
33
33
  id=event.meta.id,
34
- event=event.get_name(),
34
+ event=event.event_name,
35
35
  resource=event.get_resource(),
36
36
  related=event.get_related(),
37
37
  payload=event.get_event_payload(),
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
- from typing import TYPE_CHECKING, Optional, TypeVar
4
+ from typing import TYPE_CHECKING, TypeVar
5
5
 
6
6
  from infrahub.message_bus.messages import ROUTING_KEY_MAP
7
7
 
@@ -36,7 +36,7 @@ class InfrahubMessageBus(ABC):
36
36
 
37
37
  @abstractmethod
38
38
  async def publish(
39
- self, message: InfrahubMessage, routing_key: str, delay: Optional[MessageTTL] = None, is_retry: bool = False
39
+ self, message: InfrahubMessage, routing_key: str, delay: MessageTTL | None = None, is_retry: bool = False
40
40
  ) -> None:
41
41
  raise NotImplementedError()
42
42
 
@@ -48,7 +48,7 @@ class InfrahubMessageBus(ABC):
48
48
  async def rpc(self, message: InfrahubMessage, response_class: type[ResponseClass]) -> ResponseClass:
49
49
  raise NotImplementedError()
50
50
 
51
- async def send(self, message: InfrahubMessage, delay: Optional[MessageTTL] = None, is_retry: bool = False) -> None:
51
+ async def send(self, message: InfrahubMessage, delay: MessageTTL | None = None, is_retry: bool = False) -> None:
52
52
  routing_key = ROUTING_KEY_MAP.get(type(message))
53
53
  if not routing_key:
54
54
  raise ValueError("Unable to determine routing key")
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from collections import defaultdict
4
- from typing import TYPE_CHECKING, Optional, TypeVar
4
+ from typing import TYPE_CHECKING, TypeVar
5
5
 
6
6
  import ujson
7
7
  from infrahub_sdk.uuidt import UUIDT
@@ -29,7 +29,7 @@ class BusSimulator(InfrahubMessageBus):
29
29
  self,
30
30
  message: InfrahubMessage,
31
31
  routing_key: str,
32
- delay: Optional[MessageTTL] = None, # noqa: ARG002
32
+ delay: MessageTTL | None = None, # noqa: ARG002
33
33
  is_retry: bool = False, # noqa: ARG002
34
34
  ) -> None:
35
35
  self.messages.append(message)
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import asyncio
4
4
  import ssl
5
- from typing import TYPE_CHECKING, Awaitable, Callable, MutableMapping, Optional, TypeVar
5
+ from typing import TYPE_CHECKING, Awaitable, Callable, MutableMapping, TypeVar
6
6
 
7
7
  import nats
8
8
  import ujson
@@ -33,7 +33,7 @@ async def _add_request_id(message: InfrahubMessage) -> None:
33
33
 
34
34
 
35
35
  class NATSMessageBus(InfrahubMessageBus):
36
- def __init__(self, component_type: ComponentType, settings: Optional[BrokerSettings] = None) -> None:
36
+ def __init__(self, component_type: ComponentType, settings: BrokerSettings | None = None) -> None:
37
37
  self.settings = settings or config.SETTINGS.broker
38
38
 
39
39
  self.service: InfrahubServices
@@ -49,7 +49,7 @@ class NATSMessageBus(InfrahubMessageBus):
49
49
  self.component_type: ComponentType = component_type
50
50
 
51
51
  @classmethod
52
- async def new(cls, component_type: ComponentType, settings: Optional[BrokerSettings] = None) -> NATSMessageBus:
52
+ async def new(cls, component_type: ComponentType, settings: BrokerSettings | None = None) -> NATSMessageBus:
53
53
  message_bus = cls(component_type=component_type, settings=settings)
54
54
  await message_bus._initialize()
55
55
  return message_bus
@@ -213,7 +213,7 @@ class NATSMessageBus(InfrahubMessageBus):
213
213
  await self.publish(message, routing_key)
214
214
 
215
215
  async def publish(
216
- self, message: InfrahubMessage, routing_key: str, delay: Optional[MessageTTL] = None, is_retry: bool = False
216
+ self, message: InfrahubMessage, routing_key: str, delay: MessageTTL | None = None, is_retry: bool = False
217
217
  ) -> None:
218
218
  with trace.get_tracer(__name__).start_as_current_span("publish_message") as span:
219
219
  span.set_attribute("routing_key", routing_key)
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
- from typing import TYPE_CHECKING, Awaitable, Callable, MutableMapping, Optional, TypeVar
4
+ from typing import TYPE_CHECKING, Awaitable, Callable, MutableMapping, TypeVar
5
5
 
6
6
  import aio_pika
7
7
  import opentelemetry.instrumentation.aio_pika.span_builder
@@ -66,7 +66,7 @@ async def _add_request_id(message: InfrahubMessage) -> None:
66
66
 
67
67
  class RabbitMQMessageBus(InfrahubMessageBus):
68
68
  def __init__(
69
- self, component_type: ComponentType = ComponentType.NONE, settings: Optional[BrokerSettings] = None
69
+ self, component_type: ComponentType = ComponentType.NONE, settings: BrokerSettings | None = None
70
70
  ) -> None:
71
71
  self.settings = settings or config.SETTINGS.broker
72
72
  self.channel: AbstractChannel
@@ -85,7 +85,7 @@ class RabbitMQMessageBus(InfrahubMessageBus):
85
85
  self.component_type: ComponentType = component_type
86
86
 
87
87
  @classmethod
88
- async def new(cls, component_type: ComponentType, settings: Optional[BrokerSettings] = None) -> RabbitMQMessageBus:
88
+ async def new(cls, component_type: ComponentType, settings: BrokerSettings | None = None) -> RabbitMQMessageBus:
89
89
  message_bus = cls(component_type=component_type, settings=settings)
90
90
  await message_bus._initialize()
91
91
  return message_bus
@@ -221,7 +221,7 @@ class RabbitMQMessageBus(InfrahubMessageBus):
221
221
  self,
222
222
  message: InfrahubMessage,
223
223
  routing_key: str,
224
- delay: Optional[MessageTTL] = None,
224
+ delay: MessageTTL | None = None,
225
225
  is_retry: bool = False, # noqa: ARG002
226
226
  ) -> None:
227
227
  for enricher in self.message_enrichers:
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import uuid
4
- from typing import Any, Optional
4
+ from typing import Any
5
5
 
6
6
  from typing_extensions import TYPE_CHECKING
7
7
 
@@ -16,7 +16,7 @@ if TYPE_CHECKING:
16
16
 
17
17
 
18
18
  class WorkflowLocalExecution(InfrahubWorkflow):
19
- service: Optional[InfrahubServices] = None # needed for local injections
19
+ service: InfrahubServices | None = None # needed for local injections
20
20
 
21
21
  async def execute_workflow(
22
22
  self,
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import re
4
- from typing import TYPE_CHECKING, Any, Optional
4
+ from typing import TYPE_CHECKING, Any
5
5
 
6
6
  from attr import dataclass
7
7
 
@@ -84,7 +84,7 @@ class InfrahubComponent:
84
84
  hash_value = schema_branch.get_hash()
85
85
 
86
86
  # Use branch name if we cannot find branch id in cache
87
- branch_id: Optional[str] = None
87
+ branch_id: str | None = None
88
88
  if branch_obj := await registry.get_branch(branch=branch, db=self.db):
89
89
  branch_id = str(branch_obj.uuid)
90
90
 
@@ -129,10 +129,10 @@ class WorkerInfo:
129
129
  def __init__(self, identity: str) -> None:
130
130
  self.id = identity
131
131
  self.active = False
132
- self._schema_hash: Optional[str] = None
132
+ self._schema_hash: str | None = None
133
133
 
134
134
  @property
135
- def schema_hash(self) -> Optional[str]:
135
+ def schema_hash(self) -> str | None:
136
136
  """Return schema hash provided that the worker is active."""
137
137
  if self.active:
138
138
  return self._schema_hash
@@ -143,7 +143,7 @@ class WorkerInfo:
143
143
  if "workers:active:" in key:
144
144
  self.active = True
145
145
 
146
- def add_value(self, key: str, value: Optional[str] = None) -> None:
146
+ def add_value(self, key: str, value: str | None = None) -> None:
147
147
  if ":schema_hash:" in key:
148
148
  self._schema_hash = value
149
149
 
@@ -1,21 +1,21 @@
1
- from typing import Any, Optional, Protocol
1
+ from typing import Any, Protocol
2
2
 
3
3
 
4
4
  class InfrahubLogger(Protocol):
5
- def debug(self, event: Optional[str] = None, *args: Any, **kw: Any) -> Any:
5
+ def debug(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
6
6
  """Send a debug event"""
7
7
 
8
- def info(self, event: Optional[str] = None, *args: Any, **kw: Any) -> Any:
8
+ def info(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
9
9
  """Send an info event"""
10
10
 
11
- def warning(self, event: Optional[str] = None, *args: Any, **kw: Any) -> Any:
11
+ def warning(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
12
12
  """Send a warning event"""
13
13
 
14
- def error(self, event: Optional[str] = None, *args: Any, **kw: Any) -> Any:
14
+ def error(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
15
15
  """Send an error event."""
16
16
 
17
- def critical(self, event: Optional[str] = None, *args: Any, **kw: Any) -> Any:
17
+ def critical(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
18
18
  """Send a critical event."""
19
19
 
20
- def exception(self, event: Optional[str] = None, *args: Any, **kw: Any) -> Any:
20
+ def exception(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
21
21
  """Send an exception event."""
@@ -5,8 +5,6 @@ import random
5
5
  from dataclasses import dataclass
6
6
  from typing import TYPE_CHECKING
7
7
 
8
- from typing_extensions import Optional
9
-
10
8
  from infrahub import config
11
9
  from infrahub.components import ComponentType
12
10
  from infrahub.log import get_logger
@@ -29,7 +27,7 @@ class Schedule:
29
27
 
30
28
  class InfrahubScheduler:
31
29
  # TODO we could remove service dependency by adding kwargs to Schedule instead of passing services
32
- service: Optional[InfrahubServices]
30
+ service: InfrahubServices | None
33
31
 
34
32
  def __init__(self, component_type: ComponentType) -> None:
35
33
  self.running: bool = False