infrahub-server 1.1.3__py3-none-any.whl → 1.1.4__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/schema.py +16 -3
- infrahub/config.py +0 -1
- infrahub/core/constants/__init__.py +5 -0
- infrahub/core/schema/__init__.py +5 -0
- infrahub_sdk/analyzer.py +1 -1
- infrahub_sdk/checks.py +4 -4
- infrahub_sdk/client.py +26 -16
- infrahub_sdk/generator.py +3 -3
- infrahub_sdk/node.py +2 -2
- infrahub_sdk/pytest_plugin/items/base.py +0 -5
- infrahub_sdk/repository.py +33 -0
- infrahub_sdk/testing/repository.py +14 -8
- infrahub_sdk/transforms.py +3 -3
- infrahub_sdk/utils.py +8 -3
- {infrahub_server-1.1.3.dist-info → infrahub_server-1.1.4.dist-info}/METADATA +2 -1
- {infrahub_server-1.1.3.dist-info → infrahub_server-1.1.4.dist-info}/RECORD +19 -19
- infrahub_sdk/task_report.py +0 -208
- {infrahub_server-1.1.3.dist-info → infrahub_server-1.1.4.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.1.3.dist-info → infrahub_server-1.1.4.dist-info}/WHEEL +0 -0
- {infrahub_server-1.1.3.dist-info → infrahub_server-1.1.4.dist-info}/entry_points.txt +0 -0
infrahub/api/schema.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING, Any
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Sequence
|
|
4
4
|
|
|
5
5
|
from fastapi import APIRouter, Depends, Query, Request
|
|
6
6
|
from pydantic import (
|
|
@@ -128,13 +128,26 @@ class SchemaUpdate(BaseModel):
|
|
|
128
128
|
return self.hash != self.previous_hash
|
|
129
129
|
|
|
130
130
|
|
|
131
|
+
def _merge_candidate_schemas(schemas: Sequence[SchemaRoot]) -> SchemaRoot:
|
|
132
|
+
"""Merge multiple schemas into one suitable to be loaded."""
|
|
133
|
+
if not schemas:
|
|
134
|
+
raise ValueError("Cannot merge an empty list of schemas")
|
|
135
|
+
|
|
136
|
+
merged = schemas[0]
|
|
137
|
+
for schema in schemas[1:]:
|
|
138
|
+
merged = merged.merge(schema=schema)
|
|
139
|
+
|
|
140
|
+
return merged
|
|
141
|
+
|
|
142
|
+
|
|
131
143
|
def evaluate_candidate_schemas(
|
|
132
144
|
branch_schema: SchemaBranch, schemas_to_evaluate: SchemasLoadAPI
|
|
133
145
|
) -> tuple[SchemaBranch, SchemaUpdateValidationResult]:
|
|
134
146
|
candidate_schema = branch_schema.duplicate()
|
|
147
|
+
schema = _merge_candidate_schemas(schemas=schemas_to_evaluate.schemas)
|
|
148
|
+
|
|
135
149
|
try:
|
|
136
|
-
|
|
137
|
-
candidate_schema.load_schema(schema=schema)
|
|
150
|
+
candidate_schema.load_schema(schema=schema)
|
|
138
151
|
candidate_schema.process()
|
|
139
152
|
|
|
140
153
|
schema_diff = branch_schema.diff(other=candidate_schema)
|
infrahub/config.py
CHANGED
|
@@ -120,7 +120,12 @@ class AllowOverrideType(InfrahubStringEnum):
|
|
|
120
120
|
|
|
121
121
|
class ContentType(InfrahubStringEnum):
|
|
122
122
|
APPLICATION_JSON = "application/json"
|
|
123
|
+
APPLICATION_YAML = "application/yaml"
|
|
124
|
+
APPLICATION_XML = "application/xml"
|
|
123
125
|
TEXT_PLAIN = "text/plain"
|
|
126
|
+
TEXT_MARKDOWN = "text/markdown"
|
|
127
|
+
TEXT_CSV = "text/csv"
|
|
128
|
+
IMAGE_SVG = "image/svg+xml"
|
|
124
129
|
|
|
125
130
|
|
|
126
131
|
class CheckType(InfrahubStringEnum):
|
infrahub/core/schema/__init__.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import uuid
|
|
4
4
|
from typing import Any, Optional, TypeAlias, Union
|
|
5
5
|
|
|
6
|
+
from infrahub_sdk.utils import deep_merge_dict
|
|
6
7
|
from pydantic import BaseModel, ConfigDict, Field
|
|
7
8
|
|
|
8
9
|
from infrahub.core.constants import RESTRICTED_NAMESPACES
|
|
@@ -86,6 +87,10 @@ class SchemaRoot(BaseModel):
|
|
|
86
87
|
if not item.id:
|
|
87
88
|
item.id = str(uuid.uuid4())
|
|
88
89
|
|
|
90
|
+
def merge(self, schema: SchemaRoot) -> SchemaRoot:
|
|
91
|
+
"""Return a new `SchemaRoot` after merging `self` with `schema`."""
|
|
92
|
+
return SchemaRoot.model_validate(deep_merge_dict(dicta=self.model_dump(), dictb=schema.model_dump()))
|
|
93
|
+
|
|
89
94
|
|
|
90
95
|
internal_schema = internal.to_dict()
|
|
91
96
|
|
infrahub_sdk/analyzer.py
CHANGED
|
@@ -91,7 +91,7 @@ class GraphQLQueryAnalyzer:
|
|
|
91
91
|
else:
|
|
92
92
|
data["default_value"] = variable.default_value.value
|
|
93
93
|
|
|
94
|
-
if not data.get("default_value"
|
|
94
|
+
if not data.get("default_value") and non_null:
|
|
95
95
|
data["required"] = True
|
|
96
96
|
|
|
97
97
|
response.append(GraphQLQueryVariable(**data))
|
infrahub_sdk/checks.py
CHANGED
|
@@ -8,9 +8,10 @@ from abc import abstractmethod
|
|
|
8
8
|
from typing import TYPE_CHECKING, Any
|
|
9
9
|
|
|
10
10
|
import ujson
|
|
11
|
-
from git.repo import Repo
|
|
12
11
|
from pydantic import BaseModel, Field
|
|
13
12
|
|
|
13
|
+
from infrahub_sdk.repository import GitRepoManager
|
|
14
|
+
|
|
14
15
|
from .exceptions import UninitializedError
|
|
15
16
|
|
|
16
17
|
if TYPE_CHECKING:
|
|
@@ -43,7 +44,7 @@ class InfrahubCheck:
|
|
|
43
44
|
params: dict | None = None,
|
|
44
45
|
client: InfrahubClient | None = None,
|
|
45
46
|
):
|
|
46
|
-
self.git:
|
|
47
|
+
self.git: GitRepoManager | None = None
|
|
47
48
|
self.initializer = initializer or InfrahubCheckInitializer()
|
|
48
49
|
|
|
49
50
|
self.logs: list[dict[str, Any]] = []
|
|
@@ -137,10 +138,9 @@ class InfrahubCheck:
|
|
|
137
138
|
return self.branch
|
|
138
139
|
|
|
139
140
|
if not self.git:
|
|
140
|
-
self.git =
|
|
141
|
+
self.git = GitRepoManager(self.root_directory)
|
|
141
142
|
|
|
142
143
|
self.branch = str(self.git.active_branch)
|
|
143
|
-
|
|
144
144
|
return self.branch
|
|
145
145
|
|
|
146
146
|
@abstractmethod
|
infrahub_sdk/client.py
CHANGED
|
@@ -547,8 +547,10 @@ class InfrahubClient(BaseClient):
|
|
|
547
547
|
at: Timestamp | None = None,
|
|
548
548
|
branch: str | None = None,
|
|
549
549
|
timeout: int | None = None,
|
|
550
|
+
**kwargs: Any,
|
|
550
551
|
) -> int:
|
|
551
552
|
"""Return the number of nodes of a given kind."""
|
|
553
|
+
filters = kwargs
|
|
552
554
|
schema = await self.schema.get(kind=kind, branch=branch)
|
|
553
555
|
|
|
554
556
|
branch = branch or self.default_branch
|
|
@@ -556,7 +558,10 @@ class InfrahubClient(BaseClient):
|
|
|
556
558
|
at = Timestamp(at)
|
|
557
559
|
|
|
558
560
|
response = await self.execute_graphql(
|
|
559
|
-
query=Query(query={schema.kind: {"count": None}}).render(),
|
|
561
|
+
query=Query(query={schema.kind: {"count": None, "@filters": filters}}).render(),
|
|
562
|
+
branch_name=branch,
|
|
563
|
+
at=at,
|
|
564
|
+
timeout=timeout,
|
|
560
565
|
)
|
|
561
566
|
return int(response.get(schema.kind, {}).get("count", 0))
|
|
562
567
|
|
|
@@ -781,7 +786,7 @@ class InfrahubClient(BaseClient):
|
|
|
781
786
|
nodes = []
|
|
782
787
|
related_nodes = []
|
|
783
788
|
batch_process = await self.create_batch()
|
|
784
|
-
count = await self.count(kind=schema.kind)
|
|
789
|
+
count = await self.count(kind=schema.kind, **filters)
|
|
785
790
|
total_pages = (count + pagination_size - 1) // pagination_size
|
|
786
791
|
|
|
787
792
|
for page_number in range(1, total_pages + 1):
|
|
@@ -1181,7 +1186,7 @@ class InfrahubClient(BaseClient):
|
|
|
1181
1186
|
async def allocate_next_ip_address(
|
|
1182
1187
|
self,
|
|
1183
1188
|
resource_pool: CoreNode,
|
|
1184
|
-
kind:
|
|
1189
|
+
kind: None = ...,
|
|
1185
1190
|
identifier: str | None = ...,
|
|
1186
1191
|
prefix_length: int | None = ...,
|
|
1187
1192
|
address_type: str | None = ...,
|
|
@@ -1196,7 +1201,7 @@ class InfrahubClient(BaseClient):
|
|
|
1196
1201
|
async def allocate_next_ip_address(
|
|
1197
1202
|
self,
|
|
1198
1203
|
resource_pool: CoreNode,
|
|
1199
|
-
kind:
|
|
1204
|
+
kind: None = ...,
|
|
1200
1205
|
identifier: str | None = ...,
|
|
1201
1206
|
prefix_length: int | None = ...,
|
|
1202
1207
|
address_type: str | None = ...,
|
|
@@ -1211,7 +1216,7 @@ class InfrahubClient(BaseClient):
|
|
|
1211
1216
|
async def allocate_next_ip_address(
|
|
1212
1217
|
self,
|
|
1213
1218
|
resource_pool: CoreNode,
|
|
1214
|
-
kind:
|
|
1219
|
+
kind: None = ...,
|
|
1215
1220
|
identifier: str | None = ...,
|
|
1216
1221
|
prefix_length: int | None = ...,
|
|
1217
1222
|
address_type: str | None = ...,
|
|
@@ -1328,7 +1333,7 @@ class InfrahubClient(BaseClient):
|
|
|
1328
1333
|
async def allocate_next_ip_prefix(
|
|
1329
1334
|
self,
|
|
1330
1335
|
resource_pool: CoreNode,
|
|
1331
|
-
kind:
|
|
1336
|
+
kind: None = ...,
|
|
1332
1337
|
identifier: str | None = ...,
|
|
1333
1338
|
prefix_length: int | None = ...,
|
|
1334
1339
|
member_type: str | None = ...,
|
|
@@ -1344,7 +1349,7 @@ class InfrahubClient(BaseClient):
|
|
|
1344
1349
|
async def allocate_next_ip_prefix(
|
|
1345
1350
|
self,
|
|
1346
1351
|
resource_pool: CoreNode,
|
|
1347
|
-
kind:
|
|
1352
|
+
kind: None = ...,
|
|
1348
1353
|
identifier: str | None = ...,
|
|
1349
1354
|
prefix_length: int | None = ...,
|
|
1350
1355
|
member_type: str | None = ...,
|
|
@@ -1360,7 +1365,7 @@ class InfrahubClient(BaseClient):
|
|
|
1360
1365
|
async def allocate_next_ip_prefix(
|
|
1361
1366
|
self,
|
|
1362
1367
|
resource_pool: CoreNode,
|
|
1363
|
-
kind:
|
|
1368
|
+
kind: None = ...,
|
|
1364
1369
|
identifier: str | None = ...,
|
|
1365
1370
|
prefix_length: int | None = ...,
|
|
1366
1371
|
member_type: str | None = ...,
|
|
@@ -1651,8 +1656,10 @@ class InfrahubClientSync(BaseClient):
|
|
|
1651
1656
|
at: Timestamp | None = None,
|
|
1652
1657
|
branch: str | None = None,
|
|
1653
1658
|
timeout: int | None = None,
|
|
1659
|
+
**kwargs: Any,
|
|
1654
1660
|
) -> int:
|
|
1655
1661
|
"""Return the number of nodes of a given kind."""
|
|
1662
|
+
filters = kwargs
|
|
1656
1663
|
schema = self.schema.get(kind=kind, branch=branch)
|
|
1657
1664
|
|
|
1658
1665
|
branch = branch or self.default_branch
|
|
@@ -1660,7 +1667,10 @@ class InfrahubClientSync(BaseClient):
|
|
|
1660
1667
|
at = Timestamp(at)
|
|
1661
1668
|
|
|
1662
1669
|
response = self.execute_graphql(
|
|
1663
|
-
query=Query(query={schema.kind: {"count": None}}).render(),
|
|
1670
|
+
query=Query(query={schema.kind: {"count": None, "@filters": filters}}).render(),
|
|
1671
|
+
branch_name=branch,
|
|
1672
|
+
at=at,
|
|
1673
|
+
timeout=timeout,
|
|
1664
1674
|
)
|
|
1665
1675
|
return int(response.get(schema.kind, {}).get("count", 0))
|
|
1666
1676
|
|
|
@@ -1920,7 +1930,7 @@ class InfrahubClientSync(BaseClient):
|
|
|
1920
1930
|
related_nodes = []
|
|
1921
1931
|
batch_process = self.create_batch()
|
|
1922
1932
|
|
|
1923
|
-
count = self.count(kind=schema.kind)
|
|
1933
|
+
count = self.count(kind=schema.kind, **filters)
|
|
1924
1934
|
total_pages = (count + pagination_size - 1) // pagination_size
|
|
1925
1935
|
|
|
1926
1936
|
for page_number in range(1, total_pages + 1):
|
|
@@ -2296,7 +2306,7 @@ class InfrahubClientSync(BaseClient):
|
|
|
2296
2306
|
def allocate_next_ip_address(
|
|
2297
2307
|
self,
|
|
2298
2308
|
resource_pool: CoreNodeSync,
|
|
2299
|
-
kind:
|
|
2309
|
+
kind: None = ...,
|
|
2300
2310
|
identifier: str | None = ...,
|
|
2301
2311
|
prefix_length: int | None = ...,
|
|
2302
2312
|
address_type: str | None = ...,
|
|
@@ -2311,7 +2321,7 @@ class InfrahubClientSync(BaseClient):
|
|
|
2311
2321
|
def allocate_next_ip_address(
|
|
2312
2322
|
self,
|
|
2313
2323
|
resource_pool: CoreNodeSync,
|
|
2314
|
-
kind:
|
|
2324
|
+
kind: None = ...,
|
|
2315
2325
|
identifier: str | None = ...,
|
|
2316
2326
|
prefix_length: int | None = ...,
|
|
2317
2327
|
address_type: str | None = ...,
|
|
@@ -2326,7 +2336,7 @@ class InfrahubClientSync(BaseClient):
|
|
|
2326
2336
|
def allocate_next_ip_address(
|
|
2327
2337
|
self,
|
|
2328
2338
|
resource_pool: CoreNodeSync,
|
|
2329
|
-
kind:
|
|
2339
|
+
kind: None = ...,
|
|
2330
2340
|
identifier: str | None = ...,
|
|
2331
2341
|
prefix_length: int | None = ...,
|
|
2332
2342
|
address_type: str | None = ...,
|
|
@@ -2439,7 +2449,7 @@ class InfrahubClientSync(BaseClient):
|
|
|
2439
2449
|
def allocate_next_ip_prefix(
|
|
2440
2450
|
self,
|
|
2441
2451
|
resource_pool: CoreNodeSync,
|
|
2442
|
-
kind:
|
|
2452
|
+
kind: None = ...,
|
|
2443
2453
|
identifier: str | None = ...,
|
|
2444
2454
|
prefix_length: int | None = ...,
|
|
2445
2455
|
member_type: str | None = ...,
|
|
@@ -2455,7 +2465,7 @@ class InfrahubClientSync(BaseClient):
|
|
|
2455
2465
|
def allocate_next_ip_prefix(
|
|
2456
2466
|
self,
|
|
2457
2467
|
resource_pool: CoreNodeSync,
|
|
2458
|
-
kind:
|
|
2468
|
+
kind: None = ...,
|
|
2459
2469
|
identifier: str | None = ...,
|
|
2460
2470
|
prefix_length: int | None = ...,
|
|
2461
2471
|
member_type: str | None = ...,
|
|
@@ -2471,7 +2481,7 @@ class InfrahubClientSync(BaseClient):
|
|
|
2471
2481
|
def allocate_next_ip_prefix(
|
|
2472
2482
|
self,
|
|
2473
2483
|
resource_pool: CoreNodeSync,
|
|
2474
|
-
kind:
|
|
2484
|
+
kind: None = ...,
|
|
2475
2485
|
identifier: str | None = ...,
|
|
2476
2486
|
prefix_length: int | None = ...,
|
|
2477
2487
|
member_type: str | None = ...,
|
infrahub_sdk/generator.py
CHANGED
|
@@ -4,7 +4,7 @@ import os
|
|
|
4
4
|
from abc import abstractmethod
|
|
5
5
|
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
|
-
from
|
|
7
|
+
from infrahub_sdk.repository import GitRepoManager
|
|
8
8
|
|
|
9
9
|
from .exceptions import UninitializedError
|
|
10
10
|
|
|
@@ -30,7 +30,7 @@ class InfrahubGenerator:
|
|
|
30
30
|
) -> None:
|
|
31
31
|
self.query = query
|
|
32
32
|
self.branch = branch
|
|
33
|
-
self.git:
|
|
33
|
+
self.git: GitRepoManager | None = None
|
|
34
34
|
self.params = params or {}
|
|
35
35
|
self.root_directory = root_directory or os.getcwd()
|
|
36
36
|
self.generator_instance = generator_instance
|
|
@@ -81,7 +81,7 @@ class InfrahubGenerator:
|
|
|
81
81
|
return self.branch
|
|
82
82
|
|
|
83
83
|
if not self.git:
|
|
84
|
-
self.git =
|
|
84
|
+
self.git = GitRepoManager(self.root_directory)
|
|
85
85
|
|
|
86
86
|
self.branch = str(self.git.active_branch)
|
|
87
87
|
|
infrahub_sdk/node.py
CHANGED
|
@@ -1074,7 +1074,7 @@ class InfrahubNode(InfrahubNodeBase):
|
|
|
1074
1074
|
timeout: int | None = None,
|
|
1075
1075
|
) -> Self:
|
|
1076
1076
|
if not schema:
|
|
1077
|
-
node_kind = data.get("__typename"
|
|
1077
|
+
node_kind = data.get("__typename") or data.get("node", {}).get("__typename", None)
|
|
1078
1078
|
if not node_kind:
|
|
1079
1079
|
raise ValueError("Unable to determine the type of the node, __typename not present in data")
|
|
1080
1080
|
schema = await client.schema.get(kind=node_kind, branch=branch, timeout=timeout)
|
|
@@ -1594,7 +1594,7 @@ class InfrahubNodeSync(InfrahubNodeBase):
|
|
|
1594
1594
|
timeout: int | None = None,
|
|
1595
1595
|
) -> Self:
|
|
1596
1596
|
if not schema:
|
|
1597
|
-
node_kind = data.get("__typename"
|
|
1597
|
+
node_kind = data.get("__typename") or data.get("node", {}).get("__typename", None)
|
|
1598
1598
|
if not node_kind:
|
|
1599
1599
|
raise ValueError("Unable to determine the type of the node, __typename not present in data")
|
|
1600
1600
|
schema = client.schema.get(kind=node_kind, branch=branch, timeout=timeout)
|
|
@@ -6,7 +6,6 @@ from typing import TYPE_CHECKING, Any
|
|
|
6
6
|
|
|
7
7
|
import pytest
|
|
8
8
|
import ujson
|
|
9
|
-
from git.exc import InvalidGitRepositoryError
|
|
10
9
|
|
|
11
10
|
from ..exceptions import InvalidResourceConfigError
|
|
12
11
|
from ..models import InfrahubInputOutputTest
|
|
@@ -28,7 +27,6 @@ class InfrahubItem(pytest.Item):
|
|
|
28
27
|
**kwargs: dict[str, Any],
|
|
29
28
|
):
|
|
30
29
|
super().__init__(*args, **kwargs) # type: ignore[arg-type]
|
|
31
|
-
|
|
32
30
|
self.resource_name: str = resource_name
|
|
33
31
|
self.resource_config: InfrahubRepositoryConfigElement = resource_config
|
|
34
32
|
self.test: InfrahubTest = test
|
|
@@ -68,9 +66,6 @@ class InfrahubItem(pytest.Item):
|
|
|
68
66
|
"""Run the test logic."""
|
|
69
67
|
|
|
70
68
|
def repr_failure(self, excinfo: pytest.ExceptionInfo, style: str | None = None) -> str: # noqa: ARG002
|
|
71
|
-
if isinstance(excinfo.value, InvalidGitRepositoryError):
|
|
72
|
-
return f"Invalid Git repository at {excinfo.value}"
|
|
73
|
-
|
|
74
69
|
return str(excinfo.value)
|
|
75
70
|
|
|
76
71
|
def reportinfo(self) -> tuple[Path | str, int | None, str]:
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from dulwich import porcelain
|
|
6
|
+
from dulwich.repo import Repo
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GitRepoManager:
|
|
10
|
+
def __init__(self, root_directory: str, branch: str = "main"):
|
|
11
|
+
self.root_directory = root_directory
|
|
12
|
+
self.branch = branch
|
|
13
|
+
self.git: Repo = self.initialize_repo()
|
|
14
|
+
|
|
15
|
+
def initialize_repo(self) -> Repo:
|
|
16
|
+
# Check if the directory already has a repository
|
|
17
|
+
|
|
18
|
+
root_path = Path(self.root_directory)
|
|
19
|
+
|
|
20
|
+
if root_path.exists() and (root_path / ".git").is_dir():
|
|
21
|
+
repo = Repo(self.root_directory) # Open existing repo
|
|
22
|
+
else:
|
|
23
|
+
repo = Repo.init(self.root_directory, default_branch=self.branch.encode("utf-8"))
|
|
24
|
+
|
|
25
|
+
if not repo:
|
|
26
|
+
raise ValueError("Failed to initialize or open a repository.")
|
|
27
|
+
|
|
28
|
+
return repo
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def active_branch(self) -> str | None:
|
|
32
|
+
active_branch = porcelain.active_branch(self.root_directory).decode("utf-8")
|
|
33
|
+
return active_branch
|
|
@@ -7,10 +7,11 @@ from enum import Enum
|
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
from typing import TYPE_CHECKING
|
|
9
9
|
|
|
10
|
-
from
|
|
10
|
+
from dulwich import porcelain
|
|
11
11
|
|
|
12
12
|
from infrahub_sdk.graphql import Mutation
|
|
13
13
|
from infrahub_sdk.protocols import CoreGenericRepository
|
|
14
|
+
from infrahub_sdk.repository import GitRepoManager
|
|
14
15
|
|
|
15
16
|
if TYPE_CHECKING:
|
|
16
17
|
from infrahub_sdk import InfrahubClient
|
|
@@ -37,14 +38,14 @@ class GitRepo:
|
|
|
37
38
|
|
|
38
39
|
type: GitRepoType = GitRepoType.INTEGRATED
|
|
39
40
|
|
|
40
|
-
_repo:
|
|
41
|
+
_repo: GitRepoManager | None = None
|
|
41
42
|
initial_branch: str = "main"
|
|
42
43
|
directories_to_ignore: list[str] = field(default_factory=list)
|
|
43
44
|
remote_directory_name: str = "/remote"
|
|
44
45
|
_branches: list[str] = field(default_factory=list)
|
|
45
46
|
|
|
46
47
|
@property
|
|
47
|
-
def repo(self) ->
|
|
48
|
+
def repo(self) -> GitRepoManager:
|
|
48
49
|
if self._repo:
|
|
49
50
|
return self._repo
|
|
50
51
|
raise ValueError("Repo hasn't been initialized yet")
|
|
@@ -62,12 +63,17 @@ class GitRepo:
|
|
|
62
63
|
dst=self.dst_directory / self.name,
|
|
63
64
|
ignore=shutil.ignore_patterns(".git"),
|
|
64
65
|
)
|
|
65
|
-
self._repo = Repo.init(self.dst_directory / self.name, initial_branch=self.initial_branch)
|
|
66
|
-
for untracked in self.repo.untracked_files:
|
|
67
|
-
self.repo.index.add(untracked)
|
|
68
|
-
self.repo.index.commit("First commit")
|
|
69
66
|
|
|
70
|
-
self.
|
|
67
|
+
self._repo = GitRepoManager(str(Path(self.dst_directory / self.name)), branch=self.initial_branch)
|
|
68
|
+
|
|
69
|
+
files = list(
|
|
70
|
+
porcelain.get_untracked_paths(self._repo.git.path, self._repo.git.path, self._repo.git.open_index())
|
|
71
|
+
)
|
|
72
|
+
files_to_add = [str(Path(self._repo.git.path) / t) for t in files]
|
|
73
|
+
if files_to_add:
|
|
74
|
+
porcelain.add(repo=self._repo.git.path, paths=files_to_add)
|
|
75
|
+
porcelain.commit(repo=self._repo.git.path, message="First commit")
|
|
76
|
+
porcelain.checkout_branch(self._repo.git, self.initial_branch.encode("utf-8"))
|
|
71
77
|
|
|
72
78
|
async def add_to_infrahub(self, client: InfrahubClient, branch: str | None = None) -> dict:
|
|
73
79
|
input_data = {
|
infrahub_sdk/transforms.py
CHANGED
|
@@ -5,7 +5,7 @@ import os
|
|
|
5
5
|
from abc import abstractmethod
|
|
6
6
|
from typing import TYPE_CHECKING, Any
|
|
7
7
|
|
|
8
|
-
from
|
|
8
|
+
from infrahub_sdk.repository import GitRepoManager
|
|
9
9
|
|
|
10
10
|
from .exceptions import UninitializedError
|
|
11
11
|
|
|
@@ -27,7 +27,7 @@ class InfrahubTransform:
|
|
|
27
27
|
server_url: str = "",
|
|
28
28
|
client: InfrahubClient | None = None,
|
|
29
29
|
):
|
|
30
|
-
self.git:
|
|
30
|
+
self.git: GitRepoManager
|
|
31
31
|
|
|
32
32
|
self.branch = branch
|
|
33
33
|
self.server_url = server_url or os.environ.get("INFRAHUB_URL", "http://127.0.0.1:8000")
|
|
@@ -56,7 +56,7 @@ class InfrahubTransform:
|
|
|
56
56
|
return self.branch
|
|
57
57
|
|
|
58
58
|
if not hasattr(self, "git") or not self.git:
|
|
59
|
-
self.git =
|
|
59
|
+
self.git = GitRepoManager(self.root_directory)
|
|
60
60
|
|
|
61
61
|
self.branch = str(self.git.active_branch)
|
|
62
62
|
|
infrahub_sdk/utils.py
CHANGED
|
@@ -9,13 +9,14 @@ from uuid import UUID, uuid4
|
|
|
9
9
|
|
|
10
10
|
import httpx
|
|
11
11
|
import ujson
|
|
12
|
-
from git.repo import Repo
|
|
13
12
|
from graphql import (
|
|
14
13
|
FieldNode,
|
|
15
14
|
InlineFragmentNode,
|
|
16
15
|
SelectionSetNode,
|
|
17
16
|
)
|
|
18
17
|
|
|
18
|
+
from infrahub_sdk.repository import GitRepoManager
|
|
19
|
+
|
|
19
20
|
from .exceptions import JsonDecodeError
|
|
20
21
|
|
|
21
22
|
if TYPE_CHECKING:
|
|
@@ -135,8 +136,12 @@ def deep_merge_dict(dicta: dict, dictb: dict, path: list | None = None) -> dict:
|
|
|
135
136
|
if key in dicta:
|
|
136
137
|
if isinstance(dicta[key], dict) and isinstance(dictb[key], dict):
|
|
137
138
|
deep_merge_dict(dicta[key], dictb[key], path + [str(key)])
|
|
139
|
+
elif isinstance(dicta[key], list) and isinstance(dictb[key], list):
|
|
140
|
+
# Merge lists
|
|
141
|
+
# Cannot use compare_list because list of dicts won't work (dict not hashable)
|
|
142
|
+
dicta[key] = [i for i in dicta[key] if i not in dictb[key]] + dictb[key]
|
|
138
143
|
elif dicta[key] == dictb[key]:
|
|
139
|
-
|
|
144
|
+
continue
|
|
140
145
|
else:
|
|
141
146
|
raise ValueError("Conflict at %s" % ".".join(path + [str(key)]))
|
|
142
147
|
else:
|
|
@@ -246,7 +251,7 @@ def get_branch(branch: str | None = None, directory: str | Path = ".") -> str:
|
|
|
246
251
|
if branch:
|
|
247
252
|
return branch
|
|
248
253
|
|
|
249
|
-
repo =
|
|
254
|
+
repo = GitRepoManager(directory)
|
|
250
255
|
return str(repo.active_branch)
|
|
251
256
|
|
|
252
257
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: infrahub-server
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.4
|
|
4
4
|
Summary: Infrahub is taking a new approach to Infrastructure Management by providing a new generation of datastore to organize and control all the data that defines how an infrastructure should run.
|
|
5
5
|
Home-page: https://opsmill.com
|
|
6
6
|
License: AGPL-3.0-only
|
|
@@ -20,6 +20,7 @@ Requires-Dist: asgi-correlation-id (==4.2.0)
|
|
|
20
20
|
Requires-Dist: authlib (==1.3.2)
|
|
21
21
|
Requires-Dist: bcrypt (>=4.1,<4.2)
|
|
22
22
|
Requires-Dist: boto3 (==1.34.129)
|
|
23
|
+
Requires-Dist: dulwich (>=0.22.7,<0.23.0)
|
|
23
24
|
Requires-Dist: email-validator (>=2.1,<2.2)
|
|
24
25
|
Requires-Dist: fastapi (>=0.115,<0.116)
|
|
25
26
|
Requires-Dist: fastapi-storages (>=0.3,<0.4)
|
|
@@ -14,7 +14,7 @@ infrahub/api/menu.py,sha256=xp5bj5JXQZA6ZEPWoTSGGSfTXZ1sVmehMxr3VSG7FlQ,1216
|
|
|
14
14
|
infrahub/api/oauth2.py,sha256=9rOAM2DPvuS25lHPc6M2YRx0Aso1NDHqqk62SevnMpE,5517
|
|
15
15
|
infrahub/api/oidc.py,sha256=wyQXVVqQ0-GFhcVTtB2FwHC8AxV-pwGffRwdaSV7V2E,7240
|
|
16
16
|
infrahub/api/query.py,sha256=uZ93JJpaLzj9Y3O6IzxFGasLY26XTHLlyrwIJHd_kyg,6976
|
|
17
|
-
infrahub/api/schema.py,sha256=
|
|
17
|
+
infrahub/api/schema.py,sha256=1IS6H03fplhkyXa9v0uADiIhz1bad04L95xStNGb1sY,16611
|
|
18
18
|
infrahub/api/static/redoc.standalone.js,sha256=77kGx7mVN9EcdER2ZM4gQ-E-ra_N6AZq9QseAeD6kt0,1042008
|
|
19
19
|
infrahub/api/static/swagger-ui-bundle.js,sha256=wuSp7wgUSDn_R8FCAgY-z-TlnnCk5xVKJr1Q2IDIi6E,1452753
|
|
20
20
|
infrahub/api/static/swagger-ui.css,sha256=QBcPDuhZ0X-SExunBzKaiKBw5PZodNETZemnfSMvYRc,152071
|
|
@@ -33,7 +33,7 @@ infrahub/computed_attribute/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
|
33
33
|
infrahub/computed_attribute/constants.py,sha256=oTMPEfRuf2mcfCkBpRLWRALO6nsLHpFm9jJGu0lowS4,446
|
|
34
34
|
infrahub/computed_attribute/models.py,sha256=icUzsu0DrGoxMkBVXpNiv17rMo0OwpSE-QBJyWblMM0,2637
|
|
35
35
|
infrahub/computed_attribute/tasks.py,sha256=xjRHUz48L6IxE7UjSUMHp7UZCoFFaO-N8FCelK4Y4nY,33141
|
|
36
|
-
infrahub/config.py,sha256=
|
|
36
|
+
infrahub/config.py,sha256=DQFXa6e6nbW6McdLVViuCcKYlGjw9ytmYDsKU5l-Jdo,33605
|
|
37
37
|
infrahub/core/__init__.py,sha256=z6EJBZyCYCBqinoBtX9li6BTBbbGV8WCkE_4CrEsmDA,104
|
|
38
38
|
infrahub/core/account.py,sha256=sggpuO_QpwYH7wXG_lZDnrB5Izmej486o_CYiYjYin8,26497
|
|
39
39
|
infrahub/core/attribute.py,sha256=sDhl2BBoX_Q3BR6v8lZE85j5wIuXvswATiCC57tPoqU,42045
|
|
@@ -42,7 +42,7 @@ infrahub/core/branch/constants.py,sha256=RJxn6dPZGXrnkmOYcRkx6h7IYFp_RCOgoupj1Br
|
|
|
42
42
|
infrahub/core/branch/flow_models.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
43
|
infrahub/core/branch/models.py,sha256=dX37fBbHA84WS7Se2nwSwvOyF4bZVVzZ3oXsV46x-so,19607
|
|
44
44
|
infrahub/core/branch/tasks.py,sha256=JgjwBafBfn2CdTLr93dP6zVxqoJnAbY4FdXACrNJMdU,18448
|
|
45
|
-
infrahub/core/constants/__init__.py,sha256=
|
|
45
|
+
infrahub/core/constants/__init__.py,sha256=CWAeCuj5sPjJMmCK1l3bniRT_s2dEHAOJ7tny9RqpKM,6864
|
|
46
46
|
infrahub/core/constants/database.py,sha256=lxesWX2z6SZgGok1bAY6_pCBm5rFfu7k4ayMBr6w_Vo,336
|
|
47
47
|
infrahub/core/constants/infrahubkind.py,sha256=UVPYZdsUDjG0LvfCLgKdnJC12dFlpCC6YH2Mp-N7Zp4,2378
|
|
48
48
|
infrahub/core/constants/relationship_label.py,sha256=AWbWghu5MoAKg2DBE-ysdzSOXnWoWdBn98zpIHzn_co,87
|
|
@@ -199,7 +199,7 @@ infrahub/core/relationship/constraints/peer_kind.py,sha256=d0Ca4tLt45kU1yfe3UN79
|
|
|
199
199
|
infrahub/core/relationship/constraints/profiles_kind.py,sha256=ztnc5uh84h-IANHxn6HfIHcJJf4Cga_3waXEh7eIMrQ,2449
|
|
200
200
|
infrahub/core/relationship/model.py,sha256=aAck4EmVsw0DLbT71JeLt8kV7q2QyDi_yzYST6Xu4Z4,44729
|
|
201
201
|
infrahub/core/root.py,sha256=8ZLSOtnmjQcrjqX2vxNO-AGopEUArmBPo_X5NeZBdP0,416
|
|
202
|
-
infrahub/core/schema/__init__.py,sha256=
|
|
202
|
+
infrahub/core/schema/__init__.py,sha256=0L8vLxx7VwuqCkySA3PgZa91rfnIWeQcuwfeDqFqMZM,3926
|
|
203
203
|
infrahub/core/schema/attribute_schema.py,sha256=oyU-Z8BFLnyEy1q41uukfVQKMUevS0sZ8Ug2m_J3MXk,5022
|
|
204
204
|
infrahub/core/schema/basenode_schema.py,sha256=wPw-qYh1utxjWzLcrwZ8col8ZukfAx7HBPfI1Qici6U,19507
|
|
205
205
|
infrahub/core/schema/computed_attribute.py,sha256=Hf5_2p01SSaIJ_oo4Vkpw7E_Z2FtV_8M0RB1Ol4IebA,1825
|
|
@@ -579,12 +579,12 @@ infrahub/workflows/models.py,sha256=Egyrlxsl3QiW7vITis7Lg8MznG9QLCUs9_KHzf_Qh3c,
|
|
|
579
579
|
infrahub/workflows/utils.py,sha256=oXeQY0Zx3xOLi0ghQZXVBAZcr6lQPaOjCJ9iya1ZNos,2554
|
|
580
580
|
infrahub_sdk/__init__.py,sha256=weZAa06Ar0NO5IOKLQICtCceHUCKQxbkBxHebqQGJ1o,401
|
|
581
581
|
infrahub_sdk/_importer.py,sha256=8oHTMxa_AMO_qbfb3UXNfjSr31S5YJTcqe-YMrixY_E,2257
|
|
582
|
-
infrahub_sdk/analyzer.py,sha256=
|
|
582
|
+
infrahub_sdk/analyzer.py,sha256=UDJN372vdAiuAv2TEyPUlsSVoUfZN6obWkIokNNaHbA,4148
|
|
583
583
|
infrahub_sdk/async_typer.py,sha256=Gj7E8EGdjA-XF404vr9cBt20mmbroQh7N68HXhWYx00,892
|
|
584
584
|
infrahub_sdk/batch.py,sha256=WSAPAPvRvcHR7aCFH56RcqKaVxsig1A5nIdg0mmSZBQ,3879
|
|
585
585
|
infrahub_sdk/branch.py,sha256=hmtoIekQ1uusoJ6yEKlw6vrFMTAHJrXu-YsqqCQC_kc,12716
|
|
586
|
-
infrahub_sdk/checks.py,sha256=
|
|
587
|
-
infrahub_sdk/client.py,sha256=
|
|
586
|
+
infrahub_sdk/checks.py,sha256=AmlCim-9Mbhpye_yYAaV_NM-pFL4_JvQGEVM3cJsaqY,5700
|
|
587
|
+
infrahub_sdk/client.py,sha256=yuD-uvx_5LLXqHm9sjo0jei1AH-xGgl4DhYJcoqH8uw,99592
|
|
588
588
|
infrahub_sdk/code_generator.py,sha256=UJoqofjO7WSHygORhok0RRUv7HG4aTcl6htczaKNBjc,4411
|
|
589
589
|
infrahub_sdk/config.py,sha256=hjF4Fo6NrxxLHaS1XBZ1O2o0aU7IILEyhPXRiiRedjc,7190
|
|
590
590
|
infrahub_sdk/constants.py,sha256=Ca66r09eDzpmMhfFAspKFSehSxOmoflVongP-UuBDc4,138
|
|
@@ -613,11 +613,11 @@ infrahub_sdk/ctl/validate.py,sha256=6DHhk6ubZih-FaNfX6m8G0HwOEJuJk6DFHCg1oAaZtQ,
|
|
|
613
613
|
infrahub_sdk/data.py,sha256=t3jCqmnYM8rhTZlPlc37aW8zKMKLLVcTWHozH9qb0Bs,870
|
|
614
614
|
infrahub_sdk/diff.py,sha256=Ms-3YyXo-DoF1feV9qP7GKakBYUNFsULZdy-yMEG71w,4258
|
|
615
615
|
infrahub_sdk/exceptions.py,sha256=S563xPBgwvdXkVS42XLLTuCkdVnrXOZyDSY8aFd3udc,4436
|
|
616
|
-
infrahub_sdk/generator.py,sha256=
|
|
616
|
+
infrahub_sdk/generator.py,sha256=TVxSDByNnnuqFOpmi2mBgUZnU07PudvH8J-aM8QtwMM,5242
|
|
617
617
|
infrahub_sdk/graphql.py,sha256=qw1HJ95-JhRS_zrsyDj5P_PWKuUNgoXvH1q-Kfs27IA,5861
|
|
618
618
|
infrahub_sdk/groups.py,sha256=GL14ByW4GHrkqOLJ-_vGhu6bkYDxljqPtkErcQVehv0,711
|
|
619
619
|
infrahub_sdk/jinja2.py,sha256=lTfV9E_P5gApaX6RW9M8U8oixQi-0H3U8wcs8fdGVaU,1150
|
|
620
|
-
infrahub_sdk/node.py,sha256=
|
|
620
|
+
infrahub_sdk/node.py,sha256=kwVswivc5kPnmzXjFB8Mt-BFbLhOQcp70PMl63CmkIc,87484
|
|
621
621
|
infrahub_sdk/object_store.py,sha256=d-EDnxPpw_7BsbjbGbH50rjt-1-Ojj2zNrhFansP5hA,4299
|
|
622
622
|
infrahub_sdk/playback.py,sha256=ubkY1LiW_wFwm4auerdQ0zFJcFJZ1SYQT6-d4bxzaLg,1906
|
|
623
623
|
infrahub_sdk/protocols.py,sha256=vmAuV_IjjbslSshrmFjKYcSMtyzi0vlgwj9UufCo4Hc,21233
|
|
@@ -625,7 +625,7 @@ infrahub_sdk/protocols_base.py,sha256=9aE5K2mwZ0xAza_yBppVWVRDds9ALhQqJofOjT-Ala
|
|
|
625
625
|
infrahub_sdk/pytest_plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
626
626
|
infrahub_sdk/pytest_plugin/exceptions.py,sha256=ek2WyTBPuZdxhJClOhLo4EcFdvgE4BP0q26OiAr-Sec,2185
|
|
627
627
|
infrahub_sdk/pytest_plugin/items/__init__.py,sha256=Au90dLk6lbSgRAoqrZOdYJ6m0lwFJYHFiAQHrcc6_rI,1026
|
|
628
|
-
infrahub_sdk/pytest_plugin/items/base.py,sha256
|
|
628
|
+
infrahub_sdk/pytest_plugin/items/base.py,sha256=-S7Xp3Zf7oQkw8EuqUI9lWWBzhKTfNdkn0UUjSqX9Zc,3068
|
|
629
629
|
infrahub_sdk/pytest_plugin/items/check.py,sha256=cEF9jC61EJzlYCf1YUGF241XO7F7zhkHAg2T_EPmIN8,3364
|
|
630
630
|
infrahub_sdk/pytest_plugin/items/graphql_query.py,sha256=DfYF9hdnhHEHqPCMd7wq0XQaY8HnQXlAjMbalc3UfdI,2346
|
|
631
631
|
infrahub_sdk/pytest_plugin/items/jinja2_transform.py,sha256=qmsJqOXnTNzJFp2zR4uC3FJEGTL7Pci7T5LhOGDNfLE,5360
|
|
@@ -637,6 +637,7 @@ infrahub_sdk/pytest_plugin/utils.py,sha256=AfSAgRXBGdx__8MNQJG7faw68ioZzk37CM4ZP
|
|
|
637
637
|
infrahub_sdk/queries.py,sha256=s4gnx67e-MNg-3jP4Vx1jreO9uiW3uYPllFQgaTODdQ,2308
|
|
638
638
|
infrahub_sdk/query_groups.py,sha256=Hg6MdjU9wSWQmtKktlmKCHcwjlodz7L_VPPou-jC8vk,11434
|
|
639
639
|
infrahub_sdk/recorder.py,sha256=G134AfAwE5efSqArVJneurF2JIEuhvSJWWI3woPczgI,2194
|
|
640
|
+
infrahub_sdk/repository.py,sha256=PbSHHl6ajIeZu1t4pH1j7qzR-DPOkGuzubcNM02NuV0,1011
|
|
640
641
|
infrahub_sdk/schema/__init__.py,sha256=RINn1qvejp88Y57Ov1D7ceYkxV2gpYMucldJPiNkjLU,25879
|
|
641
642
|
infrahub_sdk/schema/main.py,sha256=rySdEBJNMVpulWKMRw3ARqSbZPiFBHRYR2nqZvYp1VY,10580
|
|
642
643
|
infrahub_sdk/schema/repository.py,sha256=AAITXGprCPb2WptJSRhj9gEbRrW1HHM-yEPYAgsztcU,11299
|
|
@@ -644,10 +645,9 @@ infrahub_sdk/spec/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
|
644
645
|
infrahub_sdk/spec/menu.py,sha256=LvNLuBEkiLTMNgM3kseIzM7wQ_zK_2uXM_anUNu6Pfc,1059
|
|
645
646
|
infrahub_sdk/spec/object.py,sha256=H55fctUrQUDbRrRJJQQcXHppVOeMye6ykBoo6lCasDw,5012
|
|
646
647
|
infrahub_sdk/store.py,sha256=kWJ9UvirLuSHLuDDzTd4-ualTkuRocy9W0J7TdL60Po,5734
|
|
647
|
-
infrahub_sdk/task_report.py,sha256=17z02C1g2mkHRoUBAzAgGVLeHXw7X1YHxBLyJ5b8a_M,6400
|
|
648
648
|
infrahub_sdk/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
649
649
|
infrahub_sdk/testing/docker.py,sha256=V089h9fGjNnXVdw7Fw-mloSBgSnjXT9rvnDpj7cecoI,724
|
|
650
|
-
infrahub_sdk/testing/repository.py,sha256=
|
|
650
|
+
infrahub_sdk/testing/repository.py,sha256=9s4MMaMljbJe97Ua4bJgc64giQ2UMC0bD5qIqYd4YNk,3571
|
|
651
651
|
infrahub_sdk/testing/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
652
652
|
infrahub_sdk/testing/schemas/animal.py,sha256=5frpoBCeGaM05X8sFxIDQUH93JrPsa-kIYKb8xcQxcw,6796
|
|
653
653
|
infrahub_sdk/testing/schemas/car_person.py,sha256=1VwgJMJvVggsQyRdSqDjiLrPzysz8cXFSFzSghVSVms,8940
|
|
@@ -663,17 +663,17 @@ infrahub_sdk/transfer/importer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5
|
|
|
663
663
|
infrahub_sdk/transfer/importer/interface.py,sha256=TN7FH_LgThkBjrpWwkdTZIVJPtNklAYiK3Mn6RPs7IM,195
|
|
664
664
|
infrahub_sdk/transfer/importer/json.py,sha256=-Tlmg22TiBrEqXOSLMnUzlCFOZ2M0Q8lWyPbwjUjifw,9654
|
|
665
665
|
infrahub_sdk/transfer/schema_sorter.py,sha256=ZoBjJGFT-6jQoKOLaoOPMAWzs7vGOeo7x6zOOP4LNv0,1244
|
|
666
|
-
infrahub_sdk/transforms.py,sha256=
|
|
666
|
+
infrahub_sdk/transforms.py,sha256=5fmoBBKWGhFCu0NLKlSF95GAbbCi2k25zWiWjtsd2dA,2558
|
|
667
667
|
infrahub_sdk/types.py,sha256=UeZ1rDp4eyH12ApTcUD9a1OOtCp3IL1YZUeeZ06qF-I,1726
|
|
668
|
-
infrahub_sdk/utils.py,sha256=
|
|
668
|
+
infrahub_sdk/utils.py,sha256=5rnk-ZfMoMvNHH72D0Bb5OVRjyk6cJ__UoKvZlUNzns,11064
|
|
669
669
|
infrahub_sdk/uuidt.py,sha256=Tz-4nHkJwbi39UT3gaIe2wJeZNAoBqf6tm3sw7LZbXc,2155
|
|
670
670
|
infrahub_sdk/yaml.py,sha256=dxdzEjuaG-OwF2XIcA2YXoFEmF4TeiwKju5K2uOQhgQ,2963
|
|
671
671
|
infrahub_testcontainers/__init__.py,sha256=oPpmesGgYBSdKTg1L37FGwYBeao1EHury5SJGul-CT8,216
|
|
672
672
|
infrahub_testcontainers/container.py,sha256=g0AOvnV3z_-wGCMOUBCaK4-U_ST38YvGXYqZbfGtKXY,4421
|
|
673
673
|
infrahub_testcontainers/docker-compose.test.yml,sha256=MAF39rw6DONzZq1b2Ujndu545RI2xvOuq1PjHwc8Vto,5360
|
|
674
674
|
infrahub_testcontainers/helpers.py,sha256=3K6Bbfcr19DwH9pfc-WE6ehqIUbAXx1NruVOkKJoXvY,2274
|
|
675
|
-
infrahub_server-1.1.
|
|
676
|
-
infrahub_server-1.1.
|
|
677
|
-
infrahub_server-1.1.
|
|
678
|
-
infrahub_server-1.1.
|
|
679
|
-
infrahub_server-1.1.
|
|
675
|
+
infrahub_server-1.1.4.dist-info/LICENSE.txt,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
|
|
676
|
+
infrahub_server-1.1.4.dist-info/METADATA,sha256=HMfxxKxYt5GYldw7IAWcdlLApcBWgmy8EPeqg5r8Fpc,4702
|
|
677
|
+
infrahub_server-1.1.4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
678
|
+
infrahub_server-1.1.4.dist-info/entry_points.txt,sha256=JNQoBcLpUyfeOMhls_-uX1CdJ8Vl-AFSh9UhzTcKdjA,329
|
|
679
|
+
infrahub_server-1.1.4.dist-info/RECORD,,
|
infrahub_sdk/task_report.py
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING, Any, Final, Protocol, TypedDict, Union, runtime_checkable
|
|
4
|
-
|
|
5
|
-
from typing_extensions import Self
|
|
6
|
-
|
|
7
|
-
from .uuidt import generate_uuid
|
|
8
|
-
|
|
9
|
-
if TYPE_CHECKING:
|
|
10
|
-
from types import TracebackType
|
|
11
|
-
|
|
12
|
-
from .client import InfrahubClient
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class Log(TypedDict):
|
|
16
|
-
message: str
|
|
17
|
-
severity: str
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
TaskLogs = Union[list[Log], Log]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class TaskReport:
|
|
24
|
-
def __init__(
|
|
25
|
-
self,
|
|
26
|
-
client: InfrahubClient,
|
|
27
|
-
logger: InfrahubLogger,
|
|
28
|
-
related_node: str,
|
|
29
|
-
title: str,
|
|
30
|
-
task_id: str | None = None,
|
|
31
|
-
created_by: str | None = None,
|
|
32
|
-
create_with_context: bool = True,
|
|
33
|
-
):
|
|
34
|
-
self.client = client
|
|
35
|
-
self.title = title
|
|
36
|
-
self.task_id: Final = task_id or generate_uuid()
|
|
37
|
-
self.related_node: Final = related_node
|
|
38
|
-
self.created_by: Final = created_by
|
|
39
|
-
self.has_failures: bool = False
|
|
40
|
-
self.finalized: bool = False
|
|
41
|
-
self.created: bool = False
|
|
42
|
-
self.create_with_context = create_with_context
|
|
43
|
-
self.log = logger
|
|
44
|
-
|
|
45
|
-
async def __aenter__(self) -> Self:
|
|
46
|
-
if self.create_with_context:
|
|
47
|
-
await self.create()
|
|
48
|
-
return self
|
|
49
|
-
|
|
50
|
-
async def __aexit__(
|
|
51
|
-
self,
|
|
52
|
-
exc_type: type[BaseException] | None,
|
|
53
|
-
exc_value: BaseException | None,
|
|
54
|
-
traceback: TracebackType | None,
|
|
55
|
-
) -> None:
|
|
56
|
-
if exc_type:
|
|
57
|
-
self.finalized = True
|
|
58
|
-
await self.update(conclusion="FAILURE", logs={"message": str(exc_value), "severity": "ERROR"})
|
|
59
|
-
|
|
60
|
-
if self.finalized or not self.created:
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
conclusion = "FAILURE" if self.has_failures else "SUCCESS"
|
|
64
|
-
await self.update(conclusion=conclusion)
|
|
65
|
-
|
|
66
|
-
async def create(self, title: str | None = None, conclusion: str = "UNKNOWN", logs: TaskLogs | None = None) -> None:
|
|
67
|
-
variables: dict[str, Any] = {
|
|
68
|
-
"related_node": self.related_node,
|
|
69
|
-
"task_id": self.task_id,
|
|
70
|
-
"title": title or self.title,
|
|
71
|
-
"conclusion": conclusion,
|
|
72
|
-
}
|
|
73
|
-
if self.created_by:
|
|
74
|
-
variables["created_by"] = self.created_by
|
|
75
|
-
if logs:
|
|
76
|
-
variables["logs"] = logs
|
|
77
|
-
|
|
78
|
-
await self.client.execute_graphql(
|
|
79
|
-
query=CREATE_TASK,
|
|
80
|
-
variables=variables,
|
|
81
|
-
)
|
|
82
|
-
self.created = True
|
|
83
|
-
|
|
84
|
-
async def info(self, event: str, *args: Any, **kw: Any) -> None:
|
|
85
|
-
self.log.info(event, *args, **kw)
|
|
86
|
-
await self.update(logs={"severity": "INFO", "message": event})
|
|
87
|
-
|
|
88
|
-
async def warning(self, event: str, *args: Any, **kw: Any) -> None:
|
|
89
|
-
self.log.warning(event, *args, **kw)
|
|
90
|
-
await self.update(logs={"severity": "WARNING", "message": event})
|
|
91
|
-
|
|
92
|
-
async def error(self, event: str, *args: Any, **kw: Any) -> None:
|
|
93
|
-
self.log.error(event, *args, **kw)
|
|
94
|
-
self.has_failures = True
|
|
95
|
-
await self.update(logs={"severity": "ERROR", "message": event})
|
|
96
|
-
|
|
97
|
-
async def critical(self, event: str, *args: Any, **kw: Any) -> None:
|
|
98
|
-
self.log.critical(event, *args, **kw)
|
|
99
|
-
self.has_failures = True
|
|
100
|
-
await self.update(logs={"severity": "CRITICAL", "message": event})
|
|
101
|
-
|
|
102
|
-
async def exception(self, event: str, *args: Any, **kw: Any) -> None:
|
|
103
|
-
self.log.critical(event, *args, **kw)
|
|
104
|
-
self.has_failures = True
|
|
105
|
-
await self.update(logs={"severity": "CRITICAL", "message": event})
|
|
106
|
-
|
|
107
|
-
async def finalise(
|
|
108
|
-
self, title: str | None = None, conclusion: str = "SUCCESS", logs: TaskLogs | None = None
|
|
109
|
-
) -> None:
|
|
110
|
-
self.finalized = True
|
|
111
|
-
await self.update(title=title, conclusion=conclusion, logs=logs)
|
|
112
|
-
|
|
113
|
-
async def update(
|
|
114
|
-
self, title: str | None = None, conclusion: str | None = None, logs: TaskLogs | None = None
|
|
115
|
-
) -> None:
|
|
116
|
-
if not self.created:
|
|
117
|
-
await self.create()
|
|
118
|
-
variables: dict[str, Any] = {"task_id": self.task_id}
|
|
119
|
-
if conclusion:
|
|
120
|
-
variables["conclusion"] = conclusion
|
|
121
|
-
if title:
|
|
122
|
-
variables["title"] = title
|
|
123
|
-
if logs:
|
|
124
|
-
variables["logs"] = logs
|
|
125
|
-
await self.client.execute_graphql(query=UPDATE_TASK, variables=variables)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
class InfrahubLogger(Protocol):
|
|
129
|
-
def debug(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
130
|
-
"""Send a debug event"""
|
|
131
|
-
|
|
132
|
-
def info(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
133
|
-
"""Send an info event"""
|
|
134
|
-
|
|
135
|
-
def warning(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
136
|
-
"""Send a warning event"""
|
|
137
|
-
|
|
138
|
-
def error(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
139
|
-
"""Send an error event."""
|
|
140
|
-
|
|
141
|
-
def critical(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
142
|
-
"""Send a critical event."""
|
|
143
|
-
|
|
144
|
-
def exception(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
145
|
-
"""Send an exception event."""
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
@runtime_checkable
|
|
149
|
-
class InfrahubTaskReportLogger(Protocol):
|
|
150
|
-
async def info(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
151
|
-
"""Send an info event"""
|
|
152
|
-
|
|
153
|
-
async def warning(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
154
|
-
"""Send a warning event"""
|
|
155
|
-
|
|
156
|
-
async def error(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
157
|
-
"""Send an error event."""
|
|
158
|
-
|
|
159
|
-
async def critical(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
160
|
-
"""Send a critical event."""
|
|
161
|
-
|
|
162
|
-
async def exception(self, event: str | None = None, *args: Any, **kw: Any) -> Any:
|
|
163
|
-
"""Send an exception event."""
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
CREATE_TASK = """
|
|
167
|
-
mutation CreateTask(
|
|
168
|
-
$conclusion: TaskConclusion!,
|
|
169
|
-
$title: String!,
|
|
170
|
-
$task_id: UUID,
|
|
171
|
-
$related_node: String!,
|
|
172
|
-
$created_by: String,
|
|
173
|
-
$logs: [RelatedTaskLogCreateInput]
|
|
174
|
-
) {
|
|
175
|
-
InfrahubTaskCreate(
|
|
176
|
-
data: {
|
|
177
|
-
id: $task_id,
|
|
178
|
-
title: $title,
|
|
179
|
-
related_node: $related_node,
|
|
180
|
-
conclusion: $conclusion,
|
|
181
|
-
created_by: $created_by,
|
|
182
|
-
logs: $logs
|
|
183
|
-
}
|
|
184
|
-
) {
|
|
185
|
-
ok
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
"""
|
|
189
|
-
|
|
190
|
-
UPDATE_TASK = """
|
|
191
|
-
mutation UpdateTask(
|
|
192
|
-
$conclusion: TaskConclusion,
|
|
193
|
-
$title: String,
|
|
194
|
-
$task_id: UUID!,
|
|
195
|
-
$logs: [RelatedTaskLogCreateInput]
|
|
196
|
-
) {
|
|
197
|
-
InfrahubTaskUpdate(
|
|
198
|
-
data: {
|
|
199
|
-
id: $task_id,
|
|
200
|
-
title: $title,
|
|
201
|
-
conclusion: $conclusion,
|
|
202
|
-
logs: $logs
|
|
203
|
-
}
|
|
204
|
-
) {
|
|
205
|
-
ok
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|