add pagination to campaign phishing attempts endpoint

This commit is contained in:
Peter Annabel 2026-01-15 22:38:06 -06:00
parent 9c92b3e274
commit 7532b475a7
3 changed files with 41 additions and 2 deletions

View File

@ -153,4 +153,8 @@ Contributions to the project are welcome. If you find any issues or have suggest
:heart:
# Inspiration and Stolen Code
The premise behind this came from the [pyConnectWise](https://github.com/HealthITAU/pyconnectwise) package and I stole **most** of the code and adapted it to the Huntress API endpoints.
The premise behind this came from the [pyConnectWise](https://github.com/HealthITAU/pyconnectwise) package and I stole **most** of the code and adapted it to the Huntress API endpoints.
# How to Build
> python -m build
> python -m twine upload dist/*

View File

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

View File

@ -1,8 +1,10 @@
from pyhuntress.endpoints.base.huntress_endpoint import HuntressEndpoint
from pyhuntress.interfaces import (
IGettable,
IPaginateable,
)
from pyhuntress.models.managedsat import SATPhishingCampaignAttempts
from pyhuntress.responses.paginated_response import PaginatedResponse
from pyhuntress.types import (
JSON,
HuntressSATRequestParams,
@ -12,10 +14,43 @@ from pyhuntress.types import (
class PhishingCampaignsIdAttemptsEndpoint(
HuntressEndpoint,
IGettable[SATPhishingCampaignAttempts, HuntressSATRequestParams],
IPaginateable[SATPhishingCampaignAttempts, HuntressSATRequestParams],
):
def __init__(self, client, parent_endpoint=None) -> None:
HuntressEndpoint.__init__(self, client, "attempts", parent_endpoint=parent_endpoint)
IGettable.__init__(self, SATPhishingCampaignAttempts)
IPaginateable.__init__(self, SATPhishingCampaignAttempts)
def paginated(
self,
page: int,
limit: int,
params: HuntressSATRequestParams | None = None,
) -> PaginatedResponse[SATPhishingCampaignAttempts]:
"""
Performs a GET request against the /phishing-campaign-scenarios/{id}/attempts 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[SATPhishingCampaignAttempts]: 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),
SATPhishingCampaignAttempts,
self,
"data",
page,
limit,
params,
)
def get(
self,