Skip to content

Commit 2e04802

Browse files
authored
Merge pull request #115 from opsmill/pog-add-client-to-check
Add ability to initialize a Check with a client
2 parents 5bbb22d + 065729b commit 2e04802

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

infrahub_sdk/checks.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pydantic import BaseModel, Field
1212

1313
from . import InfrahubClient
14-
from .exceptions import InfrahubCheckNotFoundError
14+
from .exceptions import InfrahubCheckNotFoundError, UninitializedError
1515

1616
if TYPE_CHECKING:
1717
from pathlib import Path
@@ -41,6 +41,7 @@ def __init__(
4141
output: Optional[str] = None,
4242
initializer: Optional[InfrahubCheckInitializer] = None,
4343
params: Optional[dict] = None,
44+
client: Optional[InfrahubClient] = None,
4445
):
4546
self.git: Optional[Repo] = None
4647
self.initializer = initializer or InfrahubCheckInitializer()
@@ -55,7 +56,7 @@ def __init__(
5556

5657
self.root_directory = root_directory or os.getcwd()
5758

58-
self.client: InfrahubClient
59+
self._client = client
5960

6061
if not self.name:
6162
self.name = self.__class__.__name__
@@ -66,6 +67,17 @@ def __init__(
6667
def __str__(self) -> str:
6768
return self.__class__.__name__
6869

70+
@property
71+
def client(self) -> InfrahubClient:
72+
if self._client:
73+
return self._client
74+
75+
raise UninitializedError(message="This check has not been initialized with a client")
76+
77+
@client.setter
78+
def client(self, value: InfrahubClient) -> None:
79+
self._client = value
80+
6981
@classmethod
7082
async def init(cls, client: Optional[InfrahubClient] = None, *args: Any, **kwargs: Any) -> InfrahubCheck:
7183
"""Async init method, If an existing InfrahubClient client hasn't been provided, one will be created automatically."""

0 commit comments

Comments
 (0)