Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement skip_expression_validation, update sort and filter values for Jamf Pro 11.3 #58

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions src/jamf_pro_sdk/clients/pro_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def get_computer_inventory_v1(
page_size: int = ...,
sort_expression: Optional[SortExpression] = ...,
filter_expression: Optional[FilterExpression] = ...,
skip_expression_validation: Optional[bool] = ...,
return_generator: Literal[False] = False,
) -> List[Computer]: ...

Expand All @@ -76,6 +77,7 @@ def get_computer_inventory_v1(
page_size: int = ...,
sort_expression: Optional[SortExpression] = ...,
filter_expression: Optional[FilterExpression] = ...,
skip_expression_validation: Optional[bool] = ...,
return_generator: Literal[True] = True,
) -> Iterator[Page]: ...

Expand All @@ -87,6 +89,7 @@ def get_computer_inventory_v1(
page_size: int = 100,
sort_expression: Optional[SortExpression] = None,
filter_expression: Optional[FilterExpression] = None,
skip_expression_validation: Optional[bool] = False,
return_generator: bool = False,
) -> Union[List[Computer], Iterator[Page]]:
"""Returns a list of computer inventory records.
Expand Down Expand Up @@ -131,6 +134,10 @@ def get_computer_inventory_v1(

:type filter_expression: FilterExpression

:param skip_expression_validation: (optional) If ``True`` sort and filter field values validation is skipped.
Intended to be used in situations where a newer API version is ahead of the SDK release.
:type skip_expression_validation: bool

:param return_generator: If ``True`` a generator is returned to iterate over pages. By
default, the results for all pages will be returned in a single response.
:type return_generator: bool
Expand All @@ -149,10 +156,10 @@ def get_computer_inventory_v1(
f"Values for 'sections' must be one of: {', '.join(get_computer_inventory_v1_allowed_sections)}"
)

if sort_expression:
if sort_expression and not skip_expression_validation:
sort_expression.validate(get_computer_inventory_v1_allowed_sort_fields)

if filter_expression:
if filter_expression and not skip_expression_validation:
filter_expression.validate(get_computer_inventory_v1_allowed_filter_fields)

paginator = Paginator(
Expand All @@ -164,6 +171,7 @@ def get_computer_inventory_v1(
page_size=page_size,
sort_expression=sort_expression,
filter_expression=filter_expression,
skip_expression_validation=skip_expression_validation,
extra_params={"section": ",".join(sections)},
)

Expand All @@ -179,6 +187,7 @@ def get_packages_v1(
page_size: int = ...,
sort_expression: Optional[SortExpression] = ...,
filter_expression: Optional[FilterExpression] = ...,
skip_expression_validation: Optional[bool] = ...,
return_generator: Literal[False] = False,
) -> List[Package]: ...

Expand All @@ -190,6 +199,7 @@ def get_packages_v1(
page_size: int = ...,
sort_expression: Optional[SortExpression] = ...,
filter_expression: Optional[FilterExpression] = ...,
skip_expression_validation: Optional[bool] = ...,
return_generator: Literal[True] = True,
) -> Iterator[Page]: ...

Expand All @@ -200,6 +210,7 @@ def get_packages_v1(
page_size: int = 100,
sort_expression: Optional[SortExpression] = None,
filter_expression: Optional[FilterExpression] = None,
skip_expression_validation: Optional[bool] = False,
return_generator: bool = False,
) -> Union[List[Package], Iterator[Page]]:
"""Returns a list of package records.
Expand Down Expand Up @@ -234,6 +245,10 @@ def get_packages_v1(

:type filter_expression: FilterExpression

:param skip_expression_validation: (optional) If ``True`` sort and filter field values validation is skipped.
Intended to be used in situations where a newer API version is ahead of the SDK release.
:type skip_expression_validation: bool

:param return_generator: If ``True`` a generator is returned to iterate over pages. By
default, the results for all pages will be returned in a single response.
:type return_generator: bool
Expand All @@ -242,10 +257,10 @@ def get_packages_v1(
:rtype: List[~jamf_pro_sdk.models.pro.packages.package] | Iterator[Page]

"""
if sort_expression:
if sort_expression and not skip_expression_validation:
sort_expression.validate(get_packages_v1_allowed_sort_fields)

if filter_expression:
if filter_expression and not skip_expression_validation:
filter_expression.validate(get_packages_v1_allowed_filter_fields)

paginator = Paginator(
Expand All @@ -257,6 +272,7 @@ def get_packages_v1(
page_size=page_size,
sort_expression=sort_expression,
filter_expression=filter_expression,
skip_expression_validation=skip_expression_validation,
)

return paginator(return_generator=return_generator)
Expand Down Expand Up @@ -393,6 +409,7 @@ def get_mdm_commands_v2(
end_page: Optional[int] = ...,
page_size: int = ...,
sort_expression: Optional[SortExpression] = ...,
skip_expression_validation: Optional[bool] = ...,
return_generator: Literal[False] = False,
) -> List[MdmCommandStatus]: ...

Expand All @@ -404,6 +421,7 @@ def get_mdm_commands_v2(
end_page: Optional[int] = ...,
page_size: int = ...,
sort_expression: Optional[SortExpression] = ...,
skip_expression_validation: Optional[bool] = ...,
return_generator: Literal[True] = True,
) -> Iterator[Page]: ...

Expand All @@ -414,6 +432,7 @@ def get_mdm_commands_v2(
end_page: Optional[int] = None,
page_size: int = 100,
sort_expression: Optional[SortExpression] = None,
skip_expression_validation: Optional[bool] = False,
return_generator: bool = False,
) -> Union[List[MdmCommandStatus], Iterator[Page]]:
"""Returns a list of MDM commands.
Expand Down Expand Up @@ -449,6 +468,10 @@ def get_mdm_commands_v2(

:type sort_expression: SortExpression

:param skip_expression_validation: (optional) If ``True`` sort and filter field values validation is skipped.
Intended to be used in situations where a newer API version is ahead of the SDK release.
:type skip_expression_validation: bool

:param return_generator: If ``True`` an iterator is returned that yields pages. By default,
the results for all pages will be returned in a single response.
:type return_generator: bool
Expand All @@ -465,10 +488,10 @@ def get_mdm_commands_v2(
f"Values for 'command' filters must be one of: {', '.join(get_mdm_commands_v2_allowed_command_types)}"
)

if sort_expression:
if sort_expression and not skip_expression_validation:
sort_expression.validate(get_mdm_commands_v2_allowed_sort_fields)

if filter_expression:
if filter_expression and not skip_expression_validation:
filter_expression.validate(get_mdm_commands_v2_allowed_filter_fields)

paginator = Paginator(
Expand All @@ -480,6 +503,7 @@ def get_mdm_commands_v2(
page_size=page_size,
sort_expression=sort_expression,
filter_expression=filter_expression,
skip_expression_validation=skip_expression_validation,
)

return paginator(return_generator=return_generator)
Expand All @@ -495,6 +519,7 @@ def get_mobile_device_inventory_v2(
page_size: int = ...,
sort_expression: Optional[SortExpression] = ...,
filter_expression: Optional[FilterExpression] = ...,
skip_expression_validation: Optional[bool] = ...,
return_generator: Literal[False] = False,
) -> List[MobileDevice]: ...

Expand All @@ -507,6 +532,7 @@ def get_mobile_device_inventory_v2(
page_size: int = ...,
sort_expression: Optional[SortExpression] = ...,
filter_expression: Optional[FilterExpression] = ...,
skip_expression_validation: Optional[bool] = ...,
return_generator: Literal[True] = True,
) -> Iterator[Page]: ...

Expand All @@ -518,6 +544,7 @@ def get_mobile_device_inventory_v2(
page_size: int = 100,
sort_expression: Optional[SortExpression] = None,
filter_expression: Optional[FilterExpression] = None,
skip_expression_validation: Optional[bool] = False,
return_generator: bool = False,
) -> Union[List[MobileDevice], Iterator[Page]]:
"""Returns a list of mobile device (iOS and tvOS) inventory records.
Expand Down Expand Up @@ -562,6 +589,10 @@ def get_mobile_device_inventory_v2(

:type filter_expression: FilterExpression

:param skip_expression_validation: (optional) If ``True`` sort and filter field values validation is skipped.
Intended to be used in situations where a newer API version is ahead of the SDK release.
:type skip_expression_validation: bool

:param return_generator: If ``True`` a generator is returned to iterate over pages. By
default, the results for all pages will be returned in a single response.
:type return_generator: bool
Expand All @@ -580,10 +611,10 @@ def get_mobile_device_inventory_v2(
f"Values for 'sections' must be one of: {', '.join(get_mobile_device_inventory_v2_allowed_sections)}"
)

if sort_expression:
if sort_expression and not skip_expression_validation:
sort_expression.validate(get_mobile_device_inventory_v2_allowed_sort_fields)

if filter_expression:
if filter_expression and not skip_expression_validation:
filter_expression.validate(get_mobile_device_inventory_v2_allowed_filter_fields)

paginator = Paginator(
Expand All @@ -595,6 +626,7 @@ def get_mobile_device_inventory_v2(
page_size=page_size,
sort_expression=sort_expression,
filter_expression=filter_expression,
skip_expression_validation=skip_expression_validation,
extra_params={"section": ",".join(sections)},
)

Expand Down
6 changes: 6 additions & 0 deletions src/jamf_pro_sdk/clients/pro_api/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def __init__(
page_size: int = 100,
sort_expression: Optional[SortExpression] = None,
filter_expression: Optional[FilterExpression] = None,
skip_expression_validation: Optional[bool] = False,
extra_params: Optional[Dict[str, str]] = None,
):
"""A paginator for the Jamf Pro API. A paginator automatically iterates over an API if
Expand Down Expand Up @@ -196,6 +197,10 @@ def __init__(
documentation for :ref:`Pro API Filtering` for more information.
:type filter_expression: FilterExpression

:param skip_expression_validation: (optional) If ``True`` sort and filter field values validation is skipped.
Intended to be used in situations where a newer API version is ahead of the SDK release.
:type skip_expression_validation: bool

:param extra_params: (optional) A dictionary of key-value pairs that will be added to the
query string parameters of the requests.
:type extra_params: Dict[str, str]
Expand All @@ -209,6 +214,7 @@ def __init__(
self.page_size = page_size
self.sort_expression = sort_expression
self.filter_expression = filter_expression
self.skip_expression_validation = skip_expression_validation
self.extra_params = extra_params

def _paginated_request(self, page: int) -> Page:
Expand Down
Loading
Loading