Skip to content

Commit

Permalink
remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Turall committed Oct 21, 2024
1 parent cbb688d commit 10d5e42
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 222 deletions.
139 changes: 0 additions & 139 deletions opa_client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,142 +145,3 @@ def query_rule(

def ad_hoc_query(self, query: str, input_data: dict = None) -> dict:
raise NotImplementedError


# class OpaClient(BaseOpaClient):
# """
# Synchronous OpaClient implementation using requests.
# """

# def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)

# self._init_session()

# def _init_session(self):
# self._session = requests.Session()
# self._session.headers.update(self.headers)

# if self.ssl:
# self._session.verify = self.cert if self.cert else True

# # Optionally, configure retries and other session parameters

# def close_connection(self):
# if self._session:
# self._session.close()
# self._session = None

# def check_connection(self) -> str:
# url = self._build_url('policies/')
# try:
# response = self._session.get(url, timeout=self.timeout)
# response.raise_for_status()
# return "Yes, I'm here :)"
# except requests.exceptions.RequestException as e:
# raise ConnectionsError('Service unreachable', 'Check config and try again') from e

# # Implement other synchronous methods similarly
# # For example:
# def get_policies_list(self) -> list:
# url = self._build_url('policies/')
# response = self._session.get(url, timeout=self.timeout)
# response.raise_for_status()
# policies = response.json().get('result', [])
# return [policy.get('id') for policy in policies if policy.get('id')]

# # ... Rest of synchronous methods ...


# class AsyncOpaClient(BaseOpaClient):
# """
# Asynchronous OpaClient implementation using aiohttp.
# """

# async def __aenter__(self):
# await self._init_session()
# return self

# async def __aexit__(self, exc_type, exc_value, traceback):
# await self.close_connection()

# async def _init_session(self):
# ssl_context = None

# if self.ssl:
# ssl_context = ssl.create_default_context()
# if self.cert:
# if isinstance(self.cert, tuple):
# ssl_context.load_cert_chain(*self.cert)
# else:
# ssl_context.load_cert_chain(self.cert)
# else:
# ssl_context.load_default_certs()

# connector = aiohttp.TCPConnector(ssl=ssl_context)

# self._session = aiohttp.ClientSession(
# headers=self.headers,
# connector=connector,
# timeout=aiohttp.ClientTimeout(total=self.timeout),
# )

# async def close_connection(self):
# if self._session and not self._session.closed:
# await self._session.close()
# self._session = None

# async def check_connection(self) -> str:
# url = self._build_url('policies/')
# try:
# async with self._session.get(url) as response:
# if response.status == 200:
# return "Yes, I'm here :)"
# else:
# raise ConnectionsError('Service unreachable', 'Check config and try again')
# except Exception as e:
# raise ConnectionsError('Service unreachable', 'Check config and try again') from e

# # Implement other asynchronous methods similarly
# # For example:
# async def get_policies_list(self) -> list:
# url = self._build_url('policies/')
# async with self._session.get(url) as response:
# response.raise_for_status()
# policies = await response.json()
# result = policies.get('result', [])
# return [policy.get('id') for policy in result if policy.get('id')]

# # ... Rest of asynchronous methods ...


# # Example usage:

# # Synchronous client
# def sync_example():
# client = OpaClient(host='localhost', port=8181)
# try:
# result = client.check_connection()
# print(result)
# policies = client.get_policies_list()
# print("Policies:", policies)
# finally:
# client.close_connection()


# # Asynchronous client
# async def async_example():
# async with AsyncOpaClient(host='localhost', port=8181) as client:
# result = await client.check_connection()
# print(result)
# policies = await client.get_policies_list()
# print("Policies:", policies)


# if __name__ == '__main__':
# # Run synchronous example
# sync_example()

# # Run asynchronous example
# import asyncio
# asyncio.run(async_example())
83 changes: 0 additions & 83 deletions opa_client/opa.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,89 +456,6 @@ def ad_hoc_query(self, query: str, input_data: dict = None) -> dict:
response.raise_for_status()
return response.json()

# # Property methods for read-only access to certain attributes
# @property
# def host(self) -> str:
# return self._host

# @host.setter
# def host(self, value: str):
# self._host = value

# @property
# def port(self) -> int:
# return self._port

# @port.setter
# def port(self, value: int):
# if not isinstance(value, int):
# raise TypeError('Port must be an integer')
# self._port = value

# @property
# def version(self) -> str:
# return self._version

# @version.setter
# def version(self, value: str):
# self._version = value

# @property
# def schema(self) -> str:
# return self._schema

# @schema.setter
# def schema(self, value: str):
# self._schema = value

# @property
# def root_url(self) -> str:
# return self._root_url

# @root_url.setter
# def root_url(self, value: str):
# self._root_url = value

# @property
# def ssl(self) -> bool:
# return self._ssl

# @ssl.setter
# def ssl(self, value: bool):
# self._ssl = value

# @property
# def cert(self) -> Optional[str]:
# return self._cert

# @cert.setter
# def cert(self, value: Optional[str]):
# self._cert = value

# @property
# def headers(self) -> dict:
# return self._headers

# @headers.setter
# def headers(self, value: dict):
# self._headers = value

# @property
# def retries(self) -> int:
# return self._retries

# @retries.setter
# def retries(self, value: int):
# self._retries = value

# @property
# def timeout(self) -> float:
# return self._timeout

# @timeout.setter
# def timeout(self, value: float):
# self._timeout = value


# Example usage:
if __name__ == "__main__":
Expand Down

0 comments on commit 10d5e42

Please sign in to comment.