Skip to content

Commit

Permalink
Packs/Reco: fix validate_api_key
Browse files Browse the repository at this point in the history
Signed-off-by: Gal Nakash <gal@recolabs.ai>
  • Loading branch information
GalNakash-RecoLabs committed Jun 27, 2023
1 parent 1e2e7a0 commit c3e33aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
25 changes: 14 additions & 11 deletions Packs/Reco/Integrations/Reco/Reco.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Packs/Reco/Integrations/Reco/Reco_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c3e33aa

Please sign in to comment.