From bcf940e5ffd1fdb3c358fc155e694ebf116477ce Mon Sep 17 00:00:00 2001 From: Peter Annabel Date: Wed, 23 Jul 2025 15:57:49 -0500 Subject: [PATCH] fix get_next_page() to actually get next page --- .../responses/paginated_response.py | 2 +- src/pyhuntress/utils/helpers.py | 42 +++++++++---------- src/scratchpad.py | 20 +++++---- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/pyhuntress/responses/paginated_response.py b/src/pyhuntress/responses/paginated_response.py index 0f529c9..8331404 100644 --- a/src/pyhuntress/responses/paginated_response.py +++ b/src/pyhuntress/responses/paginated_response.py @@ -84,7 +84,6 @@ class PaginatedResponse(Generic[TModel]): self.endpointmodel = endpointmodel self.endpoint = endpoint self.limit = limit - print(self.endpoint) # The following for SIEM is in the response body, not the headers self.parsed_pagination_response = parse_response_body(json.loads(response.content.decode('utf-8')).get('pagination', {})) self.params = params @@ -125,6 +124,7 @@ class PaginatedResponse(Generic[TModel]): next_response.response, next_response.response_model, next_response.endpointmodel, + next_response.endpoint, self.next_page, next_response.limit, self.params, diff --git a/src/pyhuntress/utils/helpers.py b/src/pyhuntress/utils/helpers.py index 827a8e0..6da8e5b 100644 --- a/src/pyhuntress/utils/helpers.py +++ b/src/pyhuntress/utils/helpers.py @@ -69,34 +69,34 @@ def parse_response_body( result = {} - if first_page is not None: - result["first_page"] = first_page + if body.get("first_page") is not None: + result["first_page"] = body.get("first_page") - if prev_page is not None: - result["prev_page"] = prev_page - elif current_page is not None: - if current_page > 1: - result["prev_page"] = current_page - 1 + if body.get("prev_page") is not None: + result["prev_page"] = body.get("prev_page") + elif body.get("current_page") is not None: + if body.get("current_page") > 1: + result["prev_page"] = body.get("current_page") - 1 - if next_page is not None: - result["next_page"] = next_page + if body.get("next_page") is not None: + result["next_page"] = body.get("next_page") - if last_page is not None: - result["last_page"] = last_page - elif last_page is None and current_page is not None: - result["last_page"] = math.ceil(total_count/limit) + if body.get("last_page") is not None: + result["last_page"] = body.get("last_page") + elif body.get("last_page") is None and body.get("current_page") is not None: + result["last_page"] = math.ceil(body.get("total_count")/body.get("limit")) - if has_next_page: - result["has_next_page"] = has_next_page - elif current_page is not None and next_page is not None: + if body.get("has_next_page"): + result["has_next_page"] = body.get("has_next_page") + elif body.get("current_page") is not None and body.get("next_page") is not None: result["has_next_page"] = True - elif current_page is not None and next_page is None: + elif body.get("current_page") is not None and body.get("next_page") is None: result["has_next_page"] = False - if has_prev_page: - result["has_prev_page"] = has_prev_page - elif current_page is not None: - if current_page > 1: + if body.get("has_prev_page"): + result["has_prev_page"] = body.get("has_prev_page") + elif body.get("current_page") is not None: + if body.get("current_page") > 1: result["has_prev_page"] = True return result diff --git a/src/scratchpad.py b/src/scratchpad.py index 8fd793d..8bccbc6 100644 --- a/src/scratchpad.py +++ b/src/scratchpad.py @@ -39,17 +39,19 @@ siem_api_client = HuntressSIEMAPIClient( #signals = siem_api_client.signals.get() #print(signals) -paginated_billingreports = siem_api_client.billing_reports.paginated(1, 10) -print(paginated_billingreports.data) +#paginated_billingreports = siem_api_client.billing_reports.paginated(1, 10) +#print(paginated_billingreports.data) -paginated_incidentreports = siem_api_client.incident_reports.paginated(1, 10) -print(paginated_incidentreports.data) +#paginated_incidentreports = siem_api_client.incident_reports.paginated(1, 10) +#print(paginated_incidentreports.data) -paginated_organizations = siem_api_client.organizations.paginated(1, 10) +paginated_organizations = siem_api_client.organizations.paginated(1, 1) +print(paginated_organizations.data) +paginated_organizations.get_next_page() print(paginated_organizations.data) -paginated_reports = siem_api_client.reports.paginated(1, 10) -print(paginated_reports.data) +#paginated_reports = siem_api_client.reports.paginated(1, 10) +#print(paginated_reports.data) -paginated_signals = siem_api_client.signals.paginated(1, 10) -print(paginated_signals.data) +#paginated_signals = siem_api_client.signals.paginated(1, 10) +#print(paginated_signals.data)