diff --git a/src/pyhuntress/clients/huntress_client.py b/src/pyhuntress/clients/huntress_client.py index b3c9bba..d2fd7f5 100644 --- a/src/pyhuntress/clients/huntress_client.py +++ b/src/pyhuntress/clients/huntress_client.py @@ -37,16 +37,16 @@ class HuntressClient(ABC): def _get_url(self) -> str: pass - def _make_request( + def _make_request( # noqa: C901 self, method: RequestMethod, url: str, data: RequestData | None = None, - rawdata: RequestData | None = None, +# rawdata: RequestData | None = None, params: RequestParams | None = None, headers: dict[str, str] | None = None, retry_count: int = 0, - stream: bool = False, + stream: bool = False, # noqa: FBT001, FBT002 ) -> Response: """ Make an API request using the specified method, endpoint, data, and parameters. @@ -76,19 +76,19 @@ class HuntressClient(ABC): method, url, headers=headers, - json=data, - params=cast(dict[str, Any], params or {}), - stream=stream, - ) - elif rawdata: - response = requests.request( - method, - url, - headers=headers, - data=rawdata, + data=data, params=cast(dict[str, Any], params or {}), stream=stream, ) +# elif rawdata: +# response = requests.request( +# method, +# url, +# headers=headers, +# data=rawdata, +# params=cast(dict[str, Any], params or {}), +# stream=stream, +# ) else: response = requests.request( method, diff --git a/src/pyhuntress/clients/managedsat_client.py b/src/pyhuntress/clients/managedsat_client.py index 5dd2664..5519894 100644 --- a/src/pyhuntress/clients/managedsat_client.py +++ b/src/pyhuntress/clients/managedsat_client.py @@ -135,7 +135,7 @@ class HuntressSATAPIClient(HuntressClient): auth_response = self._make_request( "POST", token_url, - rawdata={ + data={ "grant_type": "client_credentials", "client_id": self.client_id, "client_secret": self.client_secret, diff --git a/src/pyhuntress/endpoints/managedsat/AccountsEndpoint.py b/src/pyhuntress/endpoints/managedsat/AccountsEndpoint.py index adf247b..e9fa61a 100644 --- a/src/pyhuntress/endpoints/managedsat/AccountsEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AccountsEndpoint.py @@ -52,10 +52,10 @@ class AccountsEndpoint( PaginatedResponse[SATData]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATAccounts, diff --git a/src/pyhuntress/endpoints/managedsat/AccountsIdAssignmentsEndpoint.py b/src/pyhuntress/endpoints/managedsat/AccountsIdAssignmentsEndpoint.py index 7bd3c87..83c86c8 100644 --- a/src/pyhuntress/endpoints/managedsat/AccountsIdAssignmentsEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AccountsIdAssignmentsEndpoint.py @@ -38,10 +38,10 @@ class AccountsIdAssignmentsEndpoint( PaginatedResponse[SATAssignments]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATAssignments, diff --git a/src/pyhuntress/endpoints/managedsat/AccountsIdUsersEndpoint.py b/src/pyhuntress/endpoints/managedsat/AccountsIdUsersEndpoint.py index 1279bad..bc5dc7f 100644 --- a/src/pyhuntress/endpoints/managedsat/AccountsIdUsersEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AccountsIdUsersEndpoint.py @@ -38,10 +38,10 @@ class AccountsIdUsersEndpoint( PaginatedResponse[SATUsers]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATUsers, diff --git a/src/pyhuntress/endpoints/managedsat/AssignmentsEndpoint.py b/src/pyhuntress/endpoints/managedsat/AssignmentsEndpoint.py index 3fb4aa5..9dd4a57 100644 --- a/src/pyhuntress/endpoints/managedsat/AssignmentsEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AssignmentsEndpoint.py @@ -52,10 +52,10 @@ class AssignmentsEndpoint( PaginatedResponse[SATData]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATAssignments, diff --git a/src/pyhuntress/endpoints/managedsat/AssignmentsIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/AssignmentsIdEndpoint.py index f6b9c84..015fdf8 100644 --- a/src/pyhuntress/endpoints/managedsat/AssignmentsIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AssignmentsIdEndpoint.py @@ -49,10 +49,10 @@ class AssignmentsIdEndpoint( PaginatedResponse[SATAssignments]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATAssignments, diff --git a/src/pyhuntress/endpoints/managedsat/AssignmentsIdLearnerActivityEndpoint.py b/src/pyhuntress/endpoints/managedsat/AssignmentsIdLearnerActivityEndpoint.py index 0b17709..e4571cb 100644 --- a/src/pyhuntress/endpoints/managedsat/AssignmentsIdLearnerActivityEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AssignmentsIdLearnerActivityEndpoint.py @@ -38,10 +38,10 @@ class AssignmentsIdLearnerActivityEndpoint( PaginatedResponse[SATLearnerActivities]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATLearnerActivities, diff --git a/src/pyhuntress/endpoints/managedsat/AssignmentsIdLearnersEndpoint.py b/src/pyhuntress/endpoints/managedsat/AssignmentsIdLearnersEndpoint.py index ccec1ae..6445c7e 100644 --- a/src/pyhuntress/endpoints/managedsat/AssignmentsIdLearnersEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/AssignmentsIdLearnersEndpoint.py @@ -38,10 +38,10 @@ class AssignmentsIdLearnersEndpoint( PaginatedResponse[SATLearners]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATLearners, diff --git a/src/pyhuntress/endpoints/managedsat/DepartmentsEndpoint.py b/src/pyhuntress/endpoints/managedsat/DepartmentsEndpoint.py index 0a73260..40ed1fc 100644 --- a/src/pyhuntress/endpoints/managedsat/DepartmentsEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/DepartmentsEndpoint.py @@ -52,10 +52,10 @@ class DepartmentsEndpoint( PaginatedResponse[SATDepartments]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATDepartments, diff --git a/src/pyhuntress/endpoints/managedsat/DepartmentsIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/DepartmentsIdEndpoint.py index 605d992..51f62d1 100644 --- a/src/pyhuntress/endpoints/managedsat/DepartmentsIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/DepartmentsIdEndpoint.py @@ -38,10 +38,10 @@ class DepartmentsIdEndpoint( PaginatedResponse[SATDepartments]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATDepartments, diff --git a/src/pyhuntress/endpoints/managedsat/EpisodesEndpoint.py b/src/pyhuntress/endpoints/managedsat/EpisodesEndpoint.py index 7e76cac..42a4ea0 100644 --- a/src/pyhuntress/endpoints/managedsat/EpisodesEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/EpisodesEndpoint.py @@ -52,10 +52,10 @@ class EpisodesEndpoint( PaginatedResponse[SATData]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATEpisodes, diff --git a/src/pyhuntress/endpoints/managedsat/EpisodesIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/EpisodesIdEndpoint.py index f35a6dd..a7e15c4 100644 --- a/src/pyhuntress/endpoints/managedsat/EpisodesIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/EpisodesIdEndpoint.py @@ -38,10 +38,10 @@ class EpisodesIdEndpoint( PaginatedResponse[SATEpisodes]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATEpisodes, diff --git a/src/pyhuntress/endpoints/managedsat/GroupsEndpoint.py b/src/pyhuntress/endpoints/managedsat/GroupsEndpoint.py index 5c59708..7705bae 100644 --- a/src/pyhuntress/endpoints/managedsat/GroupsEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/GroupsEndpoint.py @@ -52,10 +52,10 @@ class GroupsEndpoint( PaginatedResponse[SATGroups]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATGroups, diff --git a/src/pyhuntress/endpoints/managedsat/GroupsIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/GroupsIdEndpoint.py index 4773819..acd3306 100644 --- a/src/pyhuntress/endpoints/managedsat/GroupsIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/GroupsIdEndpoint.py @@ -38,10 +38,10 @@ class GroupsIdEndpoint( PaginatedResponse[SATGroups]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATGroups, diff --git a/src/pyhuntress/endpoints/managedsat/LearnersEndpoint.py b/src/pyhuntress/endpoints/managedsat/LearnersEndpoint.py index 78aa1bd..885d826 100644 --- a/src/pyhuntress/endpoints/managedsat/LearnersEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/LearnersEndpoint.py @@ -52,10 +52,10 @@ class LearnersEndpoint( PaginatedResponse[SATLearners]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATLearners, diff --git a/src/pyhuntress/endpoints/managedsat/LearnersIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/LearnersIdEndpoint.py index bfe18b1..45365a5 100644 --- a/src/pyhuntress/endpoints/managedsat/LearnersIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/LearnersIdEndpoint.py @@ -38,10 +38,10 @@ class LearnersIdEndpoint( PaginatedResponse[SATLearners]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATLearners, diff --git a/src/pyhuntress/endpoints/managedsat/PhishingCampaignScenariosEndpoint.py b/src/pyhuntress/endpoints/managedsat/PhishingCampaignScenariosEndpoint.py index 7fff65d..60525b0 100644 --- a/src/pyhuntress/endpoints/managedsat/PhishingCampaignScenariosEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/PhishingCampaignScenariosEndpoint.py @@ -52,10 +52,10 @@ class PhishingCampaignScenariosEndpoint( PaginatedResponse[SATData]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATPhishingScenarios, diff --git a/src/pyhuntress/endpoints/managedsat/PhishingCampaignScenariosIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/PhishingCampaignScenariosIdEndpoint.py index bacf660..8adbe19 100644 --- a/src/pyhuntress/endpoints/managedsat/PhishingCampaignScenariosIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/PhishingCampaignScenariosIdEndpoint.py @@ -45,10 +45,10 @@ class PhishingCampaignScenariosIdEndpoint( PaginatedResponse[SATPhishingScenarios]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATPhishingScenarios, diff --git a/src/pyhuntress/endpoints/managedsat/PhishingCampaignsEndpoint.py b/src/pyhuntress/endpoints/managedsat/PhishingCampaignsEndpoint.py index 8bee66b..837a69d 100644 --- a/src/pyhuntress/endpoints/managedsat/PhishingCampaignsEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/PhishingCampaignsEndpoint.py @@ -52,10 +52,10 @@ class PhishingCampaignsEndpoint( PaginatedResponse[SATData]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATPhishingCampaigns, diff --git a/src/pyhuntress/endpoints/managedsat/PhishingCampaignsIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/PhishingCampaignsIdEndpoint.py index bf3b7de..b189a09 100644 --- a/src/pyhuntress/endpoints/managedsat/PhishingCampaignsIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/PhishingCampaignsIdEndpoint.py @@ -43,10 +43,10 @@ class PhishingCampaignsIdEndpoint( PaginatedResponse[SATPhishingCampaigns]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATPhishingCampaigns, diff --git a/src/pyhuntress/endpoints/managedsat/PhishingScenariosEndpoint.py b/src/pyhuntress/endpoints/managedsat/PhishingScenariosEndpoint.py index 6e1e546..ba0e08b 100644 --- a/src/pyhuntress/endpoints/managedsat/PhishingScenariosEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/PhishingScenariosEndpoint.py @@ -52,10 +52,10 @@ class PhishingScenariosEndpoint( PaginatedResponse[SATPhishingScenarios]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATPhishingScenarios, diff --git a/src/pyhuntress/endpoints/managedsat/PhishingScenariosIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/PhishingScenariosIdEndpoint.py index 7fde1a1..17cd96c 100644 --- a/src/pyhuntress/endpoints/managedsat/PhishingScenariosIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/PhishingScenariosIdEndpoint.py @@ -38,10 +38,10 @@ class PhishingScenariosIdEndpoint( PaginatedResponse[SATPhishingScenarios]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATPhishingScenarios, diff --git a/src/pyhuntress/endpoints/managedsat/UsersEndpoint.py b/src/pyhuntress/endpoints/managedsat/UsersEndpoint.py index 1dbb750..21f9a0e 100644 --- a/src/pyhuntress/endpoints/managedsat/UsersEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/UsersEndpoint.py @@ -54,10 +54,10 @@ class UsersEndpoint( PaginatedResponse[SATData]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATUsers, diff --git a/src/pyhuntress/endpoints/managedsat/UsersIdEndpoint.py b/src/pyhuntress/endpoints/managedsat/UsersIdEndpoint.py index bb78efc..ed5adc2 100644 --- a/src/pyhuntress/endpoints/managedsat/UsersIdEndpoint.py +++ b/src/pyhuntress/endpoints/managedsat/UsersIdEndpoint.py @@ -39,10 +39,10 @@ class UsersIdEndpoint( PaginatedResponse[SATUsers]: The initialized PaginatedResponse object. """ if params: - params["page"] = page - params["limit"] = limit + params["page[number]"] = page + params["page[size]"] = limit else: - params = {"page": page, "limit": limit} + params = {"page[number]": page, "page[size]": limit} return PaginatedResponse( super()._make_request("GET", params=params), SATUsers, diff --git a/src/pyhuntress/responses/paginated_response.py b/src/pyhuntress/responses/paginated_response.py index 8331404..95b3d2f 100644 --- a/src/pyhuntress/responses/paginated_response.py +++ b/src/pyhuntress/responses/paginated_response.py @@ -84,8 +84,11 @@ class PaginatedResponse(Generic[TModel]): self.endpointmodel = endpointmodel self.endpoint = endpoint self.limit = limit - # 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', {})) + # Get page data from the response body + try: + self.parsed_pagination_response = parse_response_body(json.loads(response.content.decode('utf-8')).get('pagination', {})) + except: + self.parsed_pagination_response = parse_response_body(json.loads(response.content.decode('utf-8')).get('meta.page', {})) self.params = params if self.parsed_pagination_response is not None: # Huntress SIEM API gives us a handy response to parse for Pagination diff --git a/src/pyhuntress/utils/helpers.py b/src/pyhuntress/utils/helpers.py index 6da8e5b..68d3463 100644 --- a/src/pyhuntress/utils/helpers.py +++ b/src/pyhuntress/utils/helpers.py @@ -77,12 +77,19 @@ def parse_response_body( elif body.get("current_page") is not None: if body.get("current_page") > 1: result["prev_page"] = body.get("current_page") - 1 + elif body.get("currentPage") is not None: + if body.get("currentPage") > 1: + result["prev_page"] = body.get("currentPage") - 1 if body.get("next_page") is not None: result["next_page"] = body.get("next_page") + elif body.get("currentPage") is not None and body.get("currentPage") < body.get("lastPage"): + result["next_page"] = body.get("currentPage") + 1 if body.get("last_page") is not None: result["last_page"] = body.get("last_page") + elif body.get("lastPage") is not None: + result["last_page"] = body.get("lastPage") 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")) @@ -92,12 +99,17 @@ def parse_response_body( result["has_next_page"] = True elif body.get("current_page") is not None and body.get("next_page") is None: result["has_next_page"] = False - + elif body.get("currentPage") is not None and body.get("currentPage") < body.get("lastPage"): + result["has_next_page"] = True + 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 + elif body.get("currentPage") is not None: + if body.get("currentPage") > 1: + result["has_prev_page"] = True return result