infrahub-server 1.1.7__py3-none-any.whl → 1.2.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (399) hide show
  1. infrahub/api/artifact.py +16 -4
  2. infrahub/api/dependencies.py +8 -0
  3. infrahub/api/oauth2.py +0 -1
  4. infrahub/api/oidc.py +0 -1
  5. infrahub/api/query.py +18 -7
  6. infrahub/api/schema.py +32 -6
  7. infrahub/api/transformation.py +12 -5
  8. infrahub/{message_bus/messages/check_artifact_create.py → artifacts/models.py} +5 -3
  9. infrahub/{message_bus/operations/check/artifact.py → artifacts/tasks.py} +26 -25
  10. infrahub/cli/__init__.py +0 -2
  11. infrahub/cli/db.py +6 -7
  12. infrahub/cli/events.py +8 -3
  13. infrahub/cli/git_agent.py +9 -7
  14. infrahub/cli/tasks.py +4 -6
  15. infrahub/computed_attribute/models.py +1 -1
  16. infrahub/computed_attribute/tasks.py +64 -17
  17. infrahub/computed_attribute/triggers.py +90 -0
  18. infrahub/config.py +1 -1
  19. infrahub/context.py +39 -0
  20. infrahub/core/account.py +5 -8
  21. infrahub/core/attribute.py +50 -21
  22. infrahub/core/branch/models.py +4 -4
  23. infrahub/core/branch/tasks.py +130 -125
  24. infrahub/core/changelog/__init__.py +0 -0
  25. infrahub/core/changelog/diff.py +283 -0
  26. infrahub/core/changelog/models.py +499 -0
  27. infrahub/core/constants/__init__.py +43 -2
  28. infrahub/core/constants/infrahubkind.py +1 -0
  29. infrahub/core/constants/schema.py +2 -0
  30. infrahub/core/diff/combiner.py +1 -1
  31. infrahub/core/diff/enricher/cardinality_one.py +6 -1
  32. infrahub/core/diff/enricher/hierarchy.py +22 -7
  33. infrahub/core/diff/enricher/labels.py +6 -1
  34. infrahub/core/diff/enricher/path_identifier.py +5 -1
  35. infrahub/core/diff/enricher/summary_counts.py +107 -0
  36. infrahub/core/diff/merger/merger.py +3 -1
  37. infrahub/core/diff/model/path.py +34 -11
  38. infrahub/core/diff/parent_node_adder.py +78 -0
  39. infrahub/core/diff/payload_builder.py +13 -2
  40. infrahub/core/diff/query/all_conflicts.py +1 -1
  41. infrahub/core/diff/query/artifact.py +1 -1
  42. infrahub/core/diff/query/delete_query.py +1 -1
  43. infrahub/core/diff/query/diff_get.py +1 -1
  44. infrahub/core/diff/query/diff_summary.py +1 -1
  45. infrahub/core/diff/query/field_specifiers.py +1 -1
  46. infrahub/core/diff/query/field_summary.py +1 -1
  47. infrahub/core/diff/query/filters.py +2 -2
  48. infrahub/core/diff/query/get_conflict_query.py +1 -1
  49. infrahub/core/diff/query/has_conflicts_query.py +1 -1
  50. infrahub/core/diff/query/merge.py +3 -3
  51. infrahub/core/diff/query/merge_tracking_id.py +1 -1
  52. infrahub/core/diff/query/roots_metadata.py +1 -1
  53. infrahub/core/diff/query/save.py +191 -185
  54. infrahub/core/diff/query/summary_counts_enricher.py +52 -5
  55. infrahub/core/diff/query/time_range_query.py +1 -1
  56. infrahub/core/diff/query/update_conflict_query.py +1 -1
  57. infrahub/core/diff/repository/deserializer.py +9 -4
  58. infrahub/core/diff/repository/repository.py +156 -38
  59. infrahub/core/diff/tasks.py +13 -12
  60. infrahub/core/enums.py +1 -1
  61. infrahub/core/graph/__init__.py +1 -1
  62. infrahub/core/graph/index.py +3 -0
  63. infrahub/core/integrity/object_conflict/conflict_recorder.py +1 -1
  64. infrahub/core/ipam/reconciler.py +1 -1
  65. infrahub/core/ipam/tasks.py +2 -3
  66. infrahub/core/manager.py +20 -15
  67. infrahub/core/merge.py +5 -2
  68. infrahub/core/migrations/graph/__init__.py +4 -0
  69. infrahub/core/migrations/graph/m001_add_version_to_graph.py +1 -1
  70. infrahub/core/migrations/graph/m002_attribute_is_default.py +2 -2
  71. infrahub/core/migrations/graph/m003_relationship_parent_optional.py +2 -2
  72. infrahub/core/migrations/graph/m004_add_attr_documentation.py +1 -1
  73. infrahub/core/migrations/graph/m005_add_rel_read_only.py +1 -1
  74. infrahub/core/migrations/graph/m006_add_rel_on_delete.py +1 -1
  75. infrahub/core/migrations/graph/m007_add_rel_allow_override.py +1 -1
  76. infrahub/core/migrations/graph/m008_add_human_friendly_id.py +1 -1
  77. infrahub/core/migrations/graph/m009_add_generate_profile_attr.py +1 -1
  78. infrahub/core/migrations/graph/m010_add_generate_profile_attr_generic.py +1 -1
  79. infrahub/core/migrations/graph/m011_remove_profile_relationship_schema.py +2 -2
  80. infrahub/core/migrations/graph/m012_convert_account_generic.py +12 -23
  81. infrahub/core/migrations/graph/m013_convert_git_password_credential.py +7 -11
  82. infrahub/core/migrations/graph/m014_remove_index_attr_value.py +2 -2
  83. infrahub/core/migrations/graph/m015_diff_format_update.py +1 -1
  84. infrahub/core/migrations/graph/m016_diff_delete_bug_fix.py +1 -1
  85. infrahub/core/migrations/graph/m017_add_core_profile.py +1 -1
  86. infrahub/core/migrations/graph/m018_uniqueness_nulls.py +2 -2
  87. infrahub/core/migrations/graph/m019_restore_rels_to_time.py +256 -0
  88. infrahub/core/migrations/graph/m020_add_generate_template_attr.py +48 -0
  89. infrahub/core/migrations/query/attribute_add.py +1 -1
  90. infrahub/core/migrations/query/attribute_rename.py +1 -1
  91. infrahub/core/migrations/query/delete_element_in_schema.py +1 -1
  92. infrahub/core/migrations/query/node_duplicate.py +39 -19
  93. infrahub/core/migrations/query/relationship_duplicate.py +1 -1
  94. infrahub/core/migrations/query/schema_attribute_update.py +1 -1
  95. infrahub/core/migrations/schema/node_attribute_remove.py +1 -1
  96. infrahub/core/migrations/schema/node_remove.py +27 -13
  97. infrahub/core/migrations/schema/tasks.py +5 -5
  98. infrahub/core/migrations/shared.py +4 -4
  99. infrahub/core/models.py +7 -8
  100. infrahub/core/node/__init__.py +164 -45
  101. infrahub/core/node/base.py +1 -1
  102. infrahub/core/node/delete_validator.py +4 -4
  103. infrahub/core/node/ipam.py +7 -7
  104. infrahub/core/node/resource_manager/ip_prefix_pool.py +8 -5
  105. infrahub/core/node/standard.py +3 -5
  106. infrahub/core/property.py +1 -1
  107. infrahub/core/protocols.py +6 -0
  108. infrahub/core/protocols_base.py +4 -2
  109. infrahub/core/query/__init__.py +2 -5
  110. infrahub/core/query/attribute.py +9 -9
  111. infrahub/core/query/branch.py +5 -5
  112. infrahub/core/query/delete.py +1 -1
  113. infrahub/core/query/diff.py +4 -4
  114. infrahub/core/query/ipam.py +4 -4
  115. infrahub/core/query/node.py +11 -12
  116. infrahub/core/query/relationship.py +211 -25
  117. infrahub/core/query/resource_manager.py +10 -10
  118. infrahub/core/query/standard_node.py +6 -6
  119. infrahub/core/query/task.py +3 -3
  120. infrahub/core/query/task_log.py +1 -1
  121. infrahub/core/query/utils.py +5 -5
  122. infrahub/core/registry.py +0 -2
  123. infrahub/core/relationship/constraints/count.py +1 -1
  124. infrahub/core/relationship/constraints/peer_kind.py +1 -1
  125. infrahub/core/relationship/model.py +76 -38
  126. infrahub/core/schema/__init__.py +6 -4
  127. infrahub/core/schema/attribute_schema.py +8 -0
  128. infrahub/core/schema/basenode_schema.py +13 -3
  129. infrahub/core/schema/definitions/core/__init__.py +153 -0
  130. infrahub/core/schema/definitions/core/account.py +168 -0
  131. infrahub/core/schema/definitions/core/artifact.py +127 -0
  132. infrahub/core/schema/definitions/core/builtin.py +21 -0
  133. infrahub/core/schema/definitions/core/check.py +60 -0
  134. infrahub/core/schema/definitions/core/generator.py +96 -0
  135. infrahub/core/schema/definitions/core/graphql_query.py +77 -0
  136. infrahub/core/schema/definitions/core/group.py +105 -0
  137. infrahub/core/schema/definitions/core/ipam.py +252 -0
  138. infrahub/core/schema/definitions/core/lineage.py +17 -0
  139. infrahub/core/schema/definitions/core/menu.py +46 -0
  140. infrahub/core/schema/definitions/core/permission.py +161 -0
  141. infrahub/core/schema/definitions/core/profile.py +29 -0
  142. infrahub/core/schema/definitions/core/propose_change.py +88 -0
  143. infrahub/core/schema/definitions/core/propose_change_comment.py +188 -0
  144. infrahub/core/schema/definitions/core/propose_change_validator.py +326 -0
  145. infrahub/core/schema/definitions/core/repository.py +280 -0
  146. infrahub/core/schema/definitions/core/resource_pool.py +180 -0
  147. infrahub/core/schema/definitions/core/template.py +12 -0
  148. infrahub/core/schema/definitions/core/transform.py +87 -0
  149. infrahub/core/schema/definitions/core/webhook.py +108 -0
  150. infrahub/core/schema/definitions/internal.py +16 -0
  151. infrahub/core/schema/generated/genericnode_schema.py +5 -0
  152. infrahub/core/schema/generated/node_schema.py +5 -0
  153. infrahub/core/schema/generic_schema.py +5 -1
  154. infrahub/core/schema/manager.py +45 -42
  155. infrahub/core/schema/node_schema.py +4 -0
  156. infrahub/core/schema/profile_schema.py +4 -0
  157. infrahub/core/schema/relationship_schema.py +10 -2
  158. infrahub/core/schema/schema_branch.py +260 -16
  159. infrahub/core/schema/template_schema.py +36 -0
  160. infrahub/core/task/user_task.py +7 -5
  161. infrahub/core/timestamp.py +3 -3
  162. infrahub/core/utils.py +2 -2
  163. infrahub/core/validators/attribute/choices.py +1 -1
  164. infrahub/core/validators/attribute/enum.py +1 -1
  165. infrahub/core/validators/attribute/kind.py +1 -1
  166. infrahub/core/validators/attribute/length.py +1 -1
  167. infrahub/core/validators/attribute/optional.py +1 -1
  168. infrahub/core/validators/attribute/regex.py +1 -1
  169. infrahub/core/validators/attribute/unique.py +1 -1
  170. infrahub/core/validators/checks_runner.py +37 -0
  171. infrahub/core/validators/node/generate_profile.py +1 -1
  172. infrahub/core/validators/node/hierarchy.py +1 -1
  173. infrahub/core/validators/query.py +1 -1
  174. infrahub/core/validators/relationship/count.py +1 -1
  175. infrahub/core/validators/relationship/optional.py +1 -1
  176. infrahub/core/validators/relationship/peer.py +1 -1
  177. infrahub/core/validators/tasks.py +8 -6
  178. infrahub/core/validators/uniqueness/query.py +1 -1
  179. infrahub/database/__init__.py +3 -2
  180. infrahub/database/memgraph.py +1 -1
  181. infrahub/dependencies/builder/diff/combiner.py +1 -1
  182. infrahub/dependencies/builder/diff/conflicts_enricher.py +1 -1
  183. infrahub/dependencies/builder/diff/deserializer.py +4 -2
  184. infrahub/dependencies/builder/diff/enricher/hierarchy.py +3 -1
  185. infrahub/dependencies/builder/diff/enricher/summary_counts.py +8 -0
  186. infrahub/dependencies/builder/diff/parent_node_adder.py +8 -0
  187. infrahub/events/artifact_action.py +76 -0
  188. infrahub/events/branch_action.py +50 -21
  189. infrahub/events/group_action.py +117 -0
  190. infrahub/events/models.py +164 -51
  191. infrahub/events/node_action.py +70 -8
  192. infrahub/events/repository_action.py +8 -8
  193. infrahub/events/schema_action.py +21 -8
  194. infrahub/exceptions.py +9 -0
  195. infrahub/generators/models.py +1 -0
  196. infrahub/generators/tasks.py +34 -15
  197. infrahub/git/base.py +3 -5
  198. infrahub/git/constants.py +0 -1
  199. infrahub/git/integrator.py +60 -36
  200. infrahub/git/models.py +80 -1
  201. infrahub/git/repository.py +7 -8
  202. infrahub/git/tasks.py +432 -112
  203. infrahub/git_credential/helper.py +2 -3
  204. infrahub/graphql/analyzer.py +572 -11
  205. infrahub/graphql/app.py +34 -26
  206. infrahub/graphql/auth/query_permission_checker/anonymous_checker.py +5 -5
  207. infrahub/graphql/auth/query_permission_checker/default_branch_checker.py +4 -4
  208. infrahub/graphql/auth/query_permission_checker/merge_operation_checker.py +4 -4
  209. infrahub/graphql/auth/query_permission_checker/object_permission_checker.py +28 -35
  210. infrahub/graphql/auth/query_permission_checker/super_admin_checker.py +5 -5
  211. infrahub/graphql/context.py +33 -0
  212. infrahub/graphql/enums.py +1 -1
  213. infrahub/graphql/initialization.py +5 -1
  214. infrahub/graphql/loaders/node.py +2 -2
  215. infrahub/graphql/manager.py +63 -63
  216. infrahub/graphql/mutations/account.py +20 -13
  217. infrahub/graphql/mutations/artifact_definition.py +16 -12
  218. infrahub/graphql/mutations/branch.py +86 -40
  219. infrahub/graphql/mutations/computed_attribute.py +24 -15
  220. infrahub/graphql/mutations/diff.py +33 -17
  221. infrahub/graphql/mutations/diff_conflict.py +14 -8
  222. infrahub/graphql/mutations/generator.py +83 -0
  223. infrahub/graphql/mutations/graphql_query.py +19 -11
  224. infrahub/graphql/mutations/ipam.py +25 -23
  225. infrahub/graphql/mutations/main.py +233 -45
  226. infrahub/graphql/mutations/menu.py +10 -10
  227. infrahub/graphql/mutations/proposed_change.py +36 -28
  228. infrahub/graphql/mutations/relationship.py +341 -130
  229. infrahub/graphql/mutations/repository.py +41 -35
  230. infrahub/graphql/mutations/resource_manager.py +26 -26
  231. infrahub/graphql/mutations/schema.py +66 -33
  232. infrahub/graphql/mutations/tasks.py +10 -7
  233. infrahub/graphql/parser.py +1 -1
  234. infrahub/graphql/permissions.py +3 -10
  235. infrahub/graphql/queries/account.py +22 -18
  236. infrahub/graphql/queries/branch.py +6 -4
  237. infrahub/graphql/queries/diff/tree.py +63 -52
  238. infrahub/graphql/queries/event.py +115 -0
  239. infrahub/graphql/queries/internal.py +3 -3
  240. infrahub/graphql/queries/ipam.py +23 -18
  241. infrahub/graphql/queries/relationship.py +11 -10
  242. infrahub/graphql/queries/resource_manager.py +37 -25
  243. infrahub/graphql/queries/search.py +9 -8
  244. infrahub/graphql/queries/status.py +12 -9
  245. infrahub/graphql/queries/task.py +11 -9
  246. infrahub/graphql/resolvers/resolver.py +69 -43
  247. infrahub/graphql/resolvers/single_relationship.py +16 -10
  248. infrahub/graphql/schema.py +4 -0
  249. infrahub/graphql/subscription/__init__.py +1 -1
  250. infrahub/graphql/subscription/events.py +1 -1
  251. infrahub/graphql/subscription/graphql_query.py +8 -8
  252. infrahub/graphql/types/branch.py +2 -2
  253. infrahub/graphql/types/common.py +6 -1
  254. infrahub/graphql/types/context.py +12 -0
  255. infrahub/graphql/types/enums.py +2 -0
  256. infrahub/graphql/types/event.py +158 -0
  257. infrahub/graphql/types/interface.py +2 -2
  258. infrahub/graphql/types/node.py +3 -3
  259. infrahub/graphql/types/permission.py +2 -2
  260. infrahub/graphql/types/relationship.py +3 -3
  261. infrahub/graphql/types/standard_node.py +9 -11
  262. infrahub/graphql/utils.py +28 -182
  263. infrahub/groups/tasks.py +2 -3
  264. infrahub/lock.py +21 -21
  265. infrahub/menu/generator.py +0 -1
  266. infrahub/menu/menu.py +116 -138
  267. infrahub/menu/models.py +4 -4
  268. infrahub/message_bus/__init__.py +11 -13
  269. infrahub/message_bus/messages/__init__.py +0 -14
  270. infrahub/message_bus/messages/check_generator_run.py +1 -3
  271. infrahub/message_bus/messages/event_branch_merge.py +3 -0
  272. infrahub/message_bus/messages/proposed_change/request_proposedchange_refreshartifacts.py +6 -0
  273. infrahub/message_bus/messages/request_proposedchange_pipeline.py +2 -0
  274. infrahub/message_bus/messages/send_echo_request.py +1 -1
  275. infrahub/message_bus/operations/__init__.py +4 -13
  276. infrahub/message_bus/operations/check/__init__.py +2 -2
  277. infrahub/message_bus/operations/check/generator.py +1 -3
  278. infrahub/message_bus/operations/event/branch.py +7 -3
  279. infrahub/message_bus/operations/event/schema.py +1 -1
  280. infrahub/message_bus/operations/event/worker.py +0 -3
  281. infrahub/message_bus/operations/finalize/validator.py +1 -1
  282. infrahub/message_bus/operations/git/file.py +2 -2
  283. infrahub/message_bus/operations/git/repository.py +1 -1
  284. infrahub/message_bus/operations/requests/__init__.py +0 -4
  285. infrahub/message_bus/operations/requests/generator_definition.py +2 -4
  286. infrahub/message_bus/operations/requests/proposed_change.py +37 -20
  287. infrahub/message_bus/operations/send/echo.py +1 -1
  288. infrahub/message_bus/types.py +1 -1
  289. infrahub/permissions/globals.py +15 -0
  290. infrahub/pools/prefix.py +29 -165
  291. infrahub/prefect_server/__init__.py +0 -0
  292. infrahub/prefect_server/app.py +18 -0
  293. infrahub/prefect_server/database.py +20 -0
  294. infrahub/prefect_server/events.py +28 -0
  295. infrahub/prefect_server/models.py +46 -0
  296. infrahub/proposed_change/models.py +18 -1
  297. infrahub/proposed_change/tasks.py +195 -53
  298. infrahub/pytest_plugin.py +4 -4
  299. infrahub/server.py +13 -12
  300. infrahub/services/__init__.py +148 -63
  301. infrahub/services/adapters/cache/__init__.py +11 -11
  302. infrahub/services/adapters/cache/nats.py +42 -25
  303. infrahub/services/adapters/cache/redis.py +3 -11
  304. infrahub/services/adapters/event/__init__.py +10 -18
  305. infrahub/services/adapters/http/__init__.py +0 -5
  306. infrahub/services/adapters/http/httpx.py +22 -15
  307. infrahub/services/adapters/message_bus/__init__.py +25 -8
  308. infrahub/services/adapters/message_bus/local.py +9 -7
  309. infrahub/services/adapters/message_bus/nats.py +14 -8
  310. infrahub/services/adapters/message_bus/rabbitmq.py +23 -10
  311. infrahub/services/adapters/workflow/__init__.py +11 -8
  312. infrahub/services/adapters/workflow/local.py +27 -6
  313. infrahub/services/adapters/workflow/worker.py +23 -7
  314. infrahub/services/component.py +43 -40
  315. infrahub/services/protocols.py +7 -7
  316. infrahub/services/scheduler.py +30 -29
  317. infrahub/storage.py +2 -4
  318. infrahub/task_manager/constants.py +1 -1
  319. infrahub/task_manager/event.py +261 -0
  320. infrahub/task_manager/models.py +147 -3
  321. infrahub/task_manager/task.py +1 -1
  322. infrahub/tasks/artifact.py +19 -18
  323. infrahub/tasks/registry.py +1 -1
  324. infrahub/tasks/telemetry.py +13 -14
  325. infrahub/transformations/tasks.py +3 -5
  326. infrahub/trigger/__init__.py +0 -0
  327. infrahub/trigger/catalogue.py +16 -0
  328. infrahub/trigger/constants.py +9 -0
  329. infrahub/trigger/models.py +105 -0
  330. infrahub/trigger/tasks.py +91 -0
  331. infrahub/types.py +1 -1
  332. infrahub/utils.py +1 -1
  333. infrahub/webhook/constants.py +0 -2
  334. infrahub/webhook/models.py +161 -40
  335. infrahub/webhook/tasks.py +123 -202
  336. infrahub/webhook/triggers.py +27 -0
  337. infrahub/workers/infrahub_async.py +36 -25
  338. infrahub/workers/utils.py +63 -0
  339. infrahub/workflows/catalogue.py +71 -52
  340. infrahub/workflows/initialization.py +14 -8
  341. infrahub/workflows/models.py +28 -4
  342. infrahub/workflows/utils.py +1 -1
  343. infrahub_sdk/batch.py +2 -2
  344. infrahub_sdk/client.py +8 -0
  345. infrahub_sdk/config.py +1 -1
  346. infrahub_sdk/ctl/branch.py +3 -2
  347. infrahub_sdk/ctl/check.py +4 -4
  348. infrahub_sdk/ctl/cli_commands.py +16 -11
  349. infrahub_sdk/ctl/exceptions.py +0 -6
  350. infrahub_sdk/ctl/exporter.py +1 -1
  351. infrahub_sdk/ctl/generator.py +5 -5
  352. infrahub_sdk/ctl/importer.py +3 -2
  353. infrahub_sdk/ctl/menu.py +1 -1
  354. infrahub_sdk/ctl/object.py +1 -1
  355. infrahub_sdk/ctl/repository.py +23 -15
  356. infrahub_sdk/ctl/schema.py +2 -2
  357. infrahub_sdk/ctl/utils.py +6 -21
  358. infrahub_sdk/ctl/validate.py +2 -1
  359. infrahub_sdk/data.py +1 -1
  360. infrahub_sdk/exceptions.py +12 -0
  361. infrahub_sdk/generator.py +3 -0
  362. infrahub_sdk/node.py +5 -8
  363. infrahub_sdk/protocols.py +20 -8
  364. infrahub_sdk/schema/__init__.py +14 -5
  365. infrahub_sdk/schema/main.py +7 -0
  366. infrahub_sdk/task/__init__.py +1 -0
  367. infrahub_sdk/task/constants.py +3 -0
  368. infrahub_sdk/task/exceptions.py +25 -0
  369. infrahub_sdk/task/manager.py +545 -0
  370. infrahub_sdk/task/models.py +74 -0
  371. infrahub_sdk/testing/docker.py +30 -0
  372. infrahub_sdk/timestamp.py +134 -33
  373. infrahub_sdk/transfer/exporter/json.py +1 -1
  374. infrahub_sdk/utils.py +39 -1
  375. infrahub_sdk/yaml.py +2 -3
  376. {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/METADATA +7 -6
  377. {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/RECORD +383 -339
  378. infrahub_testcontainers/container.py +2 -3
  379. infrahub_testcontainers/docker-compose.test.yml +2 -2
  380. infrahub/core/branch/constants.py +0 -2
  381. infrahub/core/schema/definitions/core.py +0 -2274
  382. infrahub/graphql/query.py +0 -52
  383. infrahub/message_bus/messages/check_repository_checkdefinition.py +0 -20
  384. infrahub/message_bus/messages/check_repository_mergeconflicts.py +0 -16
  385. infrahub/message_bus/messages/check_repository_usercheck.py +0 -26
  386. infrahub/message_bus/messages/request_artifactdefinition_check.py +0 -17
  387. infrahub/message_bus/messages/request_repository_checks.py +0 -12
  388. infrahub/message_bus/messages/request_repository_userchecks.py +0 -18
  389. infrahub/message_bus/operations/check/repository.py +0 -293
  390. infrahub/message_bus/operations/requests/artifact_definition.py +0 -148
  391. infrahub/message_bus/operations/requests/repository.py +0 -133
  392. infrahub/schema/constants.py +0 -1
  393. infrahub/schema/tasks.py +0 -76
  394. infrahub/services/adapters/database/__init__.py +0 -9
  395. infrahub_sdk/ctl/_file.py +0 -13
  396. /infrahub/{schema → artifacts}/__init__.py +0 -0
  397. {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/LICENSE.txt +0 -0
  398. {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/WHEEL +0 -0
  399. {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/entry_points.txt +0 -0
infrahub/api/artifact.py CHANGED
@@ -5,7 +5,14 @@ from typing import TYPE_CHECKING
5
5
  from fastapi import APIRouter, Body, Depends, Request, Response
6
6
  from pydantic import BaseModel, Field
7
7
 
8
- from infrahub.api.dependencies import BranchParams, get_branch_params, get_current_user, get_db, get_permission_manager
8
+ from infrahub.api.dependencies import (
9
+ BranchParams,
10
+ get_branch_params,
11
+ get_context,
12
+ get_current_user,
13
+ get_db,
14
+ get_permission_manager,
15
+ )
9
16
  from infrahub.core import registry
10
17
  from infrahub.core.account import ObjectPermission
11
18
  from infrahub.core.constants import GLOBAL_BRANCH_NAME, InfrahubKind, PermissionAction
@@ -19,7 +26,9 @@ from infrahub.workflows.catalogue import REQUEST_ARTIFACT_DEFINITION_GENERATE
19
26
 
20
27
  if TYPE_CHECKING:
21
28
  from infrahub.auth import AccountSession
29
+ from infrahub.context import InfrahubContext
22
30
  from infrahub.permissions import PermissionManager
31
+ from infrahub.services import InfrahubServices
23
32
 
24
33
  log = get_logger()
25
34
  router = APIRouter(prefix="/artifact")
@@ -57,12 +66,13 @@ async def generate_artifact(
57
66
  request: Request,
58
67
  artifact_definition_id: str,
59
68
  payload: ArtifactGeneratePayload = Body(
60
- ArtifactGeneratePayload(),
69
+ ArtifactGeneratePayload(), # noqa: B008
61
70
  description="Payload of the request, can be used to limit the scope of the query to a specific list of hosts",
62
71
  ),
63
72
  db: InfrahubDatabase = Depends(get_db),
64
73
  branch_params: BranchParams = Depends(get_branch_params),
65
74
  permission_manager: PermissionManager = Depends(get_permission_manager),
75
+ context: InfrahubContext = Depends(get_context),
66
76
  ) -> None:
67
77
  permission_decision = (
68
78
  PermissionDecisionFlag.ALLOW_DEFAULT
@@ -83,7 +93,7 @@ async def generate_artifact(
83
93
  branch=branch_params.branch,
84
94
  )
85
95
 
86
- service = request.app.state.service
96
+ service: InfrahubServices = request.app.state.service
87
97
  model = RequestArtifactDefinitionGenerate(
88
98
  artifact_definition_id=artifact_definition.id,
89
99
  artifact_definition_name=artifact_definition.name.value,
@@ -91,4 +101,6 @@ async def generate_artifact(
91
101
  limit=payload.nodes,
92
102
  )
93
103
 
94
- await service.workflow.submit_workflow(workflow=REQUEST_ARTIFACT_DEFINITION_GENERATE, parameters={"model": model})
104
+ await service.workflow.submit_workflow(
105
+ workflow=REQUEST_ARTIFACT_DEFINITION_GENERATE, context=context, parameters={"model": model}
106
+ )
@@ -8,6 +8,7 @@ from pydantic import BaseModel, ConfigDict
8
8
 
9
9
  from infrahub import config
10
10
  from infrahub.auth import AccountSession, authentication_token, validate_jwt_access_token, validate_jwt_refresh_token
11
+ from infrahub.context import InfrahubContext
11
12
  from infrahub.core.branch import Branch # noqa: TC001
12
13
  from infrahub.core.registry import registry
13
14
  from infrahub.core.timestamp import Timestamp
@@ -133,3 +134,10 @@ async def get_permission_manager(
133
134
  await permission_manager.load_permissions(db=db, branch=branch_params.branch)
134
135
 
135
136
  return permission_manager
137
+
138
+
139
+ async def get_context(
140
+ branch: Branch = Depends(get_branch_dep),
141
+ account_session: AccountSession = Depends(get_current_user),
142
+ ) -> InfrahubContext:
143
+ return InfrahubContext.init(branch=branch, account=account_session)
infrahub/api/oauth2.py CHANGED
@@ -22,7 +22,6 @@ if TYPE_CHECKING:
22
22
  from infrahub.database import InfrahubDatabase
23
23
  from infrahub.services import InfrahubServices
24
24
 
25
- # pylint: disable=R0801
26
25
 
27
26
  log = get_logger()
28
27
  router = APIRouter(prefix="/oauth2")
infrahub/api/oidc.py CHANGED
@@ -24,7 +24,6 @@ if TYPE_CHECKING:
24
24
  from infrahub.database import InfrahubDatabase
25
25
  from infrahub.services import InfrahubServices
26
26
 
27
- # pylint: disable=R0801
28
27
 
29
28
  log = get_logger()
30
29
  router = APIRouter(prefix="/oidc")
infrahub/api/query.py CHANGED
@@ -7,6 +7,7 @@ from graphql import graphql
7
7
  from pydantic import BaseModel, Field
8
8
 
9
9
  from infrahub.api.dependencies import BranchParams, get_branch_params, get_current_user, get_db
10
+ from infrahub.context import InfrahubContext
10
11
  from infrahub.core import registry
11
12
  from infrahub.core.constants import InfrahubKind
12
13
  from infrahub.core.protocols import CoreGraphQLQuery
@@ -57,12 +58,21 @@ async def execute_query(
57
58
  db=db, id=query_id, kind=CoreGraphQLQuery, branch=branch_params.branch, at=branch_params.at
58
59
  )
59
60
 
61
+ context = InfrahubContext.init(branch=branch_params.branch, account=account_session)
62
+
60
63
  gql_params = await prepare_graphql_params(
61
- db=db, branch=branch_params.branch, at=branch_params.at, account_session=account_session
64
+ db=db,
65
+ branch=branch_params.branch,
66
+ at=branch_params.at,
67
+ account_session=account_session,
68
+ service=request.app.state.service,
62
69
  )
70
+ schema_branch = db.schema.get_schema_branch(name=branch_params.branch.name)
71
+
63
72
  analyzed_query = InfrahubGraphQLQueryAnalyzer(
64
73
  query=gql_query.query.value,
65
74
  schema=gql_params.schema,
75
+ schema_branch=schema_branch,
66
76
  branch=branch_params.branch,
67
77
  )
68
78
  await permission_checker.check(
@@ -97,9 +107,7 @@ async def execute_query(
97
107
  GRAPHQL_QUERY_HEIGHT_METRICS.labels(**labels).observe(await analyzed_query.calculate_height())
98
108
  GRAPHQL_QUERY_VARS_METRICS.labels(**labels).observe(len(analyzed_query.variables))
99
109
  GRAPHQL_TOP_LEVEL_QUERIES_METRICS.labels(**labels).observe(analyzed_query.nbr_queries)
100
- GRAPHQL_QUERY_OBJECTS_METRICS.labels(**labels).observe(
101
- len(await analyzed_query.get_models_in_use(types=gql_params.context.types))
102
- )
110
+ GRAPHQL_QUERY_OBJECTS_METRICS.labels(**labels).observe(len(analyzed_query.query_report.impacted_models))
103
111
 
104
112
  response_payload: dict[str, Any] = {"data": data}
105
113
 
@@ -111,11 +119,13 @@ async def execute_query(
111
119
  branch=branch_params.branch.name,
112
120
  query_id=gql_query.id,
113
121
  query_name=gql_query.name.value,
114
- related_node_ids=sorted(list(related_node_ids)),
122
+ related_node_ids=sorted(related_node_ids),
115
123
  subscribers=sorted(subscribers),
116
124
  params=params,
117
125
  )
118
- await service.workflow.submit_workflow(workflow=GRAPHQL_QUERY_GROUP_UPDATE, parameters={"model": model})
126
+ await service.workflow.submit_workflow(
127
+ workflow=GRAPHQL_QUERY_GROUP_UPDATE, context=context, parameters={"model": model}
128
+ )
119
129
 
120
130
  return response_payload
121
131
 
@@ -124,7 +134,8 @@ async def execute_query(
124
134
  async def graphql_query_post(
125
135
  request: Request,
126
136
  payload: QueryPayload = Body(
127
- QueryPayload(), description="Payload of the request, must be used to provide the variables"
137
+ QueryPayload(), # noqa: B008
138
+ description="Payload of the request, must be used to provide the variables",
128
139
  ),
129
140
  query_id: str = Path(description="ID or Name of the GraphQL query to execute"),
130
141
  subscribers: list[str] = Query(
infrahub/api/schema.py CHANGED
@@ -13,7 +13,7 @@ from pydantic import (
13
13
  from starlette.responses import JSONResponse
14
14
 
15
15
  from infrahub import lock
16
- from infrahub.api.dependencies import get_branch_dep, get_current_user, get_db, get_permission_manager
16
+ from infrahub.api.dependencies import get_branch_dep, get_context, get_current_user, get_db, get_permission_manager
17
17
  from infrahub.api.exceptions import SchemaNotValidError
18
18
  from infrahub.core import registry
19
19
  from infrahub.core.account import GlobalPermission
@@ -25,7 +25,7 @@ from infrahub.core.models import ( # noqa: TC001
25
25
  SchemaDiff,
26
26
  SchemaUpdateValidationResult,
27
27
  )
28
- from infrahub.core.schema import GenericSchema, MainSchemaTypes, NodeSchema, ProfileSchema, SchemaRoot
28
+ from infrahub.core.schema import GenericSchema, MainSchemaTypes, NodeSchema, ProfileSchema, SchemaRoot, TemplateSchema
29
29
  from infrahub.core.schema.constants import SchemaNamespace # noqa: TC001
30
30
  from infrahub.core.validators.models.validate_migration import (
31
31
  SchemaValidateMigrationData,
@@ -44,6 +44,7 @@ if TYPE_CHECKING:
44
44
  from typing_extensions import Self
45
45
 
46
46
  from infrahub.auth import AccountSession
47
+ from infrahub.context import InfrahubContext
47
48
  from infrahub.core.schema.schema_branch import SchemaBranch
48
49
  from infrahub.permissions import PermissionManager
49
50
  from infrahub.services import InfrahubServices
@@ -86,11 +87,17 @@ class APIProfileSchema(ProfileSchema, APISchemaMixin):
86
87
  hash: str
87
88
 
88
89
 
90
+ class APITemplateSchema(TemplateSchema, APISchemaMixin):
91
+ api_kind: str | None = Field(default=None, alias="kind", validate_default=True)
92
+ hash: str
93
+
94
+
89
95
  class SchemaReadAPI(BaseModel):
90
96
  main: str = Field(description="Main hash for the entire schema")
91
97
  nodes: list[APINodeSchema] = Field(default_factory=list)
92
98
  generics: list[APIGenericSchema] = Field(default_factory=list)
93
99
  profiles: list[APIProfileSchema] = Field(default_factory=list)
100
+ templates: list[APITemplateSchema] = Field(default_factory=list)
94
101
  namespaces: list[SchemaNamespace] = Field(default_factory=list)
95
102
 
96
103
 
@@ -190,6 +197,11 @@ async def get_schema(
190
197
  for value in all_schemas
191
198
  if isinstance(value, ProfileSchema) and value.namespace != "Internal"
192
199
  ],
200
+ templates=[
201
+ APITemplateSchema.from_schema(value)
202
+ for value in all_schemas
203
+ if isinstance(value, TemplateSchema) and value.namespace != "Internal"
204
+ ],
193
205
  namespaces=schema_branch.get_namespaces(),
194
206
  )
195
207
 
@@ -206,15 +218,16 @@ async def get_schema_summary(
206
218
  @router.get("/{schema_kind}")
207
219
  async def get_schema_by_kind(
208
220
  schema_kind: str, branch: Branch = Depends(get_branch_dep), _: AccountSession = Depends(get_current_user)
209
- ) -> APIProfileSchema | APINodeSchema | APIGenericSchema:
221
+ ) -> APIProfileSchema | APINodeSchema | APIGenericSchema | APITemplateSchema:
210
222
  log.debug("schema_kind_request", branch=branch.name)
211
223
 
212
224
  schema = registry.schema.get(name=schema_kind, branch=branch, duplicate=False)
213
225
 
214
- api_schema: dict[str, type[APIProfileSchema | APINodeSchema | APIGenericSchema]] = {
226
+ api_schema: dict[str, type[APIProfileSchema | APINodeSchema | APIGenericSchema | APITemplateSchema]] = {
215
227
  "profile": APIProfileSchema,
216
228
  "node": APINodeSchema,
217
229
  "generic": APIGenericSchema,
230
+ "template": APITemplateSchema,
218
231
  }
219
232
  key = ""
220
233
 
@@ -224,6 +237,8 @@ async def get_schema_by_kind(
224
237
  key = "node"
225
238
  if isinstance(schema, GenericSchema):
226
239
  key = "generic"
240
+ if isinstance(schema, TemplateSchema):
241
+ key = "template"
227
242
 
228
243
  return api_schema[key].from_schema(schema=schema)
229
244
 
@@ -269,6 +284,7 @@ async def load_schema(
269
284
  branch: Branch = Depends(get_branch_dep),
270
285
  account_session: AccountSession = Depends(get_current_user),
271
286
  permission_manager: PermissionManager = Depends(get_permission_manager),
287
+ context: InfrahubContext = Depends(get_context),
272
288
  ) -> SchemaUpdate:
273
289
  permission_manager.raise_for_permission(
274
290
  permission=GlobalPermission(
@@ -317,6 +333,7 @@ async def load_schema(
317
333
  )
318
334
  responses = await service.workflow.execute_workflow(
319
335
  workflow=SCHEMA_VALIDATE_MIGRATION,
336
+ context=context,
320
337
  expected_return=list[SchemaValidatorPathResponseData],
321
338
  parameters={"message": validate_migration_data},
322
339
  )
@@ -361,6 +378,7 @@ async def load_schema(
361
378
  )
362
379
  migration_error_msgs = await service.workflow.execute_workflow(
363
380
  workflow=SCHEMA_APPLY_MIGRATION,
381
+ context=context,
364
382
  expected_return=list[str],
365
383
  parameters={"message": apply_migration_data},
366
384
  )
@@ -373,9 +391,15 @@ async def load_schema(
373
391
  log_data = get_log_data()
374
392
  request_id = log_data.get("request_id", "")
375
393
  event = SchemaUpdatedEvent(
376
- branch=branch.name,
394
+ branch_name=branch.name,
377
395
  schema_hash=branch.active_schema_hash.main,
378
- meta=EventMeta(initiator_id=WORKER_IDENTITY, request_id=request_id, account_id=account_session.account_id),
396
+ meta=EventMeta(
397
+ initiator_id=WORKER_IDENTITY,
398
+ request_id=request_id,
399
+ account_id=account_session.account_id,
400
+ branch=branch,
401
+ context=context,
402
+ ),
379
403
  )
380
404
  await service.event.send(event=event)
381
405
 
@@ -387,6 +411,7 @@ async def check_schema(
387
411
  request: Request,
388
412
  schemas: SchemasLoadAPI,
389
413
  branch: Branch = Depends(get_branch_dep),
414
+ context: InfrahubContext = Depends(get_context),
390
415
  _: AccountSession = Depends(get_current_user),
391
416
  ) -> JSONResponse:
392
417
  service: InfrahubServices = request.app.state.service
@@ -413,6 +438,7 @@ async def check_schema(
413
438
  )
414
439
  responses = await service.workflow.execute_workflow(
415
440
  workflow=SCHEMA_VALIDATE_MIGRATION,
441
+ context=context,
416
442
  expected_return=list[SchemaValidatorPathResponseData],
417
443
  parameters={"message": validate_migration_data},
418
444
  )
@@ -9,6 +9,7 @@ from starlette.responses import JSONResponse, PlainTextResponse
9
9
  from infrahub.api.dependencies import (
10
10
  BranchParams,
11
11
  get_branch_params,
12
+ get_context,
12
13
  get_current_user,
13
14
  get_db,
14
15
  )
@@ -28,8 +29,8 @@ from infrahub.workflows.catalogue import TRANSFORM_JINJA2_RENDER, TRANSFORM_PYTH
28
29
 
29
30
  if TYPE_CHECKING:
30
31
  from infrahub.auth import AccountSession
32
+ from infrahub.context import InfrahubContext
31
33
  from infrahub.services import InfrahubServices
32
-
33
34
  router = APIRouter()
34
35
 
35
36
 
@@ -38,6 +39,7 @@ async def transform_python(
38
39
  request: Request,
39
40
  transform_id: str,
40
41
  db: InfrahubDatabase = Depends(get_db),
42
+ context: InfrahubContext = Depends(get_context),
41
43
  branch_params: BranchParams = Depends(get_branch_params),
42
44
  _: AccountSession = Depends(get_current_user),
43
45
  ) -> JSONResponse:
@@ -62,7 +64,9 @@ async def transform_python(
62
64
  message="Repository doesn't have a commit",
63
65
  )
64
66
 
65
- gql_params = await prepare_graphql_params(db=request.app.state.db, branch=branch_params.branch, at=branch_params.at)
67
+ gql_params = await prepare_graphql_params(
68
+ db=request.app.state.db, branch=branch_params.branch, at=branch_params.at, service=request.app.state.service
69
+ )
66
70
 
67
71
  result = await graphql(
68
72
  schema=gql_params.schema,
@@ -88,7 +92,7 @@ async def transform_python(
88
92
  )
89
93
 
90
94
  response = await service.workflow.execute_workflow(
91
- workflow=TRANSFORM_PYTHON_RENDER, parameters={"message": message}
95
+ workflow=TRANSFORM_PYTHON_RENDER, context=context, parameters={"message": message}
92
96
  )
93
97
  return JSONResponse(content=response)
94
98
 
@@ -99,6 +103,7 @@ async def transform_jinja2(
99
103
  transform_id: str = Path(description="ID or Name of the Jinja2 Transform to render"),
100
104
  db: InfrahubDatabase = Depends(get_db),
101
105
  branch_params: BranchParams = Depends(get_branch_params),
106
+ context: InfrahubContext = Depends(get_context),
102
107
  _: AccountSession = Depends(get_current_user),
103
108
  ) -> PlainTextResponse:
104
109
  params = {key: value for key, value in request.query_params.items() if key not in ["branch", "at"]}
@@ -122,7 +127,9 @@ async def transform_jinja2(
122
127
  message="Repository doesn't have a commit",
123
128
  )
124
129
 
125
- gql_params = await prepare_graphql_params(db=request.app.state.db, branch=branch_params.branch, at=branch_params.at)
130
+ gql_params = await prepare_graphql_params(
131
+ db=request.app.state.db, branch=branch_params.branch, at=branch_params.at, service=request.app.state.service
132
+ )
126
133
 
127
134
  result = await graphql(
128
135
  schema=gql_params.schema,
@@ -148,6 +155,6 @@ async def transform_jinja2(
148
155
  service: InfrahubServices = request.app.state.service
149
156
 
150
157
  response = await service.workflow.execute_workflow(
151
- workflow=TRANSFORM_JINJA2_RENDER, expected_return=str, parameters={"message": message}
158
+ workflow=TRANSFORM_JINJA2_RENDER, context=context, expected_return=str, parameters={"message": message}
152
159
  )
153
160
  return PlainTextResponse(content=response)
@@ -1,11 +1,11 @@
1
1
  from typing import Optional
2
2
 
3
- from pydantic import Field
3
+ from pydantic import BaseModel, Field
4
4
 
5
- from infrahub.message_bus import InfrahubMessage
5
+ from infrahub.context import InfrahubContext
6
6
 
7
7
 
8
- class CheckArtifactCreate(InfrahubMessage):
8
+ class CheckArtifactCreate(BaseModel):
9
9
  """Runs a check to verify the creation of an artifact."""
10
10
 
11
11
  artifact_name: str = Field(..., description="Name of the artifact")
@@ -19,9 +19,11 @@ class CheckArtifactCreate(InfrahubMessage):
19
19
  repository_kind: str = Field(..., description="The kind of the Repository")
20
20
  branch_name: str = Field(..., description="The branch where the check is run")
21
21
  target_id: str = Field(..., description="The ID of the target object for this artifact")
22
+ target_kind: str = Field(..., description="The kind of the target object for this artifact")
22
23
  target_name: str = Field(..., description="Name of the artifact target")
23
24
  artifact_id: Optional[str] = Field(default=None, description="The id of the artifact if it previously existed")
24
25
  query: str = Field(..., description="The name of the query to use when collecting data")
25
26
  timeout: int = Field(..., description="Timeout for requests used to generate this artifact")
26
27
  variables: dict = Field(..., description="Input variables when generating the artifact")
27
28
  validator_id: str = Field(..., description="The ID of the validator")
29
+ context: InfrahubContext = Field(..., description="The context of the task")
@@ -2,38 +2,38 @@ from typing import Union
2
2
 
3
3
  from prefect import flow
4
4
 
5
+ from infrahub.artifacts.models import CheckArtifactCreate
5
6
  from infrahub.core.constants import InfrahubKind, ValidatorConclusion
6
7
  from infrahub.core.timestamp import Timestamp
7
- from infrahub.git.repository import InfrahubReadOnlyRepository, InfrahubRepository
8
- from infrahub.log import get_logger
9
- from infrahub.message_bus import messages
8
+ from infrahub.git import InfrahubReadOnlyRepository, InfrahubRepository
10
9
  from infrahub.services import InfrahubServices
11
10
  from infrahub.tasks.artifact import define_artifact
12
- from infrahub.tasks.check import set_check_status
13
11
  from infrahub.workflows.utils import add_tags
14
12
 
15
- log = get_logger()
16
-
17
13
 
18
14
  @flow(name="git-repository-check-artifact-create", flow_run_name="Check artifact creation")
19
- async def create(message: messages.CheckArtifactCreate, service: InfrahubServices) -> None:
20
- await add_tags(branches=[message.branch_name], nodes=[message.target_id])
21
- validator = await service.client.get(
22
- kind=InfrahubKind.ARTIFACTVALIDATOR, id=message.validator_id, include=["checks"]
23
- )
15
+ async def create(model: CheckArtifactCreate, service: InfrahubServices) -> ValidatorConclusion:
16
+ await add_tags(branches=[model.branch_name], nodes=[model.target_id])
17
+ validator = await service.client.get(kind=InfrahubKind.ARTIFACTVALIDATOR, id=model.validator_id, include=["checks"])
24
18
 
19
+ repo: InfrahubReadOnlyRepository | InfrahubRepository
25
20
  if InfrahubKind.READONLYREPOSITORY:
26
21
  repo = await InfrahubReadOnlyRepository.init(
27
- id=message.repository_id, name=message.repository_name, client=service.client
22
+ id=model.repository_id,
23
+ name=model.repository_name,
24
+ client=service.client,
25
+ service=service,
28
26
  )
29
27
  else:
30
28
  repo = await InfrahubRepository.init(
31
- id=message.repository_id, name=message.repository_name, client=service.client
29
+ id=model.repository_id,
30
+ name=model.repository_name,
31
+ client=service.client,
32
+ service=service,
32
33
  )
33
34
 
34
- artifact = await define_artifact(message=message, service=service)
35
+ artifact, artifact_created = await define_artifact(model=model, service=service)
35
36
 
36
- conclusion = ValidatorConclusion.SUCCESS.value
37
37
  severity = "info"
38
38
  artifact_result: dict[str, Union[str, bool, None]] = {
39
39
  "changed": None,
@@ -44,22 +44,23 @@ async def create(message: messages.CheckArtifactCreate, service: InfrahubService
44
44
  check_message = "Failed to render artifact"
45
45
 
46
46
  try:
47
- result = await repo.render_artifact(artifact=artifact, message=message)
47
+ result = await repo.render_artifact(artifact=artifact, artifact_created=artifact_created, message=model)
48
48
  artifact_result["changed"] = result.changed
49
49
  artifact_result["checksum"] = result.checksum
50
50
  artifact_result["artifact_id"] = result.artifact_id
51
51
  artifact_result["storage_id"] = result.storage_id
52
52
  check_message = "Artifact rendered successfully"
53
+ conclusion = ValidatorConclusion.SUCCESS
53
54
 
54
- except Exception as exc: # pylint: disable=broad-except
55
- conclusion = ValidatorConclusion.FAILURE.value
55
+ except Exception as exc:
56
56
  artifact.status.value = "Error"
57
+ await artifact.save()
57
58
  severity = "critical"
59
+ conclusion = ValidatorConclusion.FAILURE
58
60
  check_message += f": {str(exc)}"
59
- await artifact.save()
60
61
 
61
62
  check = None
62
- check_name = f"{message.artifact_name}: {message.target_name}"
63
+ check_name = f"{model.artifact_name}: {model.target_name}"
63
64
  existing_check = await service.client.filters(
64
65
  kind=InfrahubKind.ARTIFACTCHECK, validator__ids=validator.id, name__value=check_name
65
66
  )
@@ -68,7 +69,7 @@ async def create(message: messages.CheckArtifactCreate, service: InfrahubService
68
69
 
69
70
  if check:
70
71
  check.created_at.value = Timestamp().to_string()
71
- check.conclusion.value = conclusion
72
+ check.conclusion.value = conclusion.value
72
73
  check.severity.value = severity
73
74
  check.changed.value = artifact_result["changed"]
74
75
  check.checksum.value = artifact_result["checksum"]
@@ -80,12 +81,12 @@ async def create(message: messages.CheckArtifactCreate, service: InfrahubService
80
81
  kind=InfrahubKind.ARTIFACTCHECK,
81
82
  data={
82
83
  "name": check_name,
83
- "origin": message.repository_id,
84
+ "origin": model.repository_id,
84
85
  "kind": "ArtifactDefinition",
85
- "validator": message.validator_id,
86
+ "validator": model.validator_id,
86
87
  "created_at": Timestamp().to_string(),
87
88
  "message": check_message,
88
- "conclusion": conclusion,
89
+ "conclusion": conclusion.value,
89
90
  "severity": severity,
90
91
  "changed": artifact_result["changed"],
91
92
  "checksum": artifact_result["checksum"],
@@ -95,4 +96,4 @@ async def create(message: messages.CheckArtifactCreate, service: InfrahubService
95
96
  )
96
97
  await check.save()
97
98
 
98
- await set_check_status(message=message, conclusion=conclusion, service=service)
99
+ return conclusion
infrahub/cli/__init__.py CHANGED
@@ -12,8 +12,6 @@ from infrahub.cli.tasks import app as tasks_app
12
12
  from infrahub.core.initialization import initialization
13
13
  from infrahub.database import InfrahubDatabase, get_db
14
14
 
15
- # pylint: disable=import-outside-toplevel
16
-
17
15
  app = typer.Typer(name="Infrahub CLI", pretty_exceptions_enable=False)
18
16
 
19
17
 
infrahub/cli/db.py CHANGED
@@ -44,7 +44,7 @@ from infrahub.core.validators.models.validate_migration import SchemaValidateMig
44
44
  from infrahub.core.validators.tasks import schema_validate_migrations
45
45
  from infrahub.database import DatabaseType
46
46
  from infrahub.log import get_logger
47
- from infrahub.services import InfrahubServices, services
47
+ from infrahub.services import InfrahubServices
48
48
  from infrahub.services.adapters.message_bus.local import BusSimulator
49
49
  from infrahub.services.adapters.workflow.local import WorkflowLocalExecution
50
50
 
@@ -193,7 +193,7 @@ async def migrate(
193
193
 
194
194
 
195
195
  @app.command()
196
- async def update_core_schema( # pylint: disable=too-many-statements
196
+ async def update_core_schema(
197
197
  ctx: typer.Context,
198
198
  debug: bool = typer.Option(False, help="Enable advanced logging and troubleshooting"),
199
199
  config_file: str = typer.Argument("infrahub.toml", envvar="INFRAHUB_CONFIG"),
@@ -216,10 +216,9 @@ async def update_core_schema( # pylint: disable=too-many-statements
216
216
  # ----------------------------------------------------------
217
217
  # Initialize Schema and Registry
218
218
  # ----------------------------------------------------------
219
- service = InfrahubServices(
220
- database=db, message_bus=BusSimulator(database=db), workflow=WorkflowLocalExecution()
219
+ service = await InfrahubServices.new(
220
+ database=db, message_bus=BusSimulator(), workflow=WorkflowLocalExecution()
221
221
  )
222
- services.prepare(service)
223
222
  await initialize_registry(db=db)
224
223
 
225
224
  default_branch = registry.get_branch_from_registry(branch=registry.default_branch)
@@ -269,7 +268,7 @@ async def update_core_schema( # pylint: disable=too-many-statements
269
268
  schema_branch=candidate_schema,
270
269
  constraints=result.constraints,
271
270
  )
272
- responses = await schema_validate_migrations(message=validate_migration_data)
271
+ responses = await schema_validate_migrations(message=validate_migration_data, service=service)
273
272
  error_messages = [violation.message for response in responses for violation in response.violations]
274
273
  if error_messages:
275
274
  rprint(f"{error_badge} | Unable to update the schema, due to failed validations")
@@ -311,7 +310,7 @@ async def update_core_schema( # pylint: disable=too-many-statements
311
310
  previous_schema=origin_schema,
312
311
  migrations=result.migrations,
313
312
  )
314
- migration_error_msgs = await schema_apply_migrations(message=apply_migration_data)
313
+ migration_error_msgs = await schema_apply_migrations(message=apply_migration_data, service=service)
315
314
 
316
315
  if migration_error_msgs:
317
316
  rprint(f"{error_badge} | Some error(s) happened while running the schema migrations")
infrahub/cli/events.py CHANGED
@@ -7,6 +7,7 @@ from infrahub_sdk.async_typer import AsyncTyper
7
7
  from rich import print as rprint
8
8
 
9
9
  from infrahub import config
10
+ from infrahub.components import ComponentType
10
11
  from infrahub.services import InfrahubServices
11
12
  from infrahub.services.adapters.message_bus.rabbitmq import RabbitMQMessageBus
12
13
 
@@ -24,9 +25,13 @@ async def listen(
24
25
  ) -> None:
25
26
  """Listen to event in the Events bus and print them."""
26
27
  config.load_and_exit(config_file)
27
- broker = RabbitMQMessageBus()
28
- service = InfrahubServices()
29
- await broker.initialize(service=service)
28
+
29
+ # Below code seems to be a duplicate of `RabbitMQMessageBus._initialize_api_server`.
30
+ # Also, here we are using ComponentType.NONE so RabbitMQMessageBus will NOT instantiate connection.
31
+ # We might want to factorize here and use ComponentType.GitAgent so broker instantiates connection correctly.
32
+ component_type = ComponentType.NONE
33
+ broker = await RabbitMQMessageBus.new(component_type=component_type)
34
+ _ = await InfrahubServices.new(message_bus=broker, component_type=component_type)
30
35
 
31
36
  queue = await broker.channel.declare_queue(exclusive=True)
32
37
  exchange_name = f"{config.SETTINGS.broker.namespace}.events"
infrahub/cli/git_agent.py CHANGED
@@ -36,7 +36,7 @@ log = get_logger()
36
36
  shutdown_event = asyncio.Event()
37
37
 
38
38
 
39
- def signal_handler(*args: Any, **kwargs: Any) -> None: # pylint: disable=unused-argument
39
+ def signal_handler(*args: Any, **kwargs: Any) -> None: # noqa: ARG001
40
40
  shutdown_event.set()
41
41
 
42
42
 
@@ -99,7 +99,7 @@ async def start(
99
99
  await client.branch.all()
100
100
  except SdkError as exc:
101
101
  log.error(f"Error in communication with Infrahub: {exc.message}")
102
- raise typer.Exit(1)
102
+ raise typer.Exit(1) from None
103
103
 
104
104
  # Initialize trace
105
105
  if config.SETTINGS.trace.enable:
@@ -119,22 +119,24 @@ async def start(
119
119
  else WorkflowLocalExecution()
120
120
  )
121
121
 
122
+ component_type = ComponentType.GIT_AGENT
122
123
  message_bus = config.OVERRIDE.message_bus or (
123
- NATSMessageBus() if config.SETTINGS.broker.driver == config.BrokerDriver.NATS else RabbitMQMessageBus()
124
+ await NATSMessageBus.new(component_type=component_type)
125
+ if config.SETTINGS.broker.driver == config.BrokerDriver.NATS
126
+ else await RabbitMQMessageBus.new(component_type=component_type)
124
127
  )
125
128
  cache = config.OVERRIDE.cache or (
126
- NATSCache() if config.SETTINGS.cache.driver == config.CacheDriver.NATS else RedisCache()
129
+ await NATSCache.new() if config.SETTINGS.cache.driver == config.CacheDriver.NATS else RedisCache()
127
130
  )
128
131
 
129
- service = InfrahubServices(
132
+ service = await InfrahubServices.new(
130
133
  cache=cache,
131
134
  client=client,
132
135
  database=database,
133
136
  workflow=workflow,
134
137
  message_bus=message_bus,
135
- component_type=ComponentType.GIT_AGENT,
138
+ component_type=component_type,
136
139
  )
137
- await service.initialize()
138
140
 
139
141
  # Initialize the lock
140
142
  initialize_lock(service=service)