@@ -145,142 +145,3 @@ def query_rule(
145
145
146
146
def ad_hoc_query (self , query : str , input_data : dict = None ) -> dict :
147
147
raise NotImplementedError
148
-
149
-
150
- # class OpaClient(BaseOpaClient):
151
- # """
152
- # Synchronous OpaClient implementation using requests.
153
- # """
154
-
155
- # def __init__(self, *args, **kwargs):
156
- # super().__init__(*args, **kwargs)
157
-
158
- # self._init_session()
159
-
160
- # def _init_session(self):
161
- # self._session = requests.Session()
162
- # self._session.headers.update(self.headers)
163
-
164
- # if self.ssl:
165
- # self._session.verify = self.cert if self.cert else True
166
-
167
- # # Optionally, configure retries and other session parameters
168
-
169
- # def close_connection(self):
170
- # if self._session:
171
- # self._session.close()
172
- # self._session = None
173
-
174
- # def check_connection(self) -> str:
175
- # url = self._build_url('policies/')
176
- # try:
177
- # response = self._session.get(url, timeout=self.timeout)
178
- # response.raise_for_status()
179
- # return "Yes, I'm here :)"
180
- # except requests.exceptions.RequestException as e:
181
- # raise ConnectionsError('Service unreachable', 'Check config and try again') from e
182
-
183
- # # Implement other synchronous methods similarly
184
- # # For example:
185
- # def get_policies_list(self) -> list:
186
- # url = self._build_url('policies/')
187
- # response = self._session.get(url, timeout=self.timeout)
188
- # response.raise_for_status()
189
- # policies = response.json().get('result', [])
190
- # return [policy.get('id') for policy in policies if policy.get('id')]
191
-
192
- # # ... Rest of synchronous methods ...
193
-
194
-
195
- # class AsyncOpaClient(BaseOpaClient):
196
- # """
197
- # Asynchronous OpaClient implementation using aiohttp.
198
- # """
199
-
200
- # async def __aenter__(self):
201
- # await self._init_session()
202
- # return self
203
-
204
- # async def __aexit__(self, exc_type, exc_value, traceback):
205
- # await self.close_connection()
206
-
207
- # async def _init_session(self):
208
- # ssl_context = None
209
-
210
- # if self.ssl:
211
- # ssl_context = ssl.create_default_context()
212
- # if self.cert:
213
- # if isinstance(self.cert, tuple):
214
- # ssl_context.load_cert_chain(*self.cert)
215
- # else:
216
- # ssl_context.load_cert_chain(self.cert)
217
- # else:
218
- # ssl_context.load_default_certs()
219
-
220
- # connector = aiohttp.TCPConnector(ssl=ssl_context)
221
-
222
- # self._session = aiohttp.ClientSession(
223
- # headers=self.headers,
224
- # connector=connector,
225
- # timeout=aiohttp.ClientTimeout(total=self.timeout),
226
- # )
227
-
228
- # async def close_connection(self):
229
- # if self._session and not self._session.closed:
230
- # await self._session.close()
231
- # self._session = None
232
-
233
- # async def check_connection(self) -> str:
234
- # url = self._build_url('policies/')
235
- # try:
236
- # async with self._session.get(url) as response:
237
- # if response.status == 200:
238
- # return "Yes, I'm here :)"
239
- # else:
240
- # raise ConnectionsError('Service unreachable', 'Check config and try again')
241
- # except Exception as e:
242
- # raise ConnectionsError('Service unreachable', 'Check config and try again') from e
243
-
244
- # # Implement other asynchronous methods similarly
245
- # # For example:
246
- # async def get_policies_list(self) -> list:
247
- # url = self._build_url('policies/')
248
- # async with self._session.get(url) as response:
249
- # response.raise_for_status()
250
- # policies = await response.json()
251
- # result = policies.get('result', [])
252
- # return [policy.get('id') for policy in result if policy.get('id')]
253
-
254
- # # ... Rest of asynchronous methods ...
255
-
256
-
257
- # # Example usage:
258
-
259
- # # Synchronous client
260
- # def sync_example():
261
- # client = OpaClient(host='localhost', port=8181)
262
- # try:
263
- # result = client.check_connection()
264
- # print(result)
265
- # policies = client.get_policies_list()
266
- # print("Policies:", policies)
267
- # finally:
268
- # client.close_connection()
269
-
270
-
271
- # # Asynchronous client
272
- # async def async_example():
273
- # async with AsyncOpaClient(host='localhost', port=8181) as client:
274
- # result = await client.check_connection()
275
- # print(result)
276
- # policies = await client.get_policies_list()
277
- # print("Policies:", policies)
278
-
279
-
280
- # if __name__ == '__main__':
281
- # # Run synchronous example
282
- # sync_example()
283
-
284
- # # Run asynchronous example
285
- # import asyncio
286
- # asyncio.run(async_example())
0 commit comments