Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions infrahub_sdk/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pydantic import BaseModel, Field

from . import InfrahubClient
from .exceptions import InfrahubCheckNotFoundError
from .exceptions import InfrahubCheckNotFoundError, UninitializedError

if TYPE_CHECKING:
from pathlib import Path
Expand Down Expand Up @@ -41,6 +41,7 @@
output: Optional[str] = None,
initializer: Optional[InfrahubCheckInitializer] = None,
params: Optional[dict] = None,
client: Optional[InfrahubClient] = None,
):
self.git: Optional[Repo] = None
self.initializer = initializer or InfrahubCheckInitializer()
Expand All @@ -55,7 +56,7 @@

self.root_directory = root_directory or os.getcwd()

self.client: InfrahubClient
self._client = client

if not self.name:
self.name = self.__class__.__name__
Expand All @@ -66,6 +67,17 @@
def __str__(self) -> str:
return self.__class__.__name__

@property
def client(self) -> InfrahubClient:
if self._client:
return self._client

raise UninitializedError(message="This check has not been initialized with a client")

Check warning on line 75 in infrahub_sdk/checks.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/checks.py#L75

Added line #L75 was not covered by tests

@client.setter
def client(self, value: InfrahubClient) -> None:
self._client = value

@classmethod
async def init(cls, client: Optional[InfrahubClient] = None, *args: Any, **kwargs: Any) -> InfrahubCheck:
"""Async init method, If an existing InfrahubClient client hasn't been provided, one will be created automatically."""
Expand Down