infrahub-server 1.1.6__py3-none-any.whl → 1.2.0rc0__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 (346) 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} +2 -4
  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/tasks.py +63 -17
  16. infrahub/computed_attribute/triggers.py +90 -0
  17. infrahub/config.py +1 -1
  18. infrahub/context.py +39 -0
  19. infrahub/core/account.py +5 -8
  20. infrahub/core/attribute.py +53 -21
  21. infrahub/core/branch/models.py +4 -4
  22. infrahub/core/branch/tasks.py +89 -130
  23. infrahub/core/changelog/__init__.py +0 -0
  24. infrahub/core/changelog/diff.py +232 -0
  25. infrahub/core/changelog/models.py +488 -0
  26. infrahub/core/constants/__init__.py +19 -2
  27. infrahub/core/constants/infrahubkind.py +1 -0
  28. infrahub/core/diff/combiner.py +12 -8
  29. infrahub/core/diff/coordinator.py +49 -70
  30. infrahub/core/diff/data_check_synchronizer.py +86 -7
  31. infrahub/core/diff/enricher/aggregated.py +3 -3
  32. infrahub/core/diff/enricher/cardinality_one.py +2 -7
  33. infrahub/core/diff/enricher/hierarchy.py +5 -3
  34. infrahub/core/diff/enricher/labels.py +14 -4
  35. infrahub/core/diff/enricher/path_identifier.py +3 -9
  36. infrahub/core/diff/enricher/summary_counts.py +3 -1
  37. infrahub/core/diff/merger/merger.py +8 -4
  38. infrahub/core/diff/model/path.py +47 -29
  39. infrahub/core/diff/query/all_conflicts.py +6 -3
  40. infrahub/core/diff/query/artifact.py +1 -1
  41. infrahub/core/diff/query/delete_query.py +1 -1
  42. infrahub/core/diff/query/diff_get.py +3 -2
  43. infrahub/core/diff/query/diff_summary.py +1 -1
  44. infrahub/core/diff/query/field_specifiers.py +3 -1
  45. infrahub/core/diff/query/field_summary.py +3 -2
  46. infrahub/core/diff/query/filters.py +12 -1
  47. infrahub/core/diff/query/get_conflict_query.py +1 -1
  48. infrahub/core/diff/query/has_conflicts_query.py +6 -3
  49. infrahub/core/diff/query/merge.py +3 -3
  50. infrahub/core/diff/query/{drop_tracking_id.py → merge_tracking_id.py} +4 -4
  51. infrahub/core/diff/query/roots_metadata.py +9 -2
  52. infrahub/core/diff/query/save.py +151 -66
  53. infrahub/core/diff/query/summary_counts_enricher.py +220 -0
  54. infrahub/core/diff/query/time_range_query.py +3 -2
  55. infrahub/core/diff/query/update_conflict_query.py +1 -1
  56. infrahub/core/diff/query_parser.py +49 -24
  57. infrahub/core/diff/repository/deserializer.py +24 -25
  58. infrahub/core/diff/repository/repository.py +76 -20
  59. infrahub/core/diff/tasks.py +9 -8
  60. infrahub/core/enums.py +1 -1
  61. infrahub/core/integrity/object_conflict/conflict_recorder.py +1 -1
  62. infrahub/core/ipam/reconciler.py +1 -1
  63. infrahub/core/ipam/tasks.py +2 -3
  64. infrahub/core/manager.py +18 -13
  65. infrahub/core/merge.py +5 -2
  66. infrahub/core/migrations/graph/m001_add_version_to_graph.py +1 -1
  67. infrahub/core/migrations/graph/m002_attribute_is_default.py +2 -2
  68. infrahub/core/migrations/graph/m003_relationship_parent_optional.py +2 -2
  69. infrahub/core/migrations/graph/m004_add_attr_documentation.py +1 -1
  70. infrahub/core/migrations/graph/m005_add_rel_read_only.py +1 -1
  71. infrahub/core/migrations/graph/m006_add_rel_on_delete.py +1 -1
  72. infrahub/core/migrations/graph/m007_add_rel_allow_override.py +1 -1
  73. infrahub/core/migrations/graph/m008_add_human_friendly_id.py +1 -1
  74. infrahub/core/migrations/graph/m009_add_generate_profile_attr.py +1 -1
  75. infrahub/core/migrations/graph/m010_add_generate_profile_attr_generic.py +1 -1
  76. infrahub/core/migrations/graph/m011_remove_profile_relationship_schema.py +2 -2
  77. infrahub/core/migrations/graph/m012_convert_account_generic.py +12 -23
  78. infrahub/core/migrations/graph/m013_convert_git_password_credential.py +7 -11
  79. infrahub/core/migrations/graph/m014_remove_index_attr_value.py +2 -2
  80. infrahub/core/migrations/graph/m015_diff_format_update.py +1 -1
  81. infrahub/core/migrations/graph/m016_diff_delete_bug_fix.py +1 -1
  82. infrahub/core/migrations/graph/m017_add_core_profile.py +1 -1
  83. infrahub/core/migrations/graph/m018_uniqueness_nulls.py +2 -2
  84. infrahub/core/migrations/query/attribute_add.py +1 -1
  85. infrahub/core/migrations/query/attribute_rename.py +1 -1
  86. infrahub/core/migrations/query/delete_element_in_schema.py +1 -1
  87. infrahub/core/migrations/query/node_duplicate.py +1 -1
  88. infrahub/core/migrations/query/relationship_duplicate.py +1 -1
  89. infrahub/core/migrations/query/schema_attribute_update.py +1 -1
  90. infrahub/core/migrations/schema/node_attribute_remove.py +1 -1
  91. infrahub/core/migrations/schema/node_remove.py +1 -1
  92. infrahub/core/migrations/schema/tasks.py +5 -5
  93. infrahub/core/migrations/shared.py +4 -4
  94. infrahub/core/models.py +7 -8
  95. infrahub/core/node/__init__.py +161 -40
  96. infrahub/core/node/base.py +1 -1
  97. infrahub/core/node/constraints/grouped_uniqueness.py +9 -2
  98. infrahub/core/node/delete_validator.py +4 -4
  99. infrahub/core/node/ipam.py +13 -8
  100. infrahub/core/node/permissions.py +4 -0
  101. infrahub/core/node/resource_manager/ip_prefix_pool.py +8 -5
  102. infrahub/core/node/standard.py +3 -5
  103. infrahub/core/property.py +1 -1
  104. infrahub/core/protocols.py +4 -0
  105. infrahub/core/protocols_base.py +4 -2
  106. infrahub/core/query/__init__.py +2 -5
  107. infrahub/core/query/attribute.py +9 -9
  108. infrahub/core/query/branch.py +5 -5
  109. infrahub/core/query/delete.py +1 -1
  110. infrahub/core/query/diff.py +45 -7
  111. infrahub/core/query/ipam.py +4 -4
  112. infrahub/core/query/node.py +19 -14
  113. infrahub/core/query/relationship.py +10 -11
  114. infrahub/core/query/resource_manager.py +13 -11
  115. infrahub/core/query/standard_node.py +6 -6
  116. infrahub/core/query/task.py +3 -3
  117. infrahub/core/query/task_log.py +1 -1
  118. infrahub/core/query/utils.py +5 -5
  119. infrahub/core/registry.py +0 -2
  120. infrahub/core/relationship/constraints/count.py +1 -1
  121. infrahub/core/relationship/constraints/peer_kind.py +1 -1
  122. infrahub/core/relationship/model.py +66 -26
  123. infrahub/core/schema/__init__.py +6 -4
  124. infrahub/core/schema/basenode_schema.py +1 -3
  125. infrahub/core/schema/definitions/core.py +14 -2
  126. infrahub/core/schema/definitions/internal.py +16 -0
  127. infrahub/core/schema/generated/genericnode_schema.py +5 -0
  128. infrahub/core/schema/generated/node_schema.py +5 -0
  129. infrahub/core/schema/generic_schema.py +5 -1
  130. infrahub/core/schema/manager.py +45 -42
  131. infrahub/core/schema/node_schema.py +4 -0
  132. infrahub/core/schema/profile_schema.py +4 -0
  133. infrahub/core/schema/relationship_schema.py +2 -2
  134. infrahub/core/schema/schema_branch.py +248 -14
  135. infrahub/core/schema/template_schema.py +36 -0
  136. infrahub/core/task/user_task.py +7 -5
  137. infrahub/core/timestamp.py +1 -1
  138. infrahub/core/utils.py +3 -2
  139. infrahub/core/validators/attribute/choices.py +1 -1
  140. infrahub/core/validators/attribute/enum.py +1 -1
  141. infrahub/core/validators/attribute/kind.py +1 -1
  142. infrahub/core/validators/attribute/length.py +1 -1
  143. infrahub/core/validators/attribute/optional.py +1 -1
  144. infrahub/core/validators/attribute/regex.py +1 -1
  145. infrahub/core/validators/attribute/unique.py +1 -1
  146. infrahub/core/validators/checks_runner.py +37 -0
  147. infrahub/core/validators/node/generate_profile.py +1 -1
  148. infrahub/core/validators/node/hierarchy.py +1 -1
  149. infrahub/core/validators/query.py +1 -1
  150. infrahub/core/validators/relationship/count.py +1 -1
  151. infrahub/core/validators/relationship/optional.py +1 -1
  152. infrahub/core/validators/relationship/peer.py +1 -1
  153. infrahub/core/validators/tasks.py +8 -6
  154. infrahub/core/validators/uniqueness/query.py +20 -17
  155. infrahub/database/__init__.py +15 -2
  156. infrahub/database/memgraph.py +1 -1
  157. infrahub/dependencies/builder/constraint/grouped/node_runner.py +0 -2
  158. infrahub/dependencies/builder/diff/combiner.py +1 -1
  159. infrahub/dependencies/builder/diff/conflicts_enricher.py +1 -1
  160. infrahub/dependencies/builder/diff/coordinator.py +0 -2
  161. infrahub/dependencies/builder/diff/deserializer.py +1 -1
  162. infrahub/dependencies/builder/diff/enricher/summary_counts.py +1 -1
  163. infrahub/events/branch_action.py +47 -21
  164. infrahub/events/group_action.py +73 -0
  165. infrahub/events/models.py +159 -51
  166. infrahub/events/node_action.py +74 -8
  167. infrahub/events/repository_action.py +8 -8
  168. infrahub/events/schema_action.py +21 -8
  169. infrahub/generators/tasks.py +12 -13
  170. infrahub/git/base.py +3 -5
  171. infrahub/git/constants.py +0 -1
  172. infrahub/git/integrator.py +36 -35
  173. infrahub/git/repository.py +7 -8
  174. infrahub/git/tasks.py +43 -107
  175. infrahub/git_credential/helper.py +2 -3
  176. infrahub/graphql/analyzer.py +572 -11
  177. infrahub/graphql/app.py +34 -26
  178. infrahub/graphql/auth/query_permission_checker/anonymous_checker.py +5 -5
  179. infrahub/graphql/auth/query_permission_checker/default_branch_checker.py +4 -4
  180. infrahub/graphql/auth/query_permission_checker/merge_operation_checker.py +4 -4
  181. infrahub/graphql/auth/query_permission_checker/object_permission_checker.py +28 -35
  182. infrahub/graphql/auth/query_permission_checker/super_admin_checker.py +5 -5
  183. infrahub/graphql/enums.py +1 -1
  184. infrahub/graphql/initialization.py +5 -1
  185. infrahub/graphql/loaders/node.py +2 -2
  186. infrahub/graphql/manager.py +59 -54
  187. infrahub/graphql/mutations/account.py +20 -13
  188. infrahub/graphql/mutations/artifact_definition.py +16 -12
  189. infrahub/graphql/mutations/branch.py +61 -40
  190. infrahub/graphql/mutations/computed_attribute.py +19 -13
  191. infrahub/graphql/mutations/diff.py +37 -9
  192. infrahub/graphql/mutations/diff_conflict.py +9 -8
  193. infrahub/graphql/mutations/graphql_query.py +19 -11
  194. infrahub/graphql/mutations/ipam.py +21 -19
  195. infrahub/graphql/mutations/main.py +197 -44
  196. infrahub/graphql/mutations/menu.py +8 -8
  197. infrahub/graphql/mutations/proposed_change.py +36 -28
  198. infrahub/graphql/mutations/relationship.py +302 -105
  199. infrahub/graphql/mutations/repository.py +41 -35
  200. infrahub/graphql/mutations/resource_manager.py +26 -26
  201. infrahub/graphql/mutations/schema.py +51 -33
  202. infrahub/graphql/mutations/tasks.py +16 -10
  203. infrahub/graphql/parser.py +1 -1
  204. infrahub/graphql/permissions.py +6 -4
  205. infrahub/graphql/queries/account.py +22 -18
  206. infrahub/graphql/queries/branch.py +6 -4
  207. infrahub/graphql/queries/diff/tree.py +48 -42
  208. infrahub/graphql/queries/event.py +112 -0
  209. infrahub/graphql/queries/internal.py +3 -3
  210. infrahub/graphql/queries/ipam.py +23 -18
  211. infrahub/graphql/queries/relationship.py +11 -10
  212. infrahub/graphql/queries/resource_manager.py +43 -27
  213. infrahub/graphql/queries/search.py +9 -8
  214. infrahub/graphql/queries/status.py +12 -9
  215. infrahub/graphql/queries/task.py +11 -9
  216. infrahub/graphql/resolvers/resolver.py +69 -43
  217. infrahub/graphql/resolvers/single_relationship.py +16 -10
  218. infrahub/graphql/schema.py +2 -0
  219. infrahub/graphql/subscription/__init__.py +1 -1
  220. infrahub/graphql/subscription/events.py +1 -1
  221. infrahub/graphql/subscription/graphql_query.py +8 -8
  222. infrahub/graphql/types/branch.py +2 -2
  223. infrahub/graphql/types/common.py +6 -1
  224. infrahub/graphql/types/enums.py +2 -0
  225. infrahub/graphql/types/event.py +100 -0
  226. infrahub/graphql/types/interface.py +2 -2
  227. infrahub/graphql/types/node.py +3 -3
  228. infrahub/graphql/types/permission.py +2 -2
  229. infrahub/graphql/types/relationship.py +3 -3
  230. infrahub/graphql/types/standard_node.py +9 -11
  231. infrahub/graphql/utils.py +28 -182
  232. infrahub/groups/tasks.py +2 -3
  233. infrahub/lock.py +1 -1
  234. infrahub/menu/constants.py +1 -0
  235. infrahub/menu/generator.py +14 -3
  236. infrahub/menu/menu.py +116 -127
  237. infrahub/menu/models.py +4 -4
  238. infrahub/message_bus/messages/__init__.py +0 -4
  239. infrahub/message_bus/messages/event_branch_merge.py +3 -0
  240. infrahub/message_bus/messages/request_proposedchange_pipeline.py +2 -0
  241. infrahub/message_bus/operations/__init__.py +3 -5
  242. infrahub/message_bus/operations/check/__init__.py +2 -2
  243. infrahub/message_bus/operations/check/generator.py +1 -3
  244. infrahub/message_bus/operations/check/repository.py +1 -1
  245. infrahub/message_bus/operations/event/branch.py +7 -3
  246. infrahub/message_bus/operations/event/schema.py +1 -1
  247. infrahub/message_bus/operations/finalize/validator.py +1 -1
  248. infrahub/message_bus/operations/git/file.py +2 -2
  249. infrahub/message_bus/operations/git/repository.py +1 -1
  250. infrahub/message_bus/operations/requests/__init__.py +0 -2
  251. infrahub/message_bus/operations/requests/generator_definition.py +1 -1
  252. infrahub/message_bus/operations/requests/proposed_change.py +26 -11
  253. infrahub/message_bus/operations/requests/repository.py +2 -2
  254. infrahub/message_bus/operations/send/echo.py +1 -1
  255. infrahub/message_bus/types.py +1 -1
  256. infrahub/permissions/__init__.py +2 -1
  257. infrahub/permissions/types.py +26 -0
  258. infrahub/pools/prefix.py +29 -165
  259. infrahub/prefect_server/__init__.py +0 -0
  260. infrahub/prefect_server/app.py +18 -0
  261. infrahub/prefect_server/database.py +20 -0
  262. infrahub/prefect_server/events.py +28 -0
  263. infrahub/prefect_server/models.py +46 -0
  264. infrahub/proposed_change/models.py +15 -1
  265. infrahub/proposed_change/tasks.py +173 -35
  266. infrahub/pytest_plugin.py +4 -4
  267. infrahub/server.py +12 -11
  268. infrahub/services/__init__.py +147 -62
  269. infrahub/services/adapters/cache/__init__.py +7 -5
  270. infrahub/services/adapters/cache/nats.py +40 -22
  271. infrahub/services/adapters/cache/redis.py +0 -4
  272. infrahub/services/adapters/event/__init__.py +10 -18
  273. infrahub/services/adapters/http/__init__.py +0 -5
  274. infrahub/services/adapters/http/httpx.py +22 -15
  275. infrahub/services/adapters/message_bus/__init__.py +23 -6
  276. infrahub/services/adapters/message_bus/local.py +8 -6
  277. infrahub/services/adapters/message_bus/nats.py +12 -6
  278. infrahub/services/adapters/message_bus/rabbitmq.py +22 -9
  279. infrahub/services/adapters/workflow/__init__.py +11 -8
  280. infrahub/services/adapters/workflow/local.py +28 -7
  281. infrahub/services/adapters/workflow/worker.py +23 -7
  282. infrahub/services/component.py +38 -35
  283. infrahub/services/scheduler.py +32 -29
  284. infrahub/storage.py +2 -4
  285. infrahub/task_manager/constants.py +1 -1
  286. infrahub/task_manager/event.py +182 -0
  287. infrahub/task_manager/models.py +125 -1
  288. infrahub/task_manager/task.py +1 -1
  289. infrahub/tasks/artifact.py +14 -16
  290. infrahub/tasks/registry.py +1 -1
  291. infrahub/tasks/telemetry.py +13 -14
  292. infrahub/transformations/tasks.py +3 -5
  293. infrahub/trigger/__init__.py +0 -0
  294. infrahub/trigger/catalogue.py +15 -0
  295. infrahub/trigger/constants.py +9 -0
  296. infrahub/trigger/models.py +69 -0
  297. infrahub/trigger/tasks.py +85 -0
  298. infrahub/types.py +1 -1
  299. infrahub/utils.py +1 -1
  300. infrahub/webhook/constants.py +0 -2
  301. infrahub/webhook/models.py +8 -2
  302. infrahub/webhook/tasks.py +20 -73
  303. infrahub/webhook/triggers.py +20 -0
  304. infrahub/workers/infrahub_async.py +36 -25
  305. infrahub/workers/utils.py +63 -0
  306. infrahub/workflows/catalogue.py +13 -37
  307. infrahub/workflows/initialization.py +6 -8
  308. infrahub/workflows/models.py +3 -5
  309. infrahub/workflows/utils.py +1 -1
  310. infrahub_sdk/ctl/check.py +3 -3
  311. infrahub_sdk/ctl/cli_commands.py +11 -10
  312. infrahub_sdk/ctl/exceptions.py +0 -6
  313. infrahub_sdk/ctl/exporter.py +1 -1
  314. infrahub_sdk/ctl/generator.py +5 -5
  315. infrahub_sdk/ctl/importer.py +3 -2
  316. infrahub_sdk/ctl/menu.py +1 -1
  317. infrahub_sdk/ctl/object.py +1 -1
  318. infrahub_sdk/ctl/repository.py +23 -15
  319. infrahub_sdk/ctl/schema.py +2 -2
  320. infrahub_sdk/ctl/utils.py +4 -3
  321. infrahub_sdk/ctl/validate.py +2 -1
  322. infrahub_sdk/exceptions.py +6 -0
  323. infrahub_sdk/generator.py +3 -0
  324. infrahub_sdk/node.py +2 -2
  325. infrahub_sdk/schema/__init__.py +14 -2
  326. infrahub_sdk/schema/main.py +7 -0
  327. infrahub_sdk/utils.py +11 -1
  328. infrahub_sdk/yaml.py +2 -3
  329. {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/METADATA +46 -12
  330. {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/RECORD +338 -321
  331. infrahub_testcontainers/container.py +14 -6
  332. infrahub_testcontainers/docker-compose.test.yml +24 -5
  333. infrahub_testcontainers/haproxy.cfg +43 -0
  334. infrahub_testcontainers/helpers.py +85 -1
  335. infrahub/core/branch/constants.py +0 -2
  336. infrahub/graphql/query.py +0 -52
  337. infrahub/message_bus/messages/request_artifactdefinition_check.py +0 -17
  338. infrahub/message_bus/operations/requests/artifact_definition.py +0 -148
  339. infrahub/schema/constants.py +0 -1
  340. infrahub/schema/tasks.py +0 -76
  341. infrahub/services/adapters/database/__init__.py +0 -9
  342. infrahub_sdk/ctl/_file.py +0 -13
  343. /infrahub/{schema → artifacts}/__init__.py +0 -0
  344. {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/LICENSE.txt +0 -0
  345. {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/WHEEL +0 -0
  346. {infrahub_server-1.1.6.dist-info → infrahub_server-1.2.0rc0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,85 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ from infrahub_sdk.utils import compare_lists
4
+ from prefect import get_run_logger, task
5
+ from prefect.automations import AutomationCore
6
+ from prefect.cache_policies import NONE
7
+ from prefect.client.orchestration import PrefectClient
8
+ from prefect.client.schemas.filters import DeploymentFilter, DeploymentFilterName
9
+
10
+ from .catalogue import triggers
11
+ from .constants import DEPRECATED_STATIC_TRIGGER_NAMES
12
+ from .models import TriggerType
13
+
14
+ if TYPE_CHECKING:
15
+ from uuid import UUID
16
+
17
+
18
+ @task(name="trigger-setup", task_run_name="Setup triggers in task-manager", cache_policy=NONE) # type: ignore[arg-type]
19
+ async def setup_triggers(client: PrefectClient) -> None:
20
+ log = get_run_logger()
21
+
22
+ # -------------------------------------------------------------
23
+ # Retrieve existing Deployments and Automation from the server
24
+ # -------------------------------------------------------------
25
+ deployment_names = list({name for trigger in triggers for name in trigger.get_deployment_names()})
26
+ deployments = {
27
+ item.name: item
28
+ for item in await client.read_deployments(
29
+ deployment_filter=DeploymentFilter(name=DeploymentFilterName(any_=deployment_names))
30
+ )
31
+ }
32
+ deployments_mapping: dict[str, UUID] = {name: item.id for name, item in deployments.items()}
33
+ existing_automations = {item.name: item for item in await client.read_automations()}
34
+
35
+ builtin_automations = [
36
+ item.name for item in await client.read_automations() if item.name.startswith(TriggerType.BUILTIN.value)
37
+ ]
38
+ trigger_names = [trigger.generate_name() for trigger in triggers]
39
+
40
+ _, to_delete, _ = compare_lists(list1=builtin_automations, list2=trigger_names)
41
+
42
+ # -------------------------------------------------------------
43
+ # Create or Update all builtin triggers
44
+ # -------------------------------------------------------------
45
+ for trigger in triggers:
46
+ automation = AutomationCore(
47
+ name=trigger.generate_name(),
48
+ description=trigger.description,
49
+ enabled=True,
50
+ trigger=trigger.trigger.get_prefect(),
51
+ actions=[action.get_prefect(mapping=deployments_mapping) for action in trigger.actions],
52
+ )
53
+
54
+ existing_automation = existing_automations.get(trigger.name, None)
55
+
56
+ if existing_automation:
57
+ await client.update_automation(automation_id=existing_automation.id, automation=automation)
58
+ log.info(f"{trigger.name} Updated")
59
+ else:
60
+ await client.create_automation(automation=automation)
61
+ log.info(f"{trigger.name} Created")
62
+
63
+ # -------------------------------------------------------------
64
+ # Delete Builtin Triggers that shouldn't be there
65
+ # -------------------------------------------------------------
66
+ for item_to_delete in to_delete:
67
+ existing_automation = existing_automations.get(item_to_delete)
68
+
69
+ if not existing_automation:
70
+ continue
71
+
72
+ await client.delete_automation(automation_id=existing_automation.id)
73
+ log.info(f"{item_to_delete} Deleted")
74
+
75
+ # -------------------------------------------------------------
76
+ # Delete Deprecated triggers
77
+ # -------------------------------------------------------------
78
+ for trigger_name in DEPRECATED_STATIC_TRIGGER_NAMES:
79
+ existing_automation = existing_automations.get(trigger_name)
80
+
81
+ if not existing_automation:
82
+ continue
83
+
84
+ await client.delete_automation(automation_id=existing_automation.id)
85
+ log.info(f"{trigger_name} Deleted")
infrahub/types.py CHANGED
@@ -354,7 +354,7 @@ ATTRIBUTE_PYTHON_TYPES: dict[str, type] = {
354
354
  "Color": str, # Colors often represented as hex strings
355
355
  "Number": float, # Numbers can be floats for general use
356
356
  "Bandwidth": float, # Bandwidth in some units, represented as a float
357
- "IPHost": IPvAnyAddress,
357
+ "IPHost": IPvAnyAddress, # type: ignore[dict-item]
358
358
  "IPNetwork": str,
359
359
  "Boolean": bool,
360
360
  "Checkbox": bool, # Checkboxes represent boolean values
infrahub/utils.py CHANGED
@@ -36,7 +36,7 @@ def format_label(slug: str) -> str:
36
36
  class MetaEnum(EnumMeta):
37
37
  def __contains__(cls, item: Any) -> bool:
38
38
  try:
39
- cls(item) # pylint: disable=no-value-for-parameter
39
+ cls(item)
40
40
  except ValueError:
41
41
  return False
42
42
  return True
@@ -1,3 +1 @@
1
- AUTOMATION_NAME = "Trigger-webhook-update-configuration"
2
-
3
1
  AUTOMATION_NAME_RUN = "Trigger-webhook-execution"
@@ -87,11 +87,17 @@ class TransformWebhook(Webhook):
87
87
  repo: Union[InfrahubReadOnlyRepository, InfrahubRepository]
88
88
  if self.repository_kind == InfrahubKind.READONLYREPOSITORY:
89
89
  repo = await InfrahubReadOnlyRepository.init(
90
- id=self.repository_id, name=self.repository_name, client=self.service.client
90
+ id=self.repository_id,
91
+ name=self.repository_name,
92
+ client=self.service.client,
93
+ service=self.service,
91
94
  )
92
95
  else:
93
96
  repo = await InfrahubRepository.init(
94
- id=self.repository_id, name=self.repository_name, client=self.service.client
97
+ id=self.repository_id,
98
+ name=self.repository_name,
99
+ client=self.service.client,
100
+ service=self.service,
95
101
  )
96
102
 
97
103
  default_branch = repo.default_branch
infrahub/webhook/tasks.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from datetime import timedelta
2
- from typing import Any
2
+ from typing import TYPE_CHECKING, Any
3
3
 
4
4
  import ujson
5
5
  from infrahub_sdk.protocols import CoreCustomWebhook, CoreStandardWebhook, CoreTransformPython
@@ -12,18 +12,20 @@ from prefect.events.schemas.automations import EventTrigger, Posture
12
12
  from prefect.events.schemas.events import ResourceSpecification
13
13
  from prefect.logging import get_run_logger
14
14
 
15
- from infrahub.core.constants import InfrahubKind, MutationAction
15
+ from infrahub.core.constants import MutationAction
16
16
  from infrahub.exceptions import NodeNotFoundError
17
- from infrahub.services import services
18
- from infrahub.workflows.catalogue import WEBHOOK_CONFIGURE, WEBHOOK_SEND, WEBHOOK_TRIGGER
17
+ from infrahub.services import InfrahubServices
18
+ from infrahub.workflows.catalogue import WEBHOOK_SEND, WEBHOOK_TRIGGER
19
19
 
20
- from .constants import AUTOMATION_NAME, AUTOMATION_NAME_RUN
20
+ from .constants import AUTOMATION_NAME_RUN
21
21
  from .models import CustomWebhook, SendWebhookData, StandardWebhook, TransformWebhook, Webhook
22
22
 
23
+ if TYPE_CHECKING:
24
+ from prefect.events.schemas.automations import Automation
25
+
23
26
 
24
27
  @flow(name="event-send-webhook", flow_run_name="Send Webhook")
25
- async def send_webhook(model: SendWebhookData) -> None:
26
- service = services.service
28
+ async def send_webhook(model: SendWebhookData, service: InfrahubServices) -> None:
27
29
  log = get_run_logger()
28
30
 
29
31
  webhook_definition = await service.cache.get(key=f"webhook:active:{model.webhook_id}")
@@ -49,20 +51,16 @@ async def send_webhook(model: SendWebhookData) -> None:
49
51
 
50
52
 
51
53
  @flow(name="webhook-trigger-actions", flow_run_name="Trigger configured webhooks")
52
- async def trigger_webhooks(event_type: str, event_data: str) -> None:
53
- service = services.service
54
- payload: dict = ujson.loads(event_data)
55
-
54
+ async def trigger_webhooks(event_type: str, event_data: dict, service: InfrahubServices) -> None:
56
55
  webhooks = await service.cache.list_keys(filter_pattern="webhook:active:*")
57
56
  for webhook in webhooks:
58
57
  webhook_id = webhook.split(":")[-1]
59
- model = SendWebhookData(webhook_id=webhook_id, event_type=event_type, event_data=payload)
58
+ model = SendWebhookData(webhook_id=webhook_id, event_type=event_type, event_data=event_data)
60
59
  await service.workflow.submit_workflow(workflow=WEBHOOK_SEND, parameters={"model": model})
61
60
 
62
61
 
63
62
  @flow(name="webhook-setup-automations", flow_run_name="Configuration webhook automation and populate cache")
64
- async def configure_webhooks() -> None:
65
- service = services.service
63
+ async def configure_webhooks(service: InfrahubServices) -> None:
66
64
  log = get_run_logger()
67
65
 
68
66
  log.debug("Refreshing webhook configuration")
@@ -135,7 +133,10 @@ async def configure_webhooks() -> None:
135
133
 
136
134
  deployment_id_webhook_trigger = deployments[WEBHOOK_TRIGGER.name].id
137
135
 
138
- webhook_configure_automation = await client.find_automation(id_or_name=AUTOMATION_NAME_RUN)
136
+ webhook_configure_automation: Automation | None = None
137
+ automations = await client.read_automations_by_name(name=AUTOMATION_NAME_RUN)
138
+ if automations:
139
+ webhook_configure_automation = automations[0]
139
140
 
140
141
  if not has_webhooks:
141
142
  if webhook_configure_automation:
@@ -163,7 +164,10 @@ async def configure_webhooks() -> None:
163
164
  deployment_id=deployment_id_webhook_trigger,
164
165
  parameters={
165
166
  "event_type": "{{ event.resource['infrahub.node.kind'] }}.{{ event.resource['infrahub.node.action'] }}",
166
- "event_data": "{{ event.payload['data'] | tojson }}",
167
+ "event_data": {
168
+ "__prefect_kind": "json",
169
+ "value": {"__prefect_kind": "jinja", "template": "{{ event.payload['data'] | tojson }}"},
170
+ },
167
171
  },
168
172
  job_variables={},
169
173
  ),
@@ -176,60 +180,3 @@ async def configure_webhooks() -> None:
176
180
  else:
177
181
  await client.create_automation(automation=automation)
178
182
  log.info(f"{AUTOMATION_NAME_RUN} Created")
179
-
180
-
181
- @flow(name="webhook-setup-configuration-trigger", flow_run_name="Setup automations for webhooks")
182
- async def trigger_webhook_configuration() -> None:
183
- log = get_run_logger()
184
-
185
- async with get_client(sync_client=False) as client:
186
- deployments = {
187
- item.name: item
188
- for item in await client.read_deployments(
189
- deployment_filter=DeploymentFilter(
190
- name=DeploymentFilterName(
191
- any_=[
192
- WEBHOOK_CONFIGURE.name,
193
- ]
194
- )
195
- )
196
- )
197
- }
198
- if WEBHOOK_CONFIGURE.name not in deployments:
199
- raise ValueError("Unable to find the deployment for WEBHOOK_CONFIGURE")
200
-
201
- deployment_id_webhook_setup = deployments[WEBHOOK_CONFIGURE.name].id
202
-
203
- webhook_configure_automation = await client.find_automation(id_or_name=AUTOMATION_NAME)
204
-
205
- automation = AutomationCore(
206
- name=AUTOMATION_NAME,
207
- description="Trigger actions on schema update event",
208
- enabled=True,
209
- trigger=EventTrigger(
210
- posture=Posture.Reactive,
211
- expect={"infrahub.node.*"},
212
- within=timedelta(0),
213
- match=ResourceSpecification(
214
- {
215
- "infrahub.node.kind": [InfrahubKind.WEBHOOK, InfrahubKind.STANDARDWEBHOOK],
216
- }
217
- ),
218
- threshold=1,
219
- ),
220
- actions=[
221
- RunDeployment(
222
- source="selected",
223
- deployment_id=deployment_id_webhook_setup,
224
- parameters={},
225
- job_variables={},
226
- ),
227
- ],
228
- )
229
-
230
- if webhook_configure_automation:
231
- await client.update_automation(automation_id=webhook_configure_automation.id, automation=automation)
232
- log.info(f"{AUTOMATION_NAME} Updated")
233
- else:
234
- await client.create_automation(automation=automation)
235
- log.info(f"{AUTOMATION_NAME} Created")
@@ -0,0 +1,20 @@
1
+ from infrahub.core.constants import InfrahubKind
2
+ from infrahub.trigger.models import BuiltinTriggerDefinition, EventTrigger, ExecuteWorkflow
3
+ from infrahub.workflows.catalogue import (
4
+ WEBHOOK_CONFIGURE,
5
+ )
6
+
7
+ TRIGGER_WEBHOOK_SETUP_UPDATE = BuiltinTriggerDefinition(
8
+ name="webhook-setup-update-configuration",
9
+ trigger=EventTrigger(
10
+ events={"infrahub.node.*"},
11
+ match={
12
+ "infrahub.node.kind": [InfrahubKind.WEBHOOK, InfrahubKind.STANDARDWEBHOOK],
13
+ },
14
+ ),
15
+ actions=[
16
+ ExecuteWorkflow(
17
+ name=WEBHOOK_CONFIGURE.name,
18
+ ),
19
+ ],
20
+ )
@@ -1,4 +1,3 @@
1
- import importlib
2
1
  import logging
3
2
  import os
4
3
  from typing import Any, Optional
@@ -23,7 +22,7 @@ from infrahub.database import InfrahubDatabase, get_db
23
22
  from infrahub.dependencies.registry import build_component_registry
24
23
  from infrahub.git import initialize_repositories_directory
25
24
  from infrahub.lock import initialize_lock
26
- from infrahub.services import InfrahubServices, services
25
+ from infrahub.services import InfrahubServices
27
26
  from infrahub.services.adapters.cache import InfrahubCache
28
27
  from infrahub.services.adapters.cache.nats import NATSCache
29
28
  from infrahub.services.adapters.cache.redis import RedisCache
@@ -33,6 +32,8 @@ from infrahub.services.adapters.message_bus.rabbitmq import RabbitMQMessageBus
33
32
  from infrahub.services.adapters.workflow import InfrahubWorkflow
34
33
  from infrahub.services.adapters.workflow.local import WorkflowLocalExecution
35
34
  from infrahub.services.adapters.workflow.worker import WorkflowWorkerExecution
35
+ from infrahub.trace import configure_trace
36
+ from infrahub.workers.utils import inject_service_parameter, load_flow_function
36
37
  from infrahub.workflows.models import TASK_RESULT_STORAGE_NAME
37
38
 
38
39
  WORKER_QUERY_SECONDS = "2"
@@ -65,6 +66,7 @@ class InfrahubWorkerAsync(BaseWorker):
65
66
  _documentation_url = "https://example.com/docs"
66
67
  _logo_url = "https://example.com/logo"
67
68
  _description = "Infrahub worker designed to run the flow in the main async loop."
69
+ service: InfrahubServices # keep a reference to `service` so we can inject it within flows parameters.
68
70
 
69
71
  async def setup(
70
72
  self,
@@ -89,6 +91,16 @@ class InfrahubWorkerAsync(BaseWorker):
89
91
 
90
92
  self._init_logger()
91
93
 
94
+ # Initialize trace
95
+ if config.SETTINGS.trace.enable:
96
+ configure_trace(
97
+ service="infrahub-task-worker",
98
+ version=infrahub_version,
99
+ exporter_type=config.SETTINGS.trace.exporter_type,
100
+ exporter_endpoint=config.SETTINGS.trace.exporter_endpoint,
101
+ exporter_protocol=config.SETTINGS.trace.exporter_protocol,
102
+ )
103
+
92
104
  # Start metric endpoint
93
105
  if metric_port is None or metric_port != 0:
94
106
  metric_port = metric_port or int(os.environ.get("INFRAHUB_METRICS_PORT", 8000))
@@ -107,20 +119,19 @@ class InfrahubWorkerAsync(BaseWorker):
107
119
  )
108
120
  )
109
121
 
110
- client = await self._init_infrahub_client(client=client)
111
- service = await self._init_services(client=client)
122
+ await self._init_services(client=client)
112
123
 
113
124
  if not registry.schema_has_been_initialized():
114
- initialize_lock(service=service)
125
+ initialize_lock(service=self.service)
115
126
 
116
- async with service.database.start_session() as db:
127
+ async with self.service.database.start_session() as db:
117
128
  await initialization(db=db)
118
129
 
119
- await service.component.refresh_schema_hash()
130
+ await self.service.component.refresh_schema_hash()
120
131
 
121
132
  initialize_repositories_directory()
122
133
  build_component_registry()
123
- await service.scheduler.start_schedule()
134
+ await self.service.scheduler.start_schedule()
124
135
  self._logger.info("Worker initialization completed .. ")
125
136
 
126
137
  async def run(
@@ -136,9 +147,8 @@ class InfrahubWorkerAsync(BaseWorker):
136
147
  file_path, flow_name = entrypoint.split(":")
137
148
  file_path.replace("/", ".")
138
149
  module_path = file_path.replace("backend/", "").replace(".py", "").replace("/", ".")
139
- module = importlib.import_module(module_path)
140
- flow_func = getattr(module, flow_name)
141
-
150
+ flow_func = load_flow_function(module_path=module_path, flow_name=flow_name)
151
+ inject_service_parameter(func=flow_func, parameters=flow_run.parameters, service=self.service)
142
152
  flow_run_logger.debug("Validating parameters")
143
153
  params = flow_func.validate_parameters(parameters=flow_run.parameters)
144
154
 
@@ -170,9 +180,9 @@ class InfrahubWorkerAsync(BaseWorker):
170
180
 
171
181
  try:
172
182
  await client.branch.all()
173
- except SdkError as exc:
174
- self._logger.error(f"Error in communication with Infrahub: {exc.message}")
175
- raise typer.Exit(1)
183
+ except SdkError as err:
184
+ self._logger.error(f"Error in communication with Infrahub: {err.message}")
185
+ raise typer.Exit(1) from err
176
186
 
177
187
  return client
178
188
 
@@ -186,32 +196,33 @@ class InfrahubWorkerAsync(BaseWorker):
186
196
  else WorkflowLocalExecution()
187
197
  )
188
198
 
189
- async def _init_message_bus(self) -> InfrahubMessageBus:
199
+ async def _init_message_bus(self, component_type: ComponentType) -> InfrahubMessageBus:
190
200
  return config.OVERRIDE.message_bus or (
191
- NATSMessageBus() if config.SETTINGS.broker.driver == config.BrokerDriver.NATS else RabbitMQMessageBus()
201
+ await NATSMessageBus.new(component_type=component_type)
202
+ if config.SETTINGS.broker.driver == config.BrokerDriver.NATS
203
+ else await RabbitMQMessageBus.new(component_type=component_type)
192
204
  )
193
205
 
194
206
  async def _init_cache(self) -> InfrahubCache:
195
207
  return config.OVERRIDE.cache or (
196
- NATSCache() if config.SETTINGS.cache.driver == config.CacheDriver.NATS else RedisCache()
208
+ await NATSCache.new() if config.SETTINGS.cache.driver == config.CacheDriver.NATS else RedisCache()
197
209
  )
198
210
 
199
- async def _init_services(self, client: InfrahubClient) -> InfrahubServices:
211
+ async def _init_services(self, client: InfrahubClient) -> None:
212
+ component_type = ComponentType.GIT_AGENT
213
+ client = await self._init_infrahub_client(client=client)
200
214
  database = await self._init_database()
201
215
  workflow = await self._init_workflow()
202
- message_bus = await self._init_message_bus()
216
+ message_bus = await self._init_message_bus(component_type=component_type)
203
217
  cache = await self._init_cache()
204
218
 
205
- service = InfrahubServices(
219
+ service = await InfrahubServices.new(
206
220
  cache=cache,
207
221
  client=client,
208
222
  database=database,
209
223
  message_bus=message_bus,
210
224
  workflow=workflow,
211
- component_type=ComponentType.GIT_AGENT,
225
+ component_type=component_type,
212
226
  )
213
227
 
214
- services.service = service
215
- await service.initialize()
216
-
217
- return service
228
+ self.service = service
@@ -0,0 +1,63 @@
1
+ from __future__ import annotations
2
+
3
+ import importlib
4
+ import inspect
5
+ from typing import TYPE_CHECKING, Any
6
+
7
+ from prefect import Flow
8
+
9
+ from infrahub.context import InfrahubContext
10
+
11
+ if TYPE_CHECKING:
12
+ from infrahub.services import InfrahubServices
13
+
14
+
15
+ def inject_service_parameter(func: Flow, parameters: dict[str, Any], service: InfrahubServices) -> None:
16
+ """
17
+ `service` object instantiates connections to various services (db, cache...) at worker startup,
18
+ so it is not meant to be sent by the server payload. We inject it here to avoid relying on a global variable.
19
+ This mutates input `parameters`.
20
+ """
21
+
22
+ # avoid circular imports
23
+ from infrahub.services import InfrahubServices # pylint: disable=C0415
24
+
25
+ if service_parameter_name := get_parameter_name(func=func, types=[InfrahubServices.__name__, InfrahubServices]):
26
+ if any(isinstance(param_value, InfrahubServices) for param_value in parameters):
27
+ raise ValueError(f"{func} parameters contains an InfrahubServices object while it should be injected")
28
+ parameters[service_parameter_name] = service
29
+ return
30
+
31
+
32
+ def inject_context_parameter(func: Flow, parameters: dict[str, Any], context: InfrahubContext | None = None) -> None:
33
+ service_parameter_name = get_parameter_name(func=func, types=[InfrahubContext.__name__, InfrahubContext])
34
+ if service_parameter_name and context:
35
+ parameters[service_parameter_name] = context
36
+ return
37
+
38
+ if service_parameter_name and not context:
39
+ raise ValueError(
40
+ f"{func} has a {service_parameter_name} parameter of type InfrahubContext, while context is not provided"
41
+ )
42
+
43
+
44
+ def load_flow_function(module_path: str, flow_name: str) -> Flow:
45
+ module = importlib.import_module(module_path)
46
+ flow_func = getattr(module, flow_name)
47
+ if not isinstance(flow_func, Flow):
48
+ raise ValueError(
49
+ f"Function loaded at {module_path=} with {flow_name=} has type {type(flow_func)}, expected {Flow}"
50
+ )
51
+ return flow_func
52
+
53
+
54
+ def get_parameter_name(func: Flow, types: list[Any]) -> str | None:
55
+ sig = inspect.signature(func)
56
+ for sig_param in sig.parameters.values():
57
+ if sig_param.annotation in types:
58
+ return sig_param.name
59
+ return None
60
+
61
+
62
+ def has_parameter(func: Flow, types: list[Any]) -> bool:
63
+ return get_parameter_name(func=func, types=types) is not None
@@ -319,27 +319,6 @@ REQUEST_PROPOSED_CHANGE_USER_TESTS = WorkflowDefinition(
319
319
  function="run_proposed_change_user_tests",
320
320
  )
321
321
 
322
- AUTOMATION_BRANCH_ACTIONS = WorkflowDefinition(
323
- name="branch-actions-setup",
324
- type=WorkflowType.CORE,
325
- module="infrahub.core.branch.tasks",
326
- function="branch_actions_setup",
327
- )
328
-
329
- AUTOMATION_SCHEMA_UPDATED = WorkflowDefinition(
330
- name="schema-updated-setup",
331
- type=WorkflowType.CORE,
332
- module="infrahub.schema.tasks",
333
- function="schema_updated_setup",
334
- )
335
-
336
- AUTOMATION_GIT_UPDATED = WorkflowDefinition(
337
- name="git-commit-automation-setup",
338
- type=WorkflowType.CORE,
339
- module="infrahub.git.tasks",
340
- function="setup_commit_automation",
341
- )
342
-
343
322
  GIT_REPOSITORIES_DIFF_NAMES_ONLY = WorkflowDefinition(
344
323
  name="git-repository-diff-names-only",
345
324
  type=WorkflowType.INTERNAL,
@@ -370,6 +349,13 @@ REQUEST_PROPOSED_CHANGE_REPOSITORY_CHECKS = WorkflowDefinition(
370
349
  function="repository_checks",
371
350
  )
372
351
 
352
+ REQUEST_ARTIFACT_DEFINITION_CHECK = WorkflowDefinition(
353
+ name="artifacts-generation-validation",
354
+ type=WorkflowType.INTERNAL,
355
+ module="infrahub.proposed_change.tasks",
356
+ function="validate_artifacts_generation",
357
+ )
358
+
373
359
  WEBHOOK_CONFIGURE = WorkflowDefinition(
374
360
  name="webhook-setup-automations",
375
361
  type=WorkflowType.USER,
@@ -384,22 +370,17 @@ WEBHOOK_TRIGGER = WorkflowDefinition(
384
370
  function="trigger_webhooks",
385
371
  )
386
372
 
387
- AUTOMATION_SETUP_WEBHOOK_CONFIGURATION_TRIGGER = WorkflowDefinition(
388
- name="webhook-setup-configuration-trigger",
373
+ GIT_REPOSITORIES_CHECK_ARTIFACT_CREATE = WorkflowDefinition(
374
+ name="git-repository-check-artifact-create",
389
375
  type=WorkflowType.USER,
390
- module="infrahub.webhook.tasks",
391
- function="trigger_webhook_configuration",
376
+ module="infrahub.artifacts.tasks",
377
+ function="create",
392
378
  )
393
379
 
394
-
395
380
  worker_pools = [INFRAHUB_WORKER_POOL]
396
381
 
397
382
  workflows = [
398
383
  ANONYMOUS_TELEMETRY_SEND,
399
- AUTOMATION_BRANCH_ACTIONS,
400
- AUTOMATION_GIT_UPDATED,
401
- AUTOMATION_SCHEMA_UPDATED,
402
- AUTOMATION_SETUP_WEBHOOK_CONFIGURATION_TRIGGER,
403
384
  BRANCH_CANCEL_PROPOSED_CHANGES,
404
385
  BRANCH_CREATE,
405
386
  BRANCH_DELETE,
@@ -413,6 +394,7 @@ workflows = [
413
394
  DIFF_REFRESH,
414
395
  DIFF_REFRESH_ALL,
415
396
  DIFF_UPDATE,
397
+ GIT_REPOSITORIES_CHECK_ARTIFACT_CREATE,
416
398
  GIT_REPOSITORIES_CREATE_BRANCH,
417
399
  GIT_REPOSITORIES_DIFF_NAMES_ONLY,
418
400
  GIT_REPOSITORIES_IMPORT_OBJECTS,
@@ -426,6 +408,7 @@ workflows = [
426
408
  PROCESS_COMPUTED_MACRO,
427
409
  PROPOSED_CHANGE_MERGE,
428
410
  QUERY_COMPUTED_ATTRIBUTE_TRANSFORM_TARGETS,
411
+ REQUEST_ARTIFACT_DEFINITION_CHECK,
429
412
  REQUEST_ARTIFACT_DEFINITION_GENERATE,
430
413
  REQUEST_ARTIFACT_GENERATE,
431
414
  REQUEST_GENERATOR_DEFINITION_RUN,
@@ -448,10 +431,3 @@ workflows = [
448
431
  WEBHOOK_SEND,
449
432
  WEBHOOK_TRIGGER,
450
433
  ]
451
-
452
- automation_setup_workflows = [
453
- AUTOMATION_BRANCH_ACTIONS,
454
- AUTOMATION_GIT_UPDATED,
455
- AUTOMATION_SCHEMA_UPDATED,
456
- AUTOMATION_SETUP_WEBHOOK_CONFIGURATION_TRIGGER,
457
- ]
@@ -7,12 +7,13 @@ from prefect.exceptions import ObjectAlreadyExists
7
7
  from prefect.logging import get_run_logger
8
8
 
9
9
  from infrahub import config
10
+ from infrahub.trigger.tasks import setup_triggers
10
11
 
11
- from .catalogue import automation_setup_workflows, worker_pools, workflows
12
+ from .catalogue import worker_pools, workflows
12
13
  from .models import TASK_RESULT_STORAGE_NAME
13
14
 
14
15
 
15
- @task(name="task-manager-setup-worker-pools", task_run_name="Setup Worker pools", cache_policy=NONE)
16
+ @task(name="task-manager-setup-worker-pools", task_run_name="Setup Worker pools", cache_policy=NONE) # type: ignore[arg-type]
16
17
  async def setup_worker_pools(client: PrefectClient) -> None:
17
18
  log = get_run_logger()
18
19
  for worker in worker_pools:
@@ -28,7 +29,7 @@ async def setup_worker_pools(client: PrefectClient) -> None:
28
29
  log.warning(f"Work pool {worker.name} already present ")
29
30
 
30
31
 
31
- @task(name="task-manager-setup-deployments", task_run_name="Setup Deployments", cache_policy=NONE)
32
+ @task(name="task-manager-setup-deployments", task_run_name="Setup Deployments", cache_policy=NONE) # type: ignore[arg-type]
32
33
  async def setup_deployments(client: PrefectClient) -> None:
33
34
  log = get_run_logger()
34
35
  for workflow in workflows:
@@ -38,12 +39,8 @@ async def setup_deployments(client: PrefectClient) -> None:
38
39
  await workflow.save(client=client, work_pool=work_pool)
39
40
  log.info(f"Flow {workflow.name}, created successfully ... ")
40
41
 
41
- for automation_setup_workflow in automation_setup_workflows:
42
- automation_setup = automation_setup_workflow.get_function()
43
- await automation_setup()
44
42
 
45
-
46
- @task(name="task-manager-setup-blocks", task_run_name="Setup Blocks", cache_policy=NONE)
43
+ @task(name="task-manager-setup-blocks", task_run_name="Setup Blocks", cache_policy=NONE) # type: ignore[arg-type]
47
44
  async def setup_blocks() -> None:
48
45
  log = get_run_logger()
49
46
 
@@ -71,3 +68,4 @@ async def setup_task_manager() -> None:
71
68
  await setup_blocks()
72
69
  await setup_worker_pools(client=client)
73
70
  await setup_deployments(client=client)
71
+ await setup_triggers(client=client)
@@ -1,7 +1,8 @@
1
1
  import importlib
2
- from typing import Any, Awaitable, Callable, TypeVar
2
+ from typing import Any, Awaitable, TypeVar
3
3
  from uuid import UUID
4
4
 
5
+ from prefect import Flow
5
6
  from prefect.client.orchestration import PrefectClient
6
7
  from prefect.client.schemas.actions import DeploymentScheduleCreate
7
8
  from prefect.client.schemas.objects import FlowRun
@@ -72,9 +73,6 @@ class WorkflowDefinition(BaseModel):
72
73
  data["work_pool_name"] = work_pool.name
73
74
  return await client.create_deployment(flow_id=flow_id, **data)
74
75
 
75
- def get_function(self) -> Callable[..., Awaitable[Any]]:
76
+ def load_function(self) -> Flow[Any, Awaitable]:
76
77
  module = importlib.import_module(self.module)
77
78
  return getattr(module, self.function)
78
-
79
- def validate_workflow(self) -> None:
80
- self.get_function()
@@ -76,4 +76,4 @@ async def wait_for_schema_to_converge(
76
76
 
77
77
  iteration += 1
78
78
 
79
- log.info(f"Schema converged after {delay * iteration} seconds")
79
+ log.info(f"Schema converged after {delay * iteration:.2f} seconds")