Added pagination to phsihing-campaigns/{id}/campaign-scenarios

This commit is contained in:
Peter Annabel 2025-07-29 12:01:39 -05:00
parent 6de7fb2ce2
commit b9068b8185
3 changed files with 42 additions and 8 deletions

View File

@ -1,6 +1,6 @@
[project] [project]
name = "pyhuntress" name = "pyhuntress"
version = "0.2.10" version = "0.2.11"
authors = [ authors = [
{ name="Peter Annabel", email="peter.annabel@gmail.com" }, { name="Peter Annabel", email="peter.annabel@gmail.com" },
] ]

View File

@ -10,7 +10,7 @@ from pyhuntress.types import (
HuntressSATRequestParams, HuntressSATRequestParams,
) )
# THIS ENDPOINT RETURNS ABSOLUTELY NOTHING. DO NOT USE
class AccountsIdPhishingScenariosEndpoint( class AccountsIdPhishingScenariosEndpoint(
HuntressEndpoint, HuntressEndpoint,
IGettable[SATPhishingScenarios, HuntressSATRequestParams], IGettable[SATPhishingScenarios, HuntressSATRequestParams],

View File

@ -1,8 +1,10 @@
from pyhuntress.endpoints.base.huntress_endpoint import HuntressEndpoint from pyhuntress.endpoints.base.huntress_endpoint import HuntressEndpoint
from pyhuntress.interfaces import ( from pyhuntress.interfaces import (
IGettable, IGettable,
IPaginateable,
) )
from pyhuntress.models.managedsat import SATPhishingCampaigns from pyhuntress.models.managedsat import SATPhishingScenarios
from pyhuntress.responses.paginated_response import PaginatedResponse
from pyhuntress.types import ( from pyhuntress.types import (
JSON, JSON,
HuntressSATRequestParams, HuntressSATRequestParams,
@ -11,17 +13,49 @@ from pyhuntress.types import (
class PhishingCampaignsIdCampaignScenariosEndpoint( class PhishingCampaignsIdCampaignScenariosEndpoint(
HuntressEndpoint, HuntressEndpoint,
IGettable[SATPhishingCampaigns, HuntressSATRequestParams], IGettable[SATPhishingScenarios, HuntressSATRequestParams],
IPaginateable[SATPhishingScenarios, HuntressSATRequestParams],
): ):
def __init__(self, client, parent_endpoint=None) -> None: def __init__(self, client, parent_endpoint=None) -> None:
HuntressEndpoint.__init__(self, client, "campaign-scenarios", parent_endpoint=parent_endpoint) HuntressEndpoint.__init__(self, client, "campaign-scenarios", parent_endpoint=parent_endpoint)
IGettable.__init__(self, SATPhishingCampaigns) IGettable.__init__(self, SATPhishingScenarios)
def paginated(
self,
page: int,
limit: int,
params: HuntressSATRequestParams | None = None,
) -> PaginatedResponse[SATPhishingScenarios]:
"""
Performs a GET request against the /phishing-campaigns/{id}/phishing-scenarios endpoint and returns an initialized PaginatedResponse object.
Parameters:
page (int): The page number to request.
limit (int): The number of results to return per page.
params (dict[str, int | str]): The parameters to send in the request query string.
Returns:
PaginatedResponse[SATPhishingScenarios]: The initialized PaginatedResponse object.
"""
if params:
params["page[number]"] = page
params["page[size]"] = limit
else:
params = {"page[number]": page, "page[size]": limit}
return PaginatedResponse(
super()._make_request("GET", params=params),
SATPhishingScenarios,
self,
"data",
page,
limit,
params,
)
def get( def get(
self, self,
data: JSON | None = None, data: JSON | None = None,
params: HuntressSATRequestParams | None = None, params: HuntressSATRequestParams | None = None,
) -> SATPhishingCampaigns: ) -> SATPhishingScenarios:
# TODO: Make this require the learnerid as a parameter # TODO: Make this require the learnerid as a parameter
@ -32,9 +66,9 @@ class PhishingCampaignsIdCampaignScenariosEndpoint(
data (dict[str, Any]): The data to send in the request body. data (dict[str, Any]): The data to send in the request body.
params (dict[str, int | str]): The parameters to send in the request query string. params (dict[str, int | str]): The parameters to send in the request query string.
Returns: Returns:
SATPhishingCampaigns: The parsed response data. SATPhishingScenarios: The parsed response data.
""" """
return self._parse_many( return self._parse_many(
SATPhishingCampaigns, SATPhishingScenarios,
super()._make_request("GET", data=data, params=params).json().get('data', {}), super()._make_request("GET", data=data, params=params).json().get('data', {}),
) )