macadmins / jamf-pro-sdk-python

A client library for the Jamf Pro APIs and webhooks.
https://macadmins.github.io/jamf-pro-sdk-python/
MIT License
47 stars 10 forks source link

[Bug] ClassicAdvancedComputerSearch error when scope includes 'member of' #41

Closed K1jaff closed 2 months ago

K1jaff commented 5 months ago

Attempting to get a list of computers missing a Recovery lock password, target report was: "is not" Recovery Lock Enabled = Enabled "is" Recovery Lock Enabled = arm64 "member of" Computer Group = All Managed Clients

workaround is to change the "member of" operator to "is" Managed = Managed

Steps to Reproduce

from jamf_pro_sdk import JamfProClient

reportdata = client.classic_api.get_advanced_computer_search_by_id(reportwithmemberof)

Expected Result

Output of report computers

Actual Result

Traceback (most recent call last): File "/usr/local/bin/Scripts/./JAMF_Script.py", line 35, in reportdata = client.classic_api.get_advanced_computer_search_by_id(98) File "/home/username/.local/lib/python3.10/site-packages/jamf_pro_sdk/clients/classic_api.py", line 490, in get_advanced_computer_search_by_id return ClassicAdvancedComputerSearch(resp.json()["advanced_computer_search"]) File "/home/username/.local/lib/python3.10/site-packages/jamf_pro_sdk/models/init.py", line 9, in init super().init(kwargs) File "/home/username/.local/lib/python3.10/site-packages/pydantic/main.py", line 175, in init self.__pydantic_validator__.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 1 validation error for ClassicAdvancedComputerSearch criteria.2.search_type Input should be 'is', 'is not', 'like', 'not like', 'has', 'does not have', 'matches regex', 'does not match regex', 'before (yyyy-mm-dd)', 'after (yyyy-mm-dd)', 'more than x days ago', 'less than x days ago', 'current', 'not current', 'greater than', 'less than', 'greater than or equal' or 'less than or equal' [type=enum, input_value='member of', input_type=str] For further information visit https://errors.pydantic.dev/2.7/v/enum

System Information

Ubuntu 22.04.4 LTS Name: jamf-pro-sdk Version: 0.6a1 Name: pydantic Version: 2.7.0

brysontyrrell commented 5 months ago

@K1jaff can you test this fix?

pip install git+https://github.com/macadmins/jamf-pro-sdk-python.git@fix-criteria-missing-member-of

K1jaff commented 5 months ago

no joy, installed it with pip and pip3 just to sure.

Traceback (most recent call last): File "/usr/local/bin/Scripts/./JAMF_Script.py", line 37, in <module> reportdata = client.classic_api.get_advanced_computer_search_by_id(98) File "/home/user/.local/lib/python3.10/site-packages/jamf_pro_sdk/clients/classic_api.py", line 490, in get_advanced_computer_search_by_id return ClassicAdvancedComputerSearch(**resp.json()["advanced_computer_search"]) File "/home/uset/.local/lib/python3.10/site-packages/jamf_pro_sdk/models/__init__.py", line 9, in __init__ super().__init__(**kwargs) File "/home/user/.local/lib/python3.10/site-packages/pydantic/main.py", line 175, in __init__ self.__pydantic_validator__.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 1 validation error for ClassicAdvancedComputerSearch criteria.3.search_type Input should be 'is', 'is not', 'like', 'not like', 'has', 'does not have', 'matches regex', 'does not match regex', 'before (yyyy-mm-dd)', 'after (yyyy-mm-dd)', 'more than x days ago', 'less than x days ago', 'current', 'not current', 'greater than', 'less than', 'greater than or equal' or 'less than or equal' [type=enum, input_value='member of', input_type=str] For further information visit https://errors.pydantic.dev/2.7/v/enum

pboushy commented 2 months ago

@brysontyrrell - I tested that branch and it does resolve this issue.

@K1jaff - I think you need to pip uninstall jamf_pro_sdk, and then pip install git+https://github.com/macadmins/jamf-pro-sdk-python.git@fix-criteria-missing-member-of

To confirm you actually have the fix, run this command: grep 'member_of' /home/user/.local/lib/python3.10/site-packages/jamf_pro_sdk/models/classic/criteria.py

If that command doesn't show the below, then python didn't actually use Bryson's branch.

member_of: str = "member of"