infrahub-server 1.3.5__py3-none-any.whl → 1.4.0b0__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.
- infrahub/api/internal.py +5 -0
- infrahub/artifacts/tasks.py +17 -22
- infrahub/branch/merge_mutation_checker.py +38 -0
- infrahub/cli/__init__.py +2 -2
- infrahub/cli/context.py +7 -3
- infrahub/cli/db.py +5 -16
- infrahub/cli/upgrade.py +7 -29
- infrahub/computed_attribute/tasks.py +36 -46
- infrahub/config.py +53 -2
- infrahub/constants/environment.py +1 -0
- infrahub/core/attribute.py +9 -7
- infrahub/core/branch/tasks.py +43 -41
- infrahub/core/constants/__init__.py +20 -6
- infrahub/core/constants/infrahubkind.py +2 -0
- infrahub/core/diff/coordinator.py +3 -1
- infrahub/core/diff/repository/repository.py +0 -8
- infrahub/core/diff/tasks.py +11 -8
- infrahub/core/graph/__init__.py +1 -1
- infrahub/core/graph/index.py +1 -2
- infrahub/core/graph/schema.py +50 -29
- infrahub/core/initialization.py +62 -33
- infrahub/core/ipam/tasks.py +4 -3
- infrahub/core/merge.py +8 -10
- infrahub/core/migrations/graph/__init__.py +2 -0
- infrahub/core/migrations/graph/m035_drop_attr_value_index.py +45 -0
- infrahub/core/migrations/query/attribute_add.py +27 -2
- infrahub/core/migrations/schema/tasks.py +6 -5
- infrahub/core/node/proposed_change.py +43 -0
- infrahub/core/protocols.py +12 -0
- infrahub/core/query/attribute.py +32 -14
- infrahub/core/query/diff.py +11 -0
- infrahub/core/query/ipam.py +13 -7
- infrahub/core/query/node.py +51 -10
- infrahub/core/query/resource_manager.py +3 -3
- infrahub/core/schema/basenode_schema.py +8 -0
- infrahub/core/schema/definitions/core/__init__.py +10 -1
- infrahub/core/schema/definitions/core/ipam.py +28 -2
- infrahub/core/schema/definitions/core/propose_change.py +15 -0
- infrahub/core/schema/definitions/core/webhook.py +3 -0
- infrahub/core/schema/generic_schema.py +10 -0
- infrahub/core/schema/manager.py +10 -1
- infrahub/core/schema/node_schema.py +22 -17
- infrahub/core/schema/profile_schema.py +8 -0
- infrahub/core/schema/schema_branch.py +9 -5
- infrahub/core/schema/template_schema.py +8 -0
- infrahub/core/validators/checks_runner.py +5 -5
- infrahub/core/validators/tasks.py +6 -7
- infrahub/core/validators/uniqueness/checker.py +4 -2
- infrahub/core/validators/uniqueness/model.py +1 -0
- infrahub/core/validators/uniqueness/query.py +57 -7
- infrahub/database/__init__.py +2 -1
- infrahub/events/__init__.py +18 -0
- infrahub/events/constants.py +7 -0
- infrahub/events/generator.py +29 -2
- infrahub/events/proposed_change_action.py +181 -0
- infrahub/generators/tasks.py +24 -20
- infrahub/git/base.py +4 -7
- infrahub/git/integrator.py +21 -12
- infrahub/git/repository.py +15 -30
- infrahub/git/tasks.py +121 -106
- infrahub/graphql/field_extractor.py +69 -0
- infrahub/graphql/manager.py +15 -11
- infrahub/graphql/mutations/account.py +2 -2
- infrahub/graphql/mutations/action.py +8 -2
- infrahub/graphql/mutations/artifact_definition.py +4 -1
- infrahub/graphql/mutations/branch.py +10 -5
- infrahub/graphql/mutations/graphql_query.py +2 -1
- infrahub/graphql/mutations/main.py +14 -8
- infrahub/graphql/mutations/menu.py +2 -1
- infrahub/graphql/mutations/proposed_change.py +225 -8
- infrahub/graphql/mutations/relationship.py +5 -0
- infrahub/graphql/mutations/repository.py +2 -1
- infrahub/graphql/mutations/tasks.py +7 -9
- infrahub/graphql/mutations/webhook.py +4 -1
- infrahub/graphql/parser.py +15 -6
- infrahub/graphql/queries/__init__.py +10 -1
- infrahub/graphql/queries/account.py +3 -3
- infrahub/graphql/queries/branch.py +2 -2
- infrahub/graphql/queries/diff/tree.py +3 -3
- infrahub/graphql/queries/event.py +13 -3
- infrahub/graphql/queries/ipam.py +23 -1
- infrahub/graphql/queries/proposed_change.py +84 -0
- infrahub/graphql/queries/relationship.py +2 -2
- infrahub/graphql/queries/resource_manager.py +3 -3
- infrahub/graphql/queries/search.py +3 -2
- infrahub/graphql/queries/status.py +3 -2
- infrahub/graphql/queries/task.py +2 -2
- infrahub/graphql/resolvers/ipam.py +440 -0
- infrahub/graphql/resolvers/many_relationship.py +4 -3
- infrahub/graphql/resolvers/resolver.py +5 -5
- infrahub/graphql/resolvers/single_relationship.py +3 -2
- infrahub/graphql/schema.py +25 -5
- infrahub/graphql/types/__init__.py +2 -2
- infrahub/graphql/types/attribute.py +3 -3
- infrahub/graphql/types/event.py +60 -0
- infrahub/groups/tasks.py +6 -6
- infrahub/lock.py +3 -2
- infrahub/menu/generator.py +8 -0
- infrahub/message_bus/operations/__init__.py +9 -12
- infrahub/message_bus/operations/git/file.py +6 -5
- infrahub/message_bus/operations/git/repository.py +12 -20
- infrahub/message_bus/operations/refresh/registry.py +15 -9
- infrahub/message_bus/operations/send/echo.py +7 -4
- infrahub/message_bus/types.py +1 -0
- infrahub/permissions/globals.py +1 -4
- infrahub/permissions/manager.py +8 -5
- infrahub/pools/prefix.py +7 -5
- infrahub/prefect_server/app.py +31 -0
- infrahub/prefect_server/bootstrap.py +18 -0
- infrahub/proposed_change/action_checker.py +206 -0
- infrahub/proposed_change/approval_revoker.py +40 -0
- infrahub/proposed_change/branch_diff.py +3 -1
- infrahub/proposed_change/checker.py +45 -0
- infrahub/proposed_change/constants.py +32 -2
- infrahub/proposed_change/tasks.py +182 -150
- infrahub/py.typed +0 -0
- infrahub/server.py +29 -17
- infrahub/services/__init__.py +13 -28
- infrahub/services/adapters/cache/__init__.py +4 -0
- infrahub/services/adapters/cache/nats.py +2 -0
- infrahub/services/adapters/cache/redis.py +3 -0
- infrahub/services/adapters/message_bus/__init__.py +0 -2
- infrahub/services/adapters/message_bus/local.py +1 -2
- infrahub/services/adapters/message_bus/nats.py +6 -8
- infrahub/services/adapters/message_bus/rabbitmq.py +7 -9
- infrahub/services/adapters/workflow/__init__.py +1 -0
- infrahub/services/adapters/workflow/local.py +1 -8
- infrahub/services/component.py +2 -1
- infrahub/task_manager/event.py +52 -0
- infrahub/task_manager/models.py +9 -0
- infrahub/tasks/artifact.py +6 -7
- infrahub/tasks/check.py +4 -7
- infrahub/telemetry/tasks.py +15 -18
- infrahub/transformations/tasks.py +10 -6
- infrahub/trigger/tasks.py +4 -3
- infrahub/types.py +4 -0
- infrahub/validators/events.py +7 -7
- infrahub/validators/tasks.py +6 -7
- infrahub/webhook/models.py +45 -45
- infrahub/webhook/tasks.py +25 -24
- infrahub/workers/dependencies.py +143 -0
- infrahub/workers/infrahub_async.py +19 -43
- infrahub/workflows/catalogue.py +16 -2
- infrahub/workflows/initialization.py +5 -4
- infrahub/workflows/models.py +2 -0
- infrahub_sdk/client.py +6 -6
- infrahub_sdk/ctl/repository.py +51 -0
- infrahub_sdk/ctl/schema.py +9 -9
- infrahub_sdk/protocols.py +40 -6
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/METADATA +5 -4
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/RECORD +158 -144
- infrahub_testcontainers/container.py +17 -0
- infrahub_testcontainers/docker-compose-cluster.test.yml +56 -1
- infrahub_testcontainers/docker-compose.test.yml +56 -1
- infrahub_testcontainers/helpers.py +4 -1
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/WHEEL +0 -0
- {infrahub_server-1.3.5.dist-info → infrahub_server-1.4.0b0.dist-info}/entry_points.txt +0 -0
infrahub/generators/tasks.py
CHANGED
|
@@ -21,25 +21,29 @@ from infrahub.generators.models import (
|
|
|
21
21
|
)
|
|
22
22
|
from infrahub.git.base import extract_repo_file_information
|
|
23
23
|
from infrahub.git.repository import get_initialized_repo
|
|
24
|
-
from infrahub.
|
|
24
|
+
from infrahub.workers.dependencies import get_client, get_workflow
|
|
25
25
|
from infrahub.workflows.catalogue import REQUEST_GENERATOR_DEFINITION_RUN, REQUEST_GENERATOR_RUN
|
|
26
26
|
from infrahub.workflows.utils import add_tags
|
|
27
27
|
|
|
28
28
|
if TYPE_CHECKING:
|
|
29
29
|
from collections.abc import Coroutine
|
|
30
30
|
|
|
31
|
+
from infrahub_sdk.client import InfrahubClient
|
|
32
|
+
|
|
31
33
|
|
|
32
34
|
@flow(
|
|
33
35
|
name="generator-run",
|
|
34
36
|
flow_run_name="Run generator {model.generator_definition.definition_name}",
|
|
35
37
|
)
|
|
36
|
-
async def run_generator(model: RequestGeneratorRun
|
|
38
|
+
async def run_generator(model: RequestGeneratorRun) -> None:
|
|
37
39
|
await add_tags(branches=[model.branch_name], nodes=[model.target_id])
|
|
38
40
|
|
|
41
|
+
client = get_client()
|
|
42
|
+
|
|
39
43
|
repository = await get_initialized_repo(
|
|
44
|
+
client=client,
|
|
40
45
|
repository_id=model.repository_id,
|
|
41
46
|
name=model.repository_name,
|
|
42
|
-
service=service,
|
|
43
47
|
repository_kind=model.repository_kind,
|
|
44
48
|
commit=model.commit,
|
|
45
49
|
)
|
|
@@ -60,7 +64,7 @@ async def run_generator(model: RequestGeneratorRun, service: InfrahubServices) -
|
|
|
60
64
|
repo_directory=repository.directory_root,
|
|
61
65
|
worktree_directory=commit_worktree.directory,
|
|
62
66
|
)
|
|
63
|
-
generator_instance = await _define_instance(model=model,
|
|
67
|
+
generator_instance = await _define_instance(model=model, client=client)
|
|
64
68
|
|
|
65
69
|
try:
|
|
66
70
|
generator_class = generator_definition.load_class(
|
|
@@ -69,7 +73,7 @@ async def run_generator(model: RequestGeneratorRun, service: InfrahubServices) -
|
|
|
69
73
|
|
|
70
74
|
generator = generator_class(
|
|
71
75
|
query=generator_definition.query,
|
|
72
|
-
client=
|
|
76
|
+
client=client,
|
|
73
77
|
branch=model.branch_name,
|
|
74
78
|
params=model.variables,
|
|
75
79
|
generator_instance=generator_instance.id,
|
|
@@ -87,11 +91,9 @@ async def run_generator(model: RequestGeneratorRun, service: InfrahubServices) -
|
|
|
87
91
|
|
|
88
92
|
|
|
89
93
|
@task(name="generator-define-instance", task_run_name="Define Instance", cache_policy=NONE) # type: ignore[arg-type]
|
|
90
|
-
async def _define_instance(model: RequestGeneratorRun,
|
|
94
|
+
async def _define_instance(model: RequestGeneratorRun, client: InfrahubClient) -> CoreGeneratorInstance:
|
|
91
95
|
if model.generator_instance:
|
|
92
|
-
instance = await
|
|
93
|
-
kind=CoreGeneratorInstance, id=model.generator_instance, branch=model.branch_name
|
|
94
|
-
)
|
|
96
|
+
instance = await client.get(kind=CoreGeneratorInstance, id=model.generator_instance, branch=model.branch_name)
|
|
95
97
|
instance.status.value = GeneratorInstanceStatus.PENDING.value
|
|
96
98
|
await instance.update(do_full_update=True)
|
|
97
99
|
|
|
@@ -99,7 +101,7 @@ async def _define_instance(model: RequestGeneratorRun, service: InfrahubServices
|
|
|
99
101
|
async with lock.registry.get(
|
|
100
102
|
f"{model.target_id}-{model.generator_definition.definition_id}", namespace="generator"
|
|
101
103
|
):
|
|
102
|
-
instances = await
|
|
104
|
+
instances = await client.filters(
|
|
103
105
|
kind=CoreGeneratorInstance,
|
|
104
106
|
definition__ids=[model.generator_definition.definition_id],
|
|
105
107
|
object__ids=[model.target_id],
|
|
@@ -110,7 +112,7 @@ async def _define_instance(model: RequestGeneratorRun, service: InfrahubServices
|
|
|
110
112
|
instance.status.value = GeneratorInstanceStatus.PENDING.value
|
|
111
113
|
await instance.update(do_full_update=True)
|
|
112
114
|
else:
|
|
113
|
-
instance = await
|
|
115
|
+
instance = await client.create(
|
|
114
116
|
kind=CoreGeneratorInstance,
|
|
115
117
|
branch=model.branch_name,
|
|
116
118
|
data={
|
|
@@ -125,10 +127,10 @@ async def _define_instance(model: RequestGeneratorRun, service: InfrahubServices
|
|
|
125
127
|
|
|
126
128
|
|
|
127
129
|
@flow(name="generator-definition-run", flow_run_name="Run all generators")
|
|
128
|
-
async def run_generator_definition(branch: str, context: InfrahubContext
|
|
130
|
+
async def run_generator_definition(branch: str, context: InfrahubContext) -> None:
|
|
129
131
|
await add_tags(branches=[branch])
|
|
130
132
|
|
|
131
|
-
generators = await
|
|
133
|
+
generators = await get_client().filters(
|
|
132
134
|
kind=InfrahubKind.GENERATORDEFINITION, prefetch_relationships=True, populate_store=True, branch=branch
|
|
133
135
|
)
|
|
134
136
|
|
|
@@ -150,7 +152,7 @@ async def run_generator_definition(branch: str, context: InfrahubContext, servic
|
|
|
150
152
|
|
|
151
153
|
for generator_definition in generator_definitions:
|
|
152
154
|
model = RequestGeneratorDefinitionRun(branch=branch, generator_definition=generator_definition)
|
|
153
|
-
await
|
|
155
|
+
await get_workflow().submit_workflow(
|
|
154
156
|
workflow=REQUEST_GENERATOR_DEFINITION_RUN, context=context, parameters={"model": model}
|
|
155
157
|
)
|
|
156
158
|
|
|
@@ -160,11 +162,13 @@ async def run_generator_definition(branch: str, context: InfrahubContext, servic
|
|
|
160
162
|
flow_run_name="Execute generator {model.generator_definition.definition_name}",
|
|
161
163
|
)
|
|
162
164
|
async def request_generator_definition_run(
|
|
163
|
-
model: RequestGeneratorDefinitionRun, context: InfrahubContext
|
|
165
|
+
model: RequestGeneratorDefinitionRun, context: InfrahubContext
|
|
164
166
|
) -> State[Any]:
|
|
165
167
|
await add_tags(branches=[model.branch], nodes=[model.generator_definition.definition_id])
|
|
166
168
|
|
|
167
|
-
|
|
169
|
+
client = get_client()
|
|
170
|
+
|
|
171
|
+
group = await client.get(
|
|
168
172
|
kind=InfrahubKind.GENERICGROUP,
|
|
169
173
|
prefetch_relationships=True,
|
|
170
174
|
populate_store=True,
|
|
@@ -173,7 +177,7 @@ async def request_generator_definition_run(
|
|
|
173
177
|
)
|
|
174
178
|
await group.members.fetch()
|
|
175
179
|
|
|
176
|
-
existing_instances = await
|
|
180
|
+
existing_instances = await client.filters(
|
|
177
181
|
kind=InfrahubKind.GENERATORINSTANCE,
|
|
178
182
|
definition__ids=[model.generator_definition.definition_id],
|
|
179
183
|
include=["object"],
|
|
@@ -183,14 +187,14 @@ async def request_generator_definition_run(
|
|
|
183
187
|
for instance in existing_instances:
|
|
184
188
|
instance_by_member[instance.object.peer.id] = instance.id
|
|
185
189
|
|
|
186
|
-
repository = await
|
|
190
|
+
repository = await client.get(
|
|
187
191
|
kind=InfrahubKind.REPOSITORY,
|
|
188
192
|
branch=model.branch,
|
|
189
193
|
id=model.generator_definition.repository_id,
|
|
190
194
|
raise_when_missing=False,
|
|
191
195
|
)
|
|
192
196
|
if not repository:
|
|
193
|
-
repository = await
|
|
197
|
+
repository = await client.get(
|
|
194
198
|
kind=InfrahubKind.READONLYREPOSITORY,
|
|
195
199
|
branch=model.branch,
|
|
196
200
|
id=model.generator_definition.repository_id,
|
|
@@ -219,7 +223,7 @@ async def request_generator_definition_run(
|
|
|
219
223
|
target_name=member.display_label,
|
|
220
224
|
)
|
|
221
225
|
tasks.append(
|
|
222
|
-
|
|
226
|
+
get_workflow().execute_workflow(
|
|
223
227
|
workflow=REQUEST_GENERATOR_RUN, context=context, parameters={"model": request_generator_run_model}
|
|
224
228
|
)
|
|
225
229
|
)
|
infrahub/git/base.py
CHANGED
|
@@ -33,7 +33,7 @@ from infrahub.git.constants import BRANCHES_DIRECTORY_NAME, COMMITS_DIRECTORY_NA
|
|
|
33
33
|
from infrahub.git.directory import get_repositories_directory, initialize_repositories_directory
|
|
34
34
|
from infrahub.git.worktree import Worktree
|
|
35
35
|
from infrahub.log import get_logger
|
|
36
|
-
from infrahub.
|
|
36
|
+
from infrahub.workers.dependencies import get_client
|
|
37
37
|
|
|
38
38
|
if TYPE_CHECKING:
|
|
39
39
|
from infrahub_sdk.branch import BranchData
|
|
@@ -153,9 +153,6 @@ class InfrahubRepositoryBase(BaseModel, ABC):
|
|
|
153
153
|
)
|
|
154
154
|
|
|
155
155
|
cache_repo: Repo | None = Field(None, description="Internal cache of the GitPython Repo object")
|
|
156
|
-
service: InfrahubServices = Field(
|
|
157
|
-
..., description="Service object with access to the message queue, the database etc.."
|
|
158
|
-
)
|
|
159
156
|
is_read_only: bool = Field(False, description="If true, changes will not be synced to remote")
|
|
160
157
|
|
|
161
158
|
internal_status: str = Field("active", description="Internal status: Active, Inactive, Staging")
|
|
@@ -169,10 +166,10 @@ class InfrahubRepositoryBase(BaseModel, ABC):
|
|
|
169
166
|
|
|
170
167
|
@property
|
|
171
168
|
def sdk(self) -> InfrahubClient:
|
|
172
|
-
if self.client:
|
|
173
|
-
|
|
169
|
+
if not self.client:
|
|
170
|
+
self.client = get_client()
|
|
174
171
|
|
|
175
|
-
return self.
|
|
172
|
+
return self.client
|
|
176
173
|
|
|
177
174
|
@property
|
|
178
175
|
def default_branch(self) -> str:
|
infrahub/git/integrator.py
CHANGED
|
@@ -50,6 +50,7 @@ from infrahub.events.repository_action import CommitUpdatedEvent
|
|
|
50
50
|
from infrahub.exceptions import CheckError, RepositoryInvalidFileSystemError, TransformError
|
|
51
51
|
from infrahub.git.base import InfrahubRepositoryBase, extract_repo_file_information
|
|
52
52
|
from infrahub.log import get_logger
|
|
53
|
+
from infrahub.workers.dependencies import get_event_service
|
|
53
54
|
from infrahub.workflows.utils import add_tags
|
|
54
55
|
|
|
55
56
|
if TYPE_CHECKING:
|
|
@@ -62,7 +63,6 @@ if TYPE_CHECKING:
|
|
|
62
63
|
|
|
63
64
|
from infrahub.artifacts.models import CheckArtifactCreate
|
|
64
65
|
from infrahub.git.models import RequestArtifactGenerate
|
|
65
|
-
from infrahub.services import InfrahubServices
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
class ArtifactGenerateResult(BaseModel):
|
|
@@ -141,8 +141,8 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
|
|
|
141
141
|
"""
|
|
142
142
|
|
|
143
143
|
@classmethod
|
|
144
|
-
async def init(cls,
|
|
145
|
-
self = cls(
|
|
144
|
+
async def init(cls, commit: str | None = None, **kwargs: Any) -> Self:
|
|
145
|
+
self = cls(**kwargs)
|
|
146
146
|
log = get_logger()
|
|
147
147
|
try:
|
|
148
148
|
self.validate_local_directories()
|
|
@@ -216,7 +216,8 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
|
|
|
216
216
|
raise error
|
|
217
217
|
|
|
218
218
|
infrahub_branch = registry.get_branch_from_registry(branch=infrahub_branch_name)
|
|
219
|
-
await
|
|
219
|
+
event_service = await get_event_service()
|
|
220
|
+
await event_service.send(
|
|
220
221
|
CommitUpdatedEvent(
|
|
221
222
|
commit=commit,
|
|
222
223
|
repository_name=self.name,
|
|
@@ -436,10 +437,18 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
|
|
|
436
437
|
branch_wt = self.get_worktree(identifier=commit or branch_name)
|
|
437
438
|
log = get_run_logger()
|
|
438
439
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
440
|
+
# Check for both .infrahub.yml and .infrahub.yaml, prefer .yml if both exist
|
|
441
|
+
config_file_yml = branch_wt.directory / ".infrahub.yml"
|
|
442
|
+
config_file_yaml = branch_wt.directory / ".infrahub.yaml"
|
|
443
|
+
|
|
444
|
+
if config_file_yml.is_file():
|
|
445
|
+
config_file = config_file_yml
|
|
446
|
+
config_file_name = ".infrahub.yml"
|
|
447
|
+
elif config_file_yaml.is_file():
|
|
448
|
+
config_file = config_file_yaml
|
|
449
|
+
config_file_name = ".infrahub.yaml"
|
|
450
|
+
else:
|
|
451
|
+
log.debug("Unable to find the configuration file (.infrahub.yml or .infrahub.yaml), skipping")
|
|
443
452
|
return None
|
|
444
453
|
|
|
445
454
|
config_file_content = config_file.read_text(encoding="utf-8")
|
|
@@ -1264,7 +1273,6 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
|
|
|
1264
1273
|
infrahub_node=InfrahubNode,
|
|
1265
1274
|
)
|
|
1266
1275
|
return await transform.run(data=data)
|
|
1267
|
-
|
|
1268
1276
|
except ModuleNotFoundError as exc:
|
|
1269
1277
|
error_msg = f"Unable to load the transform file {location}"
|
|
1270
1278
|
log.error(error_msg)
|
|
@@ -1314,11 +1322,11 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
|
|
|
1314
1322
|
artifact_content = await self.execute_python_transform.with_options(
|
|
1315
1323
|
timeout_seconds=transformation.timeout.value
|
|
1316
1324
|
)(
|
|
1325
|
+
client=self.sdk,
|
|
1317
1326
|
branch_name=branch_name,
|
|
1318
1327
|
commit=commit,
|
|
1319
1328
|
location=transformation_location,
|
|
1320
1329
|
data=response,
|
|
1321
|
-
client=self.sdk,
|
|
1322
1330
|
convert_query_response=transformation.convert_query_response.value,
|
|
1323
1331
|
) # type: ignore[misc]
|
|
1324
1332
|
|
|
@@ -1374,11 +1382,11 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
|
|
|
1374
1382
|
) # type: ignore[misc]
|
|
1375
1383
|
elif message.transform_type == InfrahubKind.TRANSFORMPYTHON:
|
|
1376
1384
|
artifact_content = await self.execute_python_transform.with_options(timeout_seconds=message.timeout)(
|
|
1385
|
+
client=self.sdk,
|
|
1377
1386
|
branch_name=message.branch_name,
|
|
1378
1387
|
commit=message.commit,
|
|
1379
1388
|
location=message.transform_location,
|
|
1380
1389
|
data=response,
|
|
1381
|
-
client=self.sdk,
|
|
1382
1390
|
convert_query_response=message.convert_query_response,
|
|
1383
1391
|
) # type: ignore[misc]
|
|
1384
1392
|
|
|
@@ -1421,7 +1429,8 @@ class InfrahubRepositoryIntegrator(InfrahubRepositoryBase):
|
|
|
1421
1429
|
storage_id_previous=previous_storage_id,
|
|
1422
1430
|
)
|
|
1423
1431
|
|
|
1424
|
-
await
|
|
1432
|
+
event_service = await get_event_service()
|
|
1433
|
+
await event_service.send(event=event)
|
|
1425
1434
|
return ArtifactGenerateResult(changed=True, checksum=checksum, storage_id=storage_id, artifact_id=artifact.id)
|
|
1426
1435
|
|
|
1427
1436
|
|
infrahub/git/repository.py
CHANGED
|
@@ -4,6 +4,8 @@ from typing import TYPE_CHECKING, Any
|
|
|
4
4
|
|
|
5
5
|
from git.exc import BadName, GitCommandError
|
|
6
6
|
from infrahub_sdk.exceptions import GraphQLError
|
|
7
|
+
from prefect import task
|
|
8
|
+
from prefect.cache_policies import NONE
|
|
7
9
|
from pydantic import Field
|
|
8
10
|
|
|
9
11
|
from infrahub.core.constants import InfrahubKind, RepositoryInternalStatus
|
|
@@ -12,7 +14,7 @@ from infrahub.git.integrator import InfrahubRepositoryIntegrator
|
|
|
12
14
|
from infrahub.log import get_logger
|
|
13
15
|
|
|
14
16
|
if TYPE_CHECKING:
|
|
15
|
-
from
|
|
17
|
+
from infrahub_sdk.client import InfrahubClient
|
|
16
18
|
|
|
17
19
|
log = get_logger()
|
|
18
20
|
|
|
@@ -25,10 +27,8 @@ class InfrahubRepository(InfrahubRepositoryIntegrator):
|
|
|
25
27
|
"""
|
|
26
28
|
|
|
27
29
|
@classmethod
|
|
28
|
-
async def new(
|
|
29
|
-
|
|
30
|
-
) -> InfrahubRepository:
|
|
31
|
-
self = cls(service=service, **kwargs)
|
|
30
|
+
async def new(cls, update_commit_value: bool = True, **kwargs: Any) -> InfrahubRepository:
|
|
31
|
+
self = cls(**kwargs)
|
|
32
32
|
await self.create_locally(
|
|
33
33
|
infrahub_branch_name=self.infrahub_branch_name, update_commit_value=update_commit_value
|
|
34
34
|
)
|
|
@@ -209,11 +209,11 @@ class InfrahubReadOnlyRepository(InfrahubRepositoryIntegrator):
|
|
|
209
209
|
ref: str | None = Field(None, description="Ref to track on the external repository")
|
|
210
210
|
|
|
211
211
|
@classmethod
|
|
212
|
-
async def new(cls,
|
|
212
|
+
async def new(cls, **kwargs: Any) -> InfrahubReadOnlyRepository:
|
|
213
213
|
if "ref" not in kwargs or "infrahub_branch_name" not in kwargs:
|
|
214
214
|
raise ValueError("ref and infrahub_branch_name are mandatory to initialize a new Read-Only repository")
|
|
215
215
|
|
|
216
|
-
self = cls(
|
|
216
|
+
self = cls(**kwargs)
|
|
217
217
|
await self.create_locally(checkout_ref=self.ref, infrahub_branch_name=self.infrahub_branch_name)
|
|
218
218
|
log.info("Created new repository locally.", repository=self.name)
|
|
219
219
|
return self
|
|
@@ -248,33 +248,18 @@ class InfrahubReadOnlyRepository(InfrahubRepositoryIntegrator):
|
|
|
248
248
|
await self.update_commit_value(branch_name=self.infrahub_branch_name, commit=commit)
|
|
249
249
|
|
|
250
250
|
|
|
251
|
+
@task(
|
|
252
|
+
name="Fetch repository commit",
|
|
253
|
+
description="Retrieve a git repository at a given commit, if it does not already exist locally",
|
|
254
|
+
cache_policy=NONE,
|
|
255
|
+
)
|
|
251
256
|
async def get_initialized_repo(
|
|
252
|
-
|
|
257
|
+
client: InfrahubClient, repository_id: str, name: str, repository_kind: str, commit: str | None = None
|
|
253
258
|
) -> InfrahubReadOnlyRepository | InfrahubRepository:
|
|
254
259
|
if repository_kind == InfrahubKind.REPOSITORY:
|
|
255
|
-
return await InfrahubRepository.init(
|
|
256
|
-
id=repository_id, name=name, commit=commit, client=service._client, service=service
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
if repository_kind == InfrahubKind.READONLYREPOSITORY:
|
|
260
|
-
return await InfrahubReadOnlyRepository.init(
|
|
261
|
-
id=repository_id, name=name, commit=commit, client=service._client, service=service
|
|
262
|
-
)
|
|
263
|
-
|
|
264
|
-
raise NotImplementedError(f"The repository kind {repository_kind} has not been implemented")
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
async def initialize_repo(
|
|
268
|
-
location: str, repository_id: str, name: str, service: InfrahubServices, repository_kind: str
|
|
269
|
-
) -> InfrahubReadOnlyRepository | InfrahubRepository:
|
|
270
|
-
if repository_kind == InfrahubKind.REPOSITORY:
|
|
271
|
-
return await InfrahubRepository.new(
|
|
272
|
-
location=location, id=repository_id, name=name, client=service._client, service=service
|
|
273
|
-
)
|
|
260
|
+
return await InfrahubRepository.init(id=repository_id, name=name, commit=commit, client=client)
|
|
274
261
|
|
|
275
262
|
if repository_kind == InfrahubKind.READONLYREPOSITORY:
|
|
276
|
-
return await InfrahubReadOnlyRepository.
|
|
277
|
-
location=location, id=repository_id, name=name, client=service._client, service=service
|
|
278
|
-
)
|
|
263
|
+
return await InfrahubReadOnlyRepository.init(id=repository_id, name=name, commit=commit, client=client)
|
|
279
264
|
|
|
280
265
|
raise NotImplementedError(f"The repository kind {repository_kind} has not been implemented")
|