From 8b6cbd5e795242c3e1cea1521db14fae08bddba3 Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Mon, 19 Feb 2024 18:54:17 -0800 Subject: [PATCH 01/11] requests: update to async --- .../integrations/requestsWrapper/client.py | 105 +++++++++++------- 1 file changed, 63 insertions(+), 42 deletions(-) diff --git a/automon/integrations/requestsWrapper/client.py b/automon/integrations/requestsWrapper/client.py index bf6c82c4..8333cfb1 100644 --- a/automon/integrations/requestsWrapper/client.py +++ b/automon/integrations/requestsWrapper/client.py @@ -33,13 +33,13 @@ def __len__(self): if self.content: len(self.content) - def _log_result(self): - if self.results.status_code == 200: + async def _log_result(self): + if self.status_code == 200: msg = [ self.results.request.method, self.results.url, f'{round(len(self.results.content) / 1024, 2)} KB', - self.results.status_code, + self.status_code, ] msg = ' '.join(msg) return logger.debug(msg) @@ -48,14 +48,14 @@ def _log_result(self): self.results.request.method, self.results.url, f'{round(len(self.results.content) / 1024, 2)} KB', - self.results.status_code, + self.status_code, self.results.content ] msg = ' '.join(msg) return logger.error(msg) - def _params(self, url, data, headers): + async def _params(self, url, data, headers): if url is None: url = self.url @@ -72,7 +72,7 @@ def _params(self, url, data, headers): @property def content(self): - if self.results: + if 'content' in dir(self.results): return self.results.content @property @@ -80,30 +80,34 @@ def text(self): if self.results: return self.results.text - def delete(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def delete(self, + url: str = None, + data: dict = None, + headers: dict = None, **kwargs) -> bool: """requests.delete""" - url, data, headers = self._params(url, data, headers) + url, data, headers = await self._params(url, data, headers) try: self.results = requests.delete(url=url, data=data, headers=headers, **kwargs) - self._log_result() - return True + await self._log_result() + + if self.status_code == 200: + return True + + return False except Exception as e: self.errors = e logger.error(f'delete failed. {e}') return False - def get(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def get(self, + url: str = None, + data: dict = None, + headers: dict = None, **kwargs) -> bool: """requests.get""" - url, data, headers = self._params(url, data, headers) + url, data, headers = await self._params(url, data, headers) try: self.results = requests.get(url=url, data=data, headers=headers, **kwargs) @@ -111,22 +115,25 @@ def get(self, logger.debug( f'{self.results.url} ' f'{round(len(self.results.content) / 1024, 2)} KB ' - f'{self.results.status_code}' + f'{self.status_code}' ) - return True + if self.status_code == 200: + return True + + return False except Exception as e: self.errors = e logger.error(f'{e}') return False - def patch(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def patch(self, + url: str = None, + data: dict = None, + headers: dict = None, **kwargs) -> bool: """requests.patch""" - url, data, headers = self._params(url, data, headers) + url, data, headers = await self._params(url, data, headers) try: self.results = requests.patch(url=url, data=data, headers=headers, **kwargs) @@ -134,22 +141,25 @@ def patch(self, logger.debug( f'{self.results.url} ' f'{round(len(self.results.content) / 1024, 2)} KB ' - f'{self.results.status_code}' + f'{self.status_code}' ) - return True + if self.status_code == 200: + return True + + return False except Exception as e: self.errors = e logger.error(f'patch failed. {e}') return False - def post(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def post(self, + url: str = None, + data: dict = None, + headers: dict = None, **kwargs) -> bool: """requests.post""" - url, data, headers = self._params(url, data, headers) + url, data, headers = await self._params(url, data, headers) try: self.results = requests.post(url=url, data=data, headers=headers, **kwargs) @@ -157,22 +167,25 @@ def post(self, logger.debug( f'{self.results.url} ' f'{round(len(self.results.content) / 1024, 2)} KB ' - f'{self.results.status_code}' + f'{self.status_code}' ) - return True + if self.status_code == 200: + return True + + return False except Exception as e: self.errors = e logger.error(f'post failed. {e}') return False - def put(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def put(self, + url: str = None, + data: dict = None, + headers: dict = None, **kwargs) -> bool: """requests.put""" - url, data, headers = self._params(url, data, headers) + url, data, headers = await self._params(url, data, headers) try: self.results = requests.put(url=url, data=data, headers=headers, **kwargs) @@ -180,16 +193,24 @@ def put(self, logger.debug( f'{self.results.url} ' f'{round(len(self.results.content) / 1024, 2)} KB ' - f'{self.results.status_code}' + f'{self.status_code}' ) - return True + if self.status_code == 200: + return True + + return False except Exception as e: self.errors = e logger.error(f'put failed. {e}') return False - def to_dict(self): + @property + def status_code(self): + if 'status_code' in dir(self.results): + return self.results.status_code + + async def to_dict(self): if self.results is not None: return json.loads(self.results.content) From b392bff9945df1989ec1f50338e776f2a70b6dcd Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Mon, 19 Feb 2024 20:14:31 -0800 Subject: [PATCH 02/11] requests: add reason method --- automon/integrations/requestsWrapper/client.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/automon/integrations/requestsWrapper/client.py b/automon/integrations/requestsWrapper/client.py index 8333cfb1..aa504724 100644 --- a/automon/integrations/requestsWrapper/client.py +++ b/automon/integrations/requestsWrapper/client.py @@ -75,11 +75,6 @@ def content(self): if 'content' in dir(self.results): return self.results.content - @property - def text(self): - if self.results: - return self.results.text - async def delete(self, url: str = None, data: dict = None, @@ -205,11 +200,21 @@ async def put(self, logger.error(f'put failed. {e}') return False + @property + def reason(self): + if 'reason' in dir(self.results): + return self.results.reason + @property def status_code(self): if 'status_code' in dir(self.results): return self.results.status_code + @property + def text(self): + if self.results: + return self.results.text + async def to_dict(self): if self.results is not None: return json.loads(self.results.content) From e8dde9cbb81f424e308c4804c9f9da6214850546 Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Tue, 20 Feb 2024 16:01:38 -0800 Subject: [PATCH 03/11] requests: add content prop, add to_json method --- .../integrations/requestsWrapper/client.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/automon/integrations/requestsWrapper/client.py b/automon/integrations/requestsWrapper/client.py index aa504724..92e0f811 100644 --- a/automon/integrations/requestsWrapper/client.py +++ b/automon/integrations/requestsWrapper/client.py @@ -38,7 +38,7 @@ async def _log_result(self): msg = [ self.results.request.method, self.results.url, - f'{round(len(self.results.content) / 1024, 2)} KB', + f'{round(len(self.content) / 1024, 2)} KB', self.status_code, ] msg = ' '.join(msg) @@ -47,9 +47,9 @@ async def _log_result(self): msg = [ self.results.request.method, self.results.url, - f'{round(len(self.results.content) / 1024, 2)} KB', + f'{round(len(self.content) / 1024, 2)} KB', self.status_code, - self.results.content + self.content ] msg = ' '.join(msg) @@ -109,7 +109,7 @@ async def get(self, logger.debug( f'{self.results.url} ' - f'{round(len(self.results.content) / 1024, 2)} KB ' + f'{round(len(self.content) / 1024, 2)} KB ' f'{self.status_code}' ) @@ -135,7 +135,7 @@ async def patch(self, logger.debug( f'{self.results.url} ' - f'{round(len(self.results.content) / 1024, 2)} KB ' + f'{round(len(self.content) / 1024, 2)} KB ' f'{self.status_code}' ) @@ -161,7 +161,7 @@ async def post(self, logger.debug( f'{self.results.url} ' - f'{round(len(self.results.content) / 1024, 2)} KB ' + f'{round(len(self.content) / 1024, 2)} KB ' f'{self.status_code}' ) @@ -187,7 +187,7 @@ async def put(self, logger.debug( f'{self.results.url} ' - f'{round(len(self.results.content) / 1024, 2)} KB ' + f'{round(len(self.content) / 1024, 2)} KB ' f'{self.status_code}' ) @@ -217,7 +217,11 @@ def text(self): async def to_dict(self): if self.results is not None: - return json.loads(self.results.content) + return json.loads(self.content) + + async def to_json(self): + if self.content: + return json.dumps(json.loads(self.content)) class Requests(RequestsClient): From 39824ccc80a3fdeb42f308c6da3d491dc0bd26e5 Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Wed, 21 Feb 2024 22:09:24 -0800 Subject: [PATCH 04/11] requests: minor support for request.Session --- automon/integrations/requestsWrapper/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/automon/integrations/requestsWrapper/client.py b/automon/integrations/requestsWrapper/client.py index 92e0f811..f18f4aff 100644 --- a/automon/integrations/requestsWrapper/client.py +++ b/automon/integrations/requestsWrapper/client.py @@ -21,6 +21,7 @@ def __init__(self, url: str = None, data: dict = None, headers: dict = None, self.headers = headers self.results = None self.requests = requests + self.session = self.requests.Session() if url: self.url = url From 3c2091c3783aaf7e6b85041fc8f79285ca6c344e Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Thu, 22 Feb 2024 04:45:44 -0800 Subject: [PATCH 05/11] requests: default to requests.Session --- .../integrations/requestsWrapper/client.py | 68 ++++++++++++------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/automon/integrations/requestsWrapper/client.py b/automon/integrations/requestsWrapper/client.py index f18f4aff..b4a8afde 100644 --- a/automon/integrations/requestsWrapper/client.py +++ b/automon/integrations/requestsWrapper/client.py @@ -76,16 +76,19 @@ def content(self): if 'content' in dir(self.results): return self.results.content - async def delete(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def delete( + self, + url: str = None, + data: dict = None, + headers: dict = None, + **kwargs + ) -> bool: """requests.delete""" url, data, headers = await self._params(url, data, headers) try: - self.results = requests.delete(url=url, data=data, headers=headers, **kwargs) + self.results = self.session.delete(url=url, data=data, headers=headers, **kwargs) await self._log_result() if self.status_code == 200: @@ -97,16 +100,19 @@ async def delete(self, logger.error(f'delete failed. {e}') return False - async def get(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def get( + self, + url: str = None, + data: dict = None, + headers: dict = None, + **kwargs + ) -> bool: """requests.get""" url, data, headers = await self._params(url, data, headers) try: - self.results = requests.get(url=url, data=data, headers=headers, **kwargs) + self.results = self.session.get(url=url, data=data, headers=headers, **kwargs) logger.debug( f'{self.results.url} ' @@ -123,16 +129,19 @@ async def get(self, logger.error(f'{e}') return False - async def patch(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def patch( + self, + url: str = None, + data: dict = None, + headers: dict = None, + **kwargs + ) -> bool: """requests.patch""" url, data, headers = await self._params(url, data, headers) try: - self.results = requests.patch(url=url, data=data, headers=headers, **kwargs) + self.results = self.session.patch(url=url, data=data, headers=headers, **kwargs) logger.debug( f'{self.results.url} ' @@ -149,16 +158,19 @@ async def patch(self, logger.error(f'patch failed. {e}') return False - async def post(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def post( + self, + url: str = None, + data: dict = None, + headers: dict = None, + **kwargs + ) -> bool: """requests.post""" url, data, headers = await self._params(url, data, headers) try: - self.results = requests.post(url=url, data=data, headers=headers, **kwargs) + self.results = self.session.post(url=url, data=data, headers=headers, **kwargs) logger.debug( f'{self.results.url} ' @@ -175,16 +187,19 @@ async def post(self, logger.error(f'post failed. {e}') return False - async def put(self, - url: str = None, - data: dict = None, - headers: dict = None, **kwargs) -> bool: + async def put( + self, + url: str = None, + data: dict = None, + headers: dict = None, + **kwargs + ) -> bool: """requests.put""" url, data, headers = await self._params(url, data, headers) try: - self.results = requests.put(url=url, data=data, headers=headers, **kwargs) + self.results = self.session.put(url=url, data=data, headers=headers, **kwargs) logger.debug( f'{self.results.url} ' @@ -224,6 +239,9 @@ async def to_json(self): if self.content: return json.dumps(json.loads(self.content)) + async def update_headers(self, headers: dict): + return self.session.headers.update(headers) + class Requests(RequestsClient): pass From 076a3240504f2910efd06c4fa048e58b8d010439 Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Sat, 24 Feb 2024 03:22:22 -0800 Subject: [PATCH 06/11] requests: rename property results to response --- .../integrations/requestsWrapper/client.py | 50 +++++++++---------- automon/integrations/splunk_soar/client.py | 22 ++++---- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/automon/integrations/requestsWrapper/client.py b/automon/integrations/requestsWrapper/client.py index b4a8afde..fd3cf769 100644 --- a/automon/integrations/requestsWrapper/client.py +++ b/automon/integrations/requestsWrapper/client.py @@ -19,14 +19,10 @@ def __init__(self, url: str = None, data: dict = None, headers: dict = None, self.data = data self.errors = None self.headers = headers - self.results = None + self.response = None self.requests = requests self.session = self.requests.Session() - if url: - self.url = url - self.get(url=self.url, data=self.data, headers=self.headers) - def __repr__(self): return f'{self.__dict__}' @@ -37,8 +33,8 @@ def __len__(self): async def _log_result(self): if self.status_code == 200: msg = [ - self.results.request.method, - self.results.url, + self.response.request.method, + self.response.url, f'{round(len(self.content) / 1024, 2)} KB', self.status_code, ] @@ -46,8 +42,8 @@ async def _log_result(self): return logger.debug(msg) msg = [ - self.results.request.method, - self.results.url, + self.response.request.method, + self.response.url, f'{round(len(self.content) / 1024, 2)} KB', self.status_code, self.content @@ -73,8 +69,8 @@ async def _params(self, url, data, headers): @property def content(self): - if 'content' in dir(self.results): - return self.results.content + if 'content' in dir(self.response): + return self.response.content async def delete( self, @@ -88,7 +84,7 @@ async def delete( url, data, headers = await self._params(url, data, headers) try: - self.results = self.session.delete(url=url, data=data, headers=headers, **kwargs) + self.response = self.session.delete(url=url, data=data, headers=headers, **kwargs) await self._log_result() if self.status_code == 200: @@ -112,10 +108,10 @@ async def get( url, data, headers = await self._params(url, data, headers) try: - self.results = self.session.get(url=url, data=data, headers=headers, **kwargs) + self.response = self.session.get(url=url, data=data, headers=headers, **kwargs) logger.debug( - f'{self.results.url} ' + f'{self.response.url} ' f'{round(len(self.content) / 1024, 2)} KB ' f'{self.status_code}' ) @@ -141,10 +137,10 @@ async def patch( url, data, headers = await self._params(url, data, headers) try: - self.results = self.session.patch(url=url, data=data, headers=headers, **kwargs) + self.response = self.session.patch(url=url, data=data, headers=headers, **kwargs) logger.debug( - f'{self.results.url} ' + f'{self.response.url} ' f'{round(len(self.content) / 1024, 2)} KB ' f'{self.status_code}' ) @@ -170,10 +166,10 @@ async def post( url, data, headers = await self._params(url, data, headers) try: - self.results = self.session.post(url=url, data=data, headers=headers, **kwargs) + self.response = self.session.post(url=url, data=data, headers=headers, **kwargs) logger.debug( - f'{self.results.url} ' + f'{self.response.url} ' f'{round(len(self.content) / 1024, 2)} KB ' f'{self.status_code}' ) @@ -199,10 +195,10 @@ async def put( url, data, headers = await self._params(url, data, headers) try: - self.results = self.session.put(url=url, data=data, headers=headers, **kwargs) + self.response = self.session.put(url=url, data=data, headers=headers, **kwargs) logger.debug( - f'{self.results.url} ' + f'{self.response.url} ' f'{round(len(self.content) / 1024, 2)} KB ' f'{self.status_code}' ) @@ -218,21 +214,21 @@ async def put( @property def reason(self): - if 'reason' in dir(self.results): - return self.results.reason + if 'reason' in dir(self.response): + return self.response.reason @property def status_code(self): - if 'status_code' in dir(self.results): - return self.results.status_code + if 'status_code' in dir(self.response): + return self.response.status_code @property def text(self): - if self.results: - return self.results.text + if self.response: + return self.response.text async def to_dict(self): - if self.results is not None: + if self.response is not None: return json.loads(self.content) async def to_json(self): diff --git a/automon/integrations/splunk_soar/client.py b/automon/integrations/splunk_soar/client.py index 1e0195d0..ec755b64 100644 --- a/automon/integrations/splunk_soar/client.py +++ b/automon/integrations/splunk_soar/client.py @@ -56,8 +56,8 @@ def __repr__(self) -> str: def _content(self) -> bytes: """get result""" - if self.client.results: - return self.client.results.content + if self.client.response: + return self.client.response.content return b'' def _content_dict(self) -> dict: @@ -95,7 +95,7 @@ def close_container(self, container_id: int, **kwargs) -> Optional[CloseContaine """Set container status to closed""" data = dict(status='closed') if self._post(Urls.container(identifier=container_id, **kwargs), data=json.dumps(data)): - if self.client.results.status_code == 200: + if self.client.response.status_code == 200: response = CloseContainerResponse(self._content_dict()) logger.info(f'container closed: {response}') return response @@ -112,7 +112,7 @@ def cancel_playbook_run( data = json.dumps(data) if self._post(Urls.playbook_run(identifier=playbook_run_id, **kwargs), data=data): - if self.client.results.status_code == 200: + if self.client.response.status_code == 200: response = CancelPlaybookResponse(self._content_dict()) logger.info(f'cancel playbook run: {response}') return response @@ -163,7 +163,7 @@ def create_artifact( ) if self._post(Urls.artifact(*args, **kwargs), data=artifact.to_json()): - if self.client.results.status_code == 200: + if self.client.response.status_code == 200: id = self.client.to_dict()['id'] logger.info(f'artifact created. {artifact} {self.client.to_dict()}') return self.get_artifact(artifact_id=id) @@ -237,7 +237,7 @@ def create_container( ) if self._post(Urls.container(*args, **kwargs), data=container.to_json()): - if self.client.results.status_code == 200: + if self.client.response.status_code == 200: response = CreateContainerResponse(self.client.to_dict()) logger.info(f'container created. {container} {response}') return response @@ -309,7 +309,7 @@ def delete_container(self, container_id, *args, **kwargs): assert isinstance(container_id, int) if self._delete(Urls.container(identifier=container_id, *args, **kwargs)): - if self.client.results.status_code == 200: + if self.client.response.status_code == 200: logger.info(f'container deleted: {container_id}') return True logger.error(f'delete container: {container_id}. {self.client.to_dict()}') @@ -321,7 +321,7 @@ def is_connected(self) -> bool: if self._get(Urls.container(page_size=1)): logger.info(f'client connected ' f'{self.config.host} ' - f'[{self.client.results.status_code}] ') + f'[{self.client.response.status_code}] ') return True else: @@ -426,7 +426,7 @@ def get_playbook_run(self, playbook_run_id: str, **kwargs) -> Optional[PlaybookR def get_vault(self, vault_id: int, **kwargs) -> Optional[Vault]: """Get vault object""" if self._get(Urls.vault(identifier=vault_id, **kwargs)): - if self.client.results.status_code == 200: + if self.client.response.status_code == 200: response = Vault(self._content_dict()) logger.info(msg=f'get vault: {response}') return response @@ -730,7 +730,7 @@ def update_playbook( ) data = json.dumps(data) if self._post(Urls.playbook(identifier=playbook_id, **kwargs), data=data): - if self.client.results.status_code == 200: + if self.client.response.status_code == 200: response = UpdatePlaybookResponse(self._content_dict()) logger.info(f'update playbook: {data}') return response @@ -754,7 +754,7 @@ def run_playbook( ) data = json.dumps(data) if self._post(Urls.playbook_run(**kwargs), data=data): - if self.client.results.status_code == 200: + if self.client.response.status_code == 200: response = RunPlaybookResponse(self._content_dict()) logger.info(f'run playbook: {data}') return response From 0ddff37d3d95b4b4e2f8278bfb35f806d3cdec37 Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Wed, 13 Mar 2024 23:11:25 -0700 Subject: [PATCH 07/11] requests: fix to_dict, fix to_json --- automon/integrations/requestsWrapper/client.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/automon/integrations/requestsWrapper/client.py b/automon/integrations/requestsWrapper/client.py index fd3cf769..04ba4c9f 100644 --- a/automon/integrations/requestsWrapper/client.py +++ b/automon/integrations/requestsWrapper/client.py @@ -229,11 +229,17 @@ def text(self): async def to_dict(self): if self.response is not None: - return json.loads(self.content) + try: + return json.loads(self.content) + except Exception as error: + logger.error(error) async def to_json(self): if self.content: - return json.dumps(json.loads(self.content)) + try: + return json.dumps(json.loads(self.content)) + except Exception as error: + logger.error(error) async def update_headers(self, headers: dict): return self.session.headers.update(headers) From 7ddbd1d7aec25e6866e0e8e52c67b52f45654aeb Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Thu, 14 Mar 2024 17:35:16 -0700 Subject: [PATCH 08/11] requests: add content_to_dict --- automon/integrations/requestsWrapper/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/automon/integrations/requestsWrapper/client.py b/automon/integrations/requestsWrapper/client.py index 04ba4c9f..b77aa50d 100644 --- a/automon/integrations/requestsWrapper/client.py +++ b/automon/integrations/requestsWrapper/client.py @@ -72,6 +72,9 @@ def content(self): if 'content' in dir(self.response): return self.response.content + async def content_to_dict(self): + return await self.to_dict() + async def delete( self, url: str = None, From 2025dc682e02ae7085ea7c36d9ca103ef8d77d14 Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Mon, 18 Mar 2024 16:57:58 -0700 Subject: [PATCH 09/11] requests: fix config --- automon/integrations/requestsWrapper/config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/automon/integrations/requestsWrapper/config.py b/automon/integrations/requestsWrapper/config.py index 2b7060b0..55d142cc 100644 --- a/automon/integrations/requestsWrapper/config.py +++ b/automon/integrations/requestsWrapper/config.py @@ -11,8 +11,9 @@ class RequestsConfig(object): def __init__(self): pass - def is_ready(self): + def __repr__(self): return f'{NotImplemented}' - def __repr__(self): + @property + def is_ready(self): return f'{NotImplemented}' From b122b56c1527e162f2391de8ca0fc43d72f3c7a1 Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Mon, 18 Mar 2024 16:58:05 -0700 Subject: [PATCH 10/11] requests: fix rest to async --- automon/integrations/requestsWrapper/rest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/automon/integrations/requestsWrapper/rest.py b/automon/integrations/requestsWrapper/rest.py index 3221e794..ba3736a7 100644 --- a/automon/integrations/requestsWrapper/rest.py +++ b/automon/integrations/requestsWrapper/rest.py @@ -20,17 +20,17 @@ def isConnected(self): return True return False - def get(self, url: str, data: str = None, headers: dict = None) -> bool: - return self.requests.get(url=url, data=data, headers=headers) + async def get(self, url: str, data: str = None, headers: dict = None) -> bool: + return await self.requests.get(url=url, data=data, headers=headers) - def post(self, url: str, data: str = None, headers: dict = None) -> bool: - return self.requests.post(url=url, data=data, headers=headers) + async def post(self, url: str, data: str = None, headers: dict = None) -> bool: + return await self.requests.post(url=url, data=data, headers=headers) - def delete(self, url: str, data: str = None, headers: dict = None) -> bool: - return self.requests.delete(url=url, data=data, headers=headers) + async def delete(self, url: str, data: str = None, headers: dict = None) -> bool: + return await self.requests.delete(url=url, data=data, headers=headers) - def patch(self, url: str, data: str = None, headers: dict = None) -> bool: - return self.requests.patch(url=url, data=data, headers=headers) + async def patch(self, url: str, data: str = None, headers: dict = None) -> bool: + return await self.requests.patch(url=url, data=data, headers=headers) def __repr__(self): return f'{self.__dict__}' From 2b3cd647e0350c478fe4945ee4de1a885822828b Mon Sep 17 00:00:00 2001 From: laerfulaolun Date: Mon, 18 Mar 2024 16:58:08 -0700 Subject: [PATCH 11/11] requests: fix tests for async --- .../integrations/requestsWrapper/tests/test_requests.py | 7 ++++--- automon/integrations/requestsWrapper/tests/test_rest.py | 7 ++++--- .../requestsWrapper/tests/test_rest_inherit.py | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/automon/integrations/requestsWrapper/tests/test_requests.py b/automon/integrations/requestsWrapper/tests/test_requests.py index 84ef5c5d..96b720c0 100644 --- a/automon/integrations/requestsWrapper/tests/test_requests.py +++ b/automon/integrations/requestsWrapper/tests/test_requests.py @@ -1,3 +1,4 @@ +import asyncio import unittest from automon.integrations.requestsWrapper import RequestsClient @@ -8,9 +9,9 @@ class Client(unittest.TestCase): def test_get(self): - r.get('https://1.1.1.1') - r.requests.get('https://1.1.1.1') - self.assertFalse(r.get('x://127.0.0.1')) + self.assertTrue(asyncio.run(r.get('https://1.1.1.1'))) + self.assertTrue(r.requests.get('https://1.1.1.1')) + self.assertFalse(asyncio.run(r.get('x://127.0.0.1'))) class Config(unittest.TestCase): diff --git a/automon/integrations/requestsWrapper/tests/test_rest.py b/automon/integrations/requestsWrapper/tests/test_rest.py index f2032a1b..cfd699b1 100644 --- a/automon/integrations/requestsWrapper/tests/test_rest.py +++ b/automon/integrations/requestsWrapper/tests/test_rest.py @@ -1,3 +1,4 @@ +import asyncio import unittest from automon.integrations.requestsWrapper.rest import BaseRestClient @@ -7,9 +8,9 @@ class Client(unittest.TestCase): def test_get(self): - r.get('https://1.1.1.1') - r.requests.get('https://1.1.1.1') - self.assertFalse(r.get('x://127.0.0.1')) + self.assertTrue(asyncio.run(r.get('https://1.1.1.1'))) + self.assertTrue(r.requests.get('https://1.1.1.1')) + self.assertFalse(asyncio.run(r.get('x://127.0.0.1'))) if __name__ == '__main__': diff --git a/automon/integrations/requestsWrapper/tests/test_rest_inherit.py b/automon/integrations/requestsWrapper/tests/test_rest_inherit.py index f8453fdd..a0b3478a 100644 --- a/automon/integrations/requestsWrapper/tests/test_rest_inherit.py +++ b/automon/integrations/requestsWrapper/tests/test_rest_inherit.py @@ -1,3 +1,4 @@ +import asyncio import unittest from automon.integrations.requestsWrapper.rest import BaseRestClient @@ -12,7 +13,7 @@ def __init__(self): class Client(unittest.TestCase): def test_get(self): - Test().get(url='https://1.1.1.1') + self.assertTrue(asyncio.run(Test().get(url='https://1.1.1.1'))) if __name__ == '__main__':