From c3e33aa6c53685d9ed17c99ff006c4e6caffbf26 Mon Sep 17 00:00:00 2001 From: Gal Nakash Date: Mon, 26 Jun 2023 16:23:46 +0300 Subject: [PATCH] Packs/Reco: fix validate_api_key Signed-off-by: Gal Nakash --- Packs/Reco/Integrations/Reco/Reco.py | 25 +++++++++++++---------- Packs/Reco/Integrations/Reco/Reco_test.py | 6 +++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Packs/Reco/Integrations/Reco/Reco.py b/Packs/Reco/Integrations/Reco/Reco.py index 14e26c830785..81ca09c6ff21 100644 --- a/Packs/Reco/Integrations/Reco/Reco.py +++ b/Packs/Reco/Integrations/Reco/Reco.py @@ -696,11 +696,11 @@ def validate_api_key(self) -> str: invalid_token_string = "Invalid token" try: response = self._http_request( - method="POST", - url_suffix="/incident-tables/tables", + method="GET", + url_suffix="/data-sources", timeout=RECO_API_TIMEOUT_IN_SECONDS, ) - if response.get("listTablesResponse") is None: + if response.get("dataSources") is None: demisto.info(f"got bad response, {response}") else: demisto.info(f"got good response, {response}") @@ -1066,18 +1066,21 @@ def fetch_incidents( ) -> Tuple[Dict[str, Any], List[Dict[str, Any]]]: demisto.info(f"fetch-incidents called {max_fetch=}") next_run = {} + incidents = [] last_run_time = last_run.get("lastRun", None) if last_run_time is not None: after = dateutil.parser.parse(last_run_time) - incidents_raw = reco_client.get_incidents( - risk_level=risk_level, - source=source, - before=before, - after=after, - limit=max_fetch, - ) - incidents = parse_incidents_objects(reco_client, incidents_raw) + try: + incidents_raw = reco_client.get_incidents(risk_level=risk_level, + source=source, + before=before, + after=after, + limit=max_fetch) + incidents = parse_incidents_objects(reco_client, incidents_raw) + except Exception as e: + demisto.info(f"Error fetching incidents: {e}") + alerts = get_alerts(reco_client, risk_level, source, before, after, max_fetch) alerts_as_incidents = parse_alerts_to_incidents(alerts) incidents.extend(alerts_as_incidents) diff --git a/Packs/Reco/Integrations/Reco/Reco_test.py b/Packs/Reco/Integrations/Reco/Reco_test.py index 35edcbe1c079..3020d3cf5776 100644 --- a/Packs/Reco/Integrations/Reco/Reco_test.py +++ b/Packs/Reco/Integrations/Reco/Reco_test.py @@ -345,9 +345,9 @@ def get_mock_assets() -> List[Dict[str, Any]]: def test_test_module_success(requests_mock, reco_client: RecoClient) -> None: - mock_response = {"listTablesResponse": {"tablesMetadata": [{"name": "table1"}]}} - requests_mock.post( - f"{DUMMY_RECO_API_DNS_NAME}/incident-tables/tables", json=mock_response + mock_response = {"dataSources": {"tablesMetadata": [{"name": "table1"}]}} + requests_mock.get( + f"{DUMMY_RECO_API_DNS_NAME}/data-sources", json=mock_response ) res = reco_client.validate_api_key()