From 92b3f384b6c00c573c6a74f3c69d1d58b6b2a39f Mon Sep 17 00:00:00 2001 From: Josh Burns Date: Tue, 24 Oct 2023 19:02:46 -0700 Subject: [PATCH 1/5] added classic api method for setting device management status --- src/jamf_pro_sdk/clients/classic_api.py | 70 ++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/jamf_pro_sdk/clients/classic_api.py b/src/jamf_pro_sdk/clients/classic_api.py index 8f383dc..dfd1e5d 100644 --- a/src/jamf_pro_sdk/clients/classic_api.py +++ b/src/jamf_pro_sdk/clients/classic_api.py @@ -1,6 +1,8 @@ from __future__ import annotations from typing import TYPE_CHECKING, Callable, Iterable, Iterator, List, Union +import secrets +import string from defusedxml.ElementTree import fromstring @@ -9,7 +11,10 @@ ClassicComputerGroupMember, ClassicComputerGroupMembershipUpdate, ) -from ..models.classic.computers import ClassicComputer, ClassicComputersItem +from ..models.classic.computers import ( + ClassicComputer, + ClassicComputersItem, +) from ..models.classic.packages import ClassicPackage, ClassicPackageItem if TYPE_CHECKING: @@ -173,6 +178,69 @@ def delete_computer_by_id(self, computer: ComputerId) -> None: computer_id = ClassicApi._parse_id(computer) self.api_request(method="delete", resource_path=f"computers/id/{computer_id}") + def set_computer_unmanaged_by_id(self, computer: ComputerId) -> None: + """Sets the management status to `unmanaged` for a single computer using the ID + + ..important:: + This action does not remove the management framework or mdm profile from the device + + :param computer: A computer ID or supported Classic API model. + :type computer: Union[int, ~jamf_pro_sdk.models.classic.computers.Computer, ComputersItem] + """ + data = { + "general": { + "remote_management": { + "managed": False, + "management_username": "", + "management_password": "", + } + } + } + update_management = ClassicComputer(**data) + computer_id = ClassicApi._parse_id(computer) + self.api_request( + method="put", resource_path=f"computers/id/{computer_id}", data=update_management + ) + + def set_computer_managed_by_id( + self, computer: ComputerId, management_user: str = "admin", management_password: str = None + ) -> None: + """Sets the management status to `managed` for a single computer using the ID. + + ..important:: + The management user does not need to match any local user account but is required for the device to be "managed" + + :param computer: A computer ID or supported Classic API model. + :type computer: Union[int, ~jamf_pro_sdk.models.classic.computers.Computer, ComputersItem] + + :param management_user: (optional) The management username. Defaults to 'admin' if not specified + :type management_user: str + + :param management_password: (optional) The management password. Defaults to a randomly generated password if not specified + :type management_password: str + + """ + if not management_password: + management_password = secrets.choice( + string.ascii_uppercase + string.ascii_lowercase + string.punctuation + for _ in range(16) + ) + computer_id = ClassicApi._parse_id(computer) + + data = { + "general": { + "remote_management": { + "managed": True, + "management_username": management_user, + "management_password": management_password, + } + } + } + manage_computer = ClassicComputer(**data) + self.api_request( + method="put", resource_path=f"computers/id/{computer_id}", data=manage_computer + ) + # /computergroups APIs def create_computer_group(self, data: Union[str, ClassicComputerGroup]) -> int: From 35e7d823d8dda31d3bcef8aad0143cfb54e500e7 Mon Sep 17 00:00:00 2001 From: Josh Burns Date: Tue, 24 Oct 2023 19:51:56 -0700 Subject: [PATCH 2/5] fixed import order --- src/jamf_pro_sdk/clients/classic_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jamf_pro_sdk/clients/classic_api.py b/src/jamf_pro_sdk/clients/classic_api.py index dfd1e5d..9ccc2a1 100644 --- a/src/jamf_pro_sdk/clients/classic_api.py +++ b/src/jamf_pro_sdk/clients/classic_api.py @@ -1,8 +1,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, Iterable, Iterator, List, Union import secrets import string +from typing import TYPE_CHECKING, Callable, Iterable, Iterator, List, Union from defusedxml.ElementTree import fromstring From 860002e60596fdaba470695a1776ad47c09a23ac Mon Sep 17 00:00:00 2001 From: Bryson Tyrrell Date: Wed, 25 Oct 2023 08:54:38 -0500 Subject: [PATCH 3/5] Update src/jamf_pro_sdk/clients/classic_api.py --- src/jamf_pro_sdk/clients/classic_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jamf_pro_sdk/clients/classic_api.py b/src/jamf_pro_sdk/clients/classic_api.py index 9ccc2a1..280e9d7 100644 --- a/src/jamf_pro_sdk/clients/classic_api.py +++ b/src/jamf_pro_sdk/clients/classic_api.py @@ -181,7 +181,7 @@ def delete_computer_by_id(self, computer: ComputerId) -> None: def set_computer_unmanaged_by_id(self, computer: ComputerId) -> None: """Sets the management status to `unmanaged` for a single computer using the ID - ..important:: + .. important:: This action does not remove the management framework or mdm profile from the device :param computer: A computer ID or supported Classic API model. From bd5e55acbded4034d12786569a440a3c26d63d06 Mon Sep 17 00:00:00 2001 From: Bryson Tyrrell Date: Wed, 25 Oct 2023 08:54:43 -0500 Subject: [PATCH 4/5] Update src/jamf_pro_sdk/clients/classic_api.py --- src/jamf_pro_sdk/clients/classic_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jamf_pro_sdk/clients/classic_api.py b/src/jamf_pro_sdk/clients/classic_api.py index 280e9d7..ea4eee6 100644 --- a/src/jamf_pro_sdk/clients/classic_api.py +++ b/src/jamf_pro_sdk/clients/classic_api.py @@ -207,7 +207,7 @@ def set_computer_managed_by_id( ) -> None: """Sets the management status to `managed` for a single computer using the ID. - ..important:: + .. important:: The management user does not need to match any local user account but is required for the device to be "managed" :param computer: A computer ID or supported Classic API model. From 488a7600c63b18452daa81d8a8370312b1b7d9e5 Mon Sep 17 00:00:00 2001 From: Bryson Tyrrell Date: Wed, 25 Oct 2023 08:55:07 -0500 Subject: [PATCH 5/5] Update src/jamf_pro_sdk/clients/classic_api.py --- src/jamf_pro_sdk/clients/classic_api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/jamf_pro_sdk/clients/classic_api.py b/src/jamf_pro_sdk/clients/classic_api.py index ea4eee6..ddf1cb7 100644 --- a/src/jamf_pro_sdk/clients/classic_api.py +++ b/src/jamf_pro_sdk/clients/classic_api.py @@ -221,9 +221,8 @@ def set_computer_managed_by_id( """ if not management_password: - management_password = secrets.choice( - string.ascii_uppercase + string.ascii_lowercase + string.punctuation - for _ in range(16) + management_password = "".join( + secrets.choice(string.ascii_letters + string.punctuation) for _ in range(16) ) computer_id = ClassicApi._parse_id(computer)