77from abc import abstractmethod
88from typing import TYPE_CHECKING , Any , Optional
99
10- import httpx
1110from git import Repo
1211
1312from infrahub_sdk import InfrahubClient
1716if TYPE_CHECKING :
1817 from pathlib import Path
1918
20- from .schema import InfrahubPythonTransformConfig , InfrahubRepositoryConfig
19+ from .schema import InfrahubPythonTransformConfig
2120
2221INFRAHUB_TRANSFORM_VARIABLE_TO_IMPORT = "INFRAHUB_TRANSFORMS"
2322
@@ -33,14 +32,12 @@ def __init__(
3332 root_directory : str = "" ,
3433 server_url : str = "" ,
3534 client : Optional [InfrahubClient ] = None ,
36- repository_config : Optional [InfrahubRepositoryConfig ] = None ,
3735 ):
3836 self .git : Repo
3937
4038 self .branch = branch
4139 self .server_url = server_url or os .environ .get ("INFRAHUB_URL" , "http://127.0.0.1:8000" )
4240 self .root_directory = root_directory or os .getcwd ()
43- self .repository_config = repository_config
4441
4542 self ._client = client
4643
@@ -61,7 +58,7 @@ def client(self) -> InfrahubClient:
6158 async def init (cls , client : Optional [InfrahubClient ] = None , * args : Any , ** kwargs : Any ) -> InfrahubTransform :
6259 """Async init method, If an existing InfrahubClient client hasn't been provided, one will be created automatically."""
6360 warnings .warn (
64- "InfrahubClient. init has been deprecated and will be removed in Infrahub SDK 0.14 .0 or the next major version" ,
61+ f" { cls . __class__ . __name__ } . init has been deprecated and will be removed in Infrahub SDK 0.15 .0 or the next major version" ,
6562 DeprecationWarning ,
6663 stacklevel = 1 ,
6764 )
@@ -90,39 +87,24 @@ def branch_name(self) -> str:
9087 def transform (self , data : dict ) -> Any :
9188 pass
9289
93- async def collect_data (self , variables : Optional [ dict ] = None ) -> dict :
90+ async def collect_data (self ) -> dict :
9491 """Query the result of the GraphQL Query defined in self.query and return the result"""
9592
96- if not variables :
97- variables = {}
93+ return await self .client .query_gql_query (name = self .query , branch_name = self .branch_name )
9894
99- # Try getting data from stored graphql query endpoint
100- try :
101- return await self .client .query_gql_query (name = self .query , branch_name = self .branch_name , variables = variables )
102- # If we run into an error, the stored graphql query may not exist. Try to query the GraphQL API directly instead.
103- except httpx .HTTPStatusError :
104- if not self .repository_config :
105- raise
106- query_str = self .repository_config .get_query (name = self .query ).load_query ()
107- return await self .client .execute_graphql (query = query_str , variables = variables , branch_name = self .branch_name )
108-
109- async def run (self , data : Optional [dict ] = None , variables : Optional [dict ] = None ) -> Any :
95+ async def run (self , data : Optional [dict ] = None ) -> Any :
11096 """Execute the transformation after collecting the data from the GraphQL query.
11197
11298 The result of the check is determined based on the presence or not of ERROR log messages.
11399
114100 Args:
115101 data: The data on which to run the transform. Data will be queried from the API if not provided
116- variables: Variables to use in the graphQL query to filter returned data
117102
118103 Returns: Transformed data
119104 """
120105
121- if not variables :
122- variables = {}
123-
124106 if not data :
125- data = await self .collect_data (variables = variables )
107+ data = await self .collect_data ()
126108
127109 unpacked = data .get ("data" ) or data
128110
@@ -136,7 +118,6 @@ def get_transform_class_instance(
136118 transform_config : InfrahubPythonTransformConfig ,
137119 search_path : Optional [Path ] = None ,
138120 branch : str = "" ,
139- repository_config : Optional [InfrahubRepositoryConfig ] = None ,
140121 client : Optional [InfrahubClient ] = None ,
141122) -> InfrahubTransform :
142123 """Gets an instance of the InfrahubTransform class.
@@ -146,9 +127,6 @@ def get_transform_class_instance(
146127 search_path: The path in which to search for a python file containing the transform. The current directory is
147128 assumed if not speicifed.
148129 branch: Infrahub branch which will be targeted in graphql query used to acquire data for transformation.
149- repository_config: Repository config object. This is dpendency injected into the InfrahubTransform instance
150- providing it with the ability to interact with other data in the repository where the transform is defined
151- (e.g. a graphql query file).
152130 client: InfrahubClient used to interact with infrahub API.
153131 """
154132 if transform_config .file_path .is_absolute () or search_path is None :
@@ -165,7 +143,7 @@ def get_transform_class_instance(
165143 transform_class = getattr (module , transform_config .class_name )
166144
167145 # Create an instance of the class
168- transform_instance = transform_class (branch = branch , client = client , repository_config = repository_config )
146+ transform_instance = transform_class (branch = branch , client = client )
169147
170148 except (FileNotFoundError , AttributeError ) as exc :
171149 raise InfrahubTransformNotFoundError (name = transform_config .name ) from exc
0 commit comments