Skip to content

Commit

Permalink
Merge pull request #39 from macadmins/mobile-devices
Browse files Browse the repository at this point in the history
Get Mobile Devices
  • Loading branch information
brysontyrrell authored Feb 14, 2024
2 parents 11ca8c1 + d9b1a13 commit 7b6f011
Show file tree
Hide file tree
Showing 10 changed files with 697 additions and 18 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/main_pr_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
contents: read

jobs:
automated-tests:
setup-env:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -33,3 +33,26 @@ jobs:

- name: Tests
run: make test

exp-integration-tests:
continue-on-error: true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'

- name: Install
run: make install

- name: Run Integration Tests
run: make test-all
env:
JAMF_PRO_HOST: ${{ vars.JAMF_PRO_HOST }}
JAMF_PRO_CLIENT_ID: ${{ vars.JAMF_PRO_CLIENT_ID }}
JAMF_PRO_CLIENT_SECRET: ${{ vars.JAMF_PRO_CLIENT_SECRET }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /bin/bash
.PHONY: docs

install:
python3 -m pip install --upgrade --editable '.[dev]'
python3 -m pip install --upgrade --force-reinstall --editable '.[dev]'

uninstall:
python3 -m pip uninstall -y -r <(python3 -m pip freeze)
Expand Down
27 changes: 27 additions & 0 deletions docs/reference/models_pro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,33 @@ MDM Commands
MdmCommandStatusStates
MdmCommandStatusTypes

Mobile Devices
--------------

.. currentmodule:: jamf_pro_sdk.models.pro.mobile_devices

.. autosummary::
:toctree: _autosummary

MobileDevice
MobileDeviceHardware
MobileDeviceUserAndLocation
MobileDevicePurchasing
MobileDeviceApplication
MobileDeviceCertificate
MobileDeviceProfile
MobileDeviceUserProfile
MobileDeviceExtensionAttribute
MobileDeviceGeneral
MobileDeviceOwnershipType
MobileDeviceEnrollmentMethodPrestage
MobileDeviceSecurity
MobileDeviceEbook
MobileDeviceNetwork
MobileDeviceServiceSubscription
ProvisioningProfile
SharedUser

Pagination
----------

Expand Down
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ line-length = 100
[tool.ruff]
line-length = 100
target-version = "py39"
src = [
"src",
"tests"
]


[tool.ruff.lint]
select = [
"E101",
"F401",
Expand All @@ -93,14 +100,7 @@ select = [
"N802",
"N806"
]
src = [
"src",
"tests"
]


[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
per-file-ignores = {"__init__.py" = ["F401"]}


[tool.pytest.ini_options]
Expand Down
96 changes: 96 additions & 0 deletions src/jamf_pro_sdk/clients/pro_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
SetRecoveryLockCommand,
ShutDownDeviceCommand,
)
from ...models.pro.mobile_devices import MobileDevice
from .pagination import Paginator

if TYPE_CHECKING:
Expand Down Expand Up @@ -259,6 +260,7 @@ def get_mdm_commands_v2(
self,
filter_expression: FilterExpression,
start_page: int = 0,
end_page: int = None,
page_size: int = 100,
sort_expression: SortExpression = None,
return_generator: bool = False,
Expand All @@ -279,6 +281,10 @@ def get_mdm_commands_v2(
:class:`Paginator` for more information.
:type start_page: int
:param end_page: (optional) The page to end returning results at. See :class:`Paginator` for
more information.
:type start_page: int
:param page_size: (optional) The number of results to include in each requested page. See
:class:`Paginator` for more information.
:type page_size: int
Expand Down Expand Up @@ -319,6 +325,96 @@ def get_mdm_commands_v2(
resource_path="v2/mdm/commands",
return_model=MdmCommandStatus,
start_page=start_page,
end_page=end_page,
page_size=page_size,
sort_expression=sort_expression,
filter_expression=filter_expression,
)

return paginator(return_generator=return_generator)

def get_mobile_device_inventory_v2(
self,
sections: List[str] = None,
start_page: int = 0,
end_page: int = None,
page_size: int = 100,
sort_expression: SortExpression = None,
filter_expression: FilterExpression = None,
return_generator: bool = False,
) -> Union[List[MobileDevice], Iterator[Page]]:
"""Returns a list of mobile device (iOS and tvOS) inventory records.
:param sections: (optional) Select which sections of the computer's details to return. If
not specific the request will default to ``GENERAL``. If ``ALL`` is passed then all
sections will be returned.
Allowed sections:
.. autoapioptions:: jamf_pro_sdk.models.pro.api_options.get_mobile_device_inventory_v2_allowed_sections
:type sections: List[str]
:param start_page: (optional) The page to begin returning results from. See
:class:`Paginator` for more information.
:type start_page: int
:param end_page: (optional) The page to end returning results at. See :class:`Paginator` for
more information.
:type start_page: int
:param page_size: (optional) The number of results to include in each requested page. See
:class:`Paginator` for more information.
:type page_size: int
:param sort_expression: (optional) The sort fields to apply to the request. See the
documentation for :ref:`Pro API Sorting` for more information.
Allowed sort fields:
.. autoapioptions:: jamf_pro_sdk.models.pro.api_options.get_mobile_device_inventory_v2_allowed_sort_fields
:type sort_expression: SortExpression
:param filter_expression: (optional) The filter expression to apply to the request. See the
documentation for :ref:`Pro API Filtering` for more information.
Allowed filter fields:
.. autoapioptions:: jamf_pro_sdk.models.pro.api_options.get_mobile_device_inventory_v2_allowed_filter_fields
:type filter_expression: FilterExpression
: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
:return: List of computers OR a paginator generator.
:rtype: List[~jamf_pro_sdk.models.pro.mobile_devices.MobileDevice] | Iterator[Page]
"""
if not sections:
sections = ["GENERAL"]
elif "ALL" in sections:
sections = get_mobile_device_inventory_v2_allowed_sections[1:]

if not all([i in get_mobile_device_inventory_v2_allowed_sections for i in sections]):
raise ValueError(
f"Values for 'sections' must be one of: {', '.join(get_mobile_device_inventory_v2_allowed_sections)}"
)

if sort_expression:
sort_expression.validate(get_mobile_device_inventory_v2_allowed_sort_fields)

if filter_expression:
filter_expression.validate(get_mobile_device_inventory_v2_allowed_filter_fields)

paginator = Paginator(
api_client=self,
resource_path="v2/mobile-devices/detail",
return_model=MobileDevice,
start_page=start_page,
end_page=end_page,
page_size=page_size,
sort_expression=sort_expression,
filter_expression=filter_expression,
Expand Down
8 changes: 5 additions & 3 deletions src/jamf_pro_sdk/clients/pro_api/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ def _paginated_request(self, page: int) -> Page:
page=page,
page_count=len(response["results"]),
total_count=response["totalCount"],
results=[self.return_model.model_validate(i) for i in response["results"]]
if self.return_model
else response["results"],
results=(
[self.return_model.model_validate(i) for i in response["results"]]
if self.return_model
else response["results"]
),
)

def _request(self) -> Iterator[Page]:
Expand Down
Loading

0 comments on commit 7b6f011

Please sign in to comment.