grahampugh / jamf-upload

Scripts for uploading packages to Jamf Cloud
Apache License 2.0
150 stars 39 forks source link

(Properly Fix) Raise error if unable to determine version of Jamf Pro #83

Closed MLBZ521 closed 1 year ago

MLBZ521 commented 2 years ago

Proper fix for PR #80. I put that fix in the wrong location, my bad.

If JamfUploader is unable to determine the Jamf Pro version, None is returned and is attempted to be compared, which results in the following error that doesn't make it obvious where the issue actually lies: Error: 'APLooseVersion' object has no attribute 'version'

Here's a sanitized -vvv run with the stack trace:

JamfPolicyUploader: Checking for existing 'Firefox' on <https://jps.org:8443>
JamfPolicyUploader: Checking for existing authentication token
JamfPolicyUploader: Checking <https://jps.org:8443> against <https://jps.org:8443>
JamfPolicyUploader: URL and user for token matches current request
JamfPolicyUploader: Existing token is valid
JamfPolicyUploader: curl command: /usr/bin/curl --dump-header /tmp/jamf_upload/curl_headers_from_jamf_upload.txt <https://jps.org:8443>/api/v1/jamf-pro-version --request GET --silent --show-error --header authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdXRoZW50aWNhdGVkLWFwcCI6IkdFTkVSSUMiLCJhdXRoZW50aWNhdGlvbi10eXBlIjoiSlNTIiwiZ3JvdXBzIjpbXSwic3ViamVjdC10eXBlIjoiSlNTX1VTRVJfSUQiLCJ0b2tlbi11dWlkIjoiZDBhODBiZjYtOTg0MS00NzczLWI5ZTEtMTY2MmI3MmRhMjE1IiwibGRhcC1zZXJ2ZXItaWQiOi0xLCJzdWIiOiI0OCIsImV4cCI6MTY2NDQwNjcxMX0.YWW1v1qSO8TIaJvV7T1CkYwgezAV9NZUUHxJg_HSXgc --output /tmp/jamf_upload/curl_output_from_jamf_upload.txt --output /tmp/jamf_upload/curl_output_from_jamf_upload.txt --header Accept: application/json --cookie-jar /tmp/jamf_upload/curl_cookies_from_jamf_upload.txt --cookie /tmp/jamf_upload/curl_cookies_from_jamf_upload.txt
JamfPolicyUploader: ERROR: No version received
Traceback (most recent call last):
  File "/Library/AutoPkg/autopkglib/__init__.py", line 840, in process
    self.env = processor.process()
  File "/Library/AutoPkg/autopkglib/__init__.py", line 626, in process
    self.main()
  File "/Library/AutoPkg/RecipeRepos/com.github.autopkg.grahampugh-recipes/JamfUploaderProcessors/JamfPolicyUploader.py", line 292, in main
    token, send_creds, _ = self.handle_classic_auth(
  File "/Library/AutoPkg/RecipeRepos/com.github.autopkg.grahampugh-recipes/JamfUploaderProcessors/JamfUploaderLib/JamfUploaderBase.py", line 216, in handle_classic_auth
    if self.validate_jamf_pro_version(url, token):
  File "/Library/AutoPkg/RecipeRepos/com.github.autopkg.grahampugh-recipes/JamfUploaderProcessors/JamfUploaderLib/JamfUploaderBase.py", line 469, in validate_jamf_pro_version
    if APLooseVersion(jamf_pro_version) >= APLooseVersion("10.35.0"):
  File "/Library/AutoPkg/autopkglib/__init__.py", line 954, in __ge__
    return self._compare(other) >= 0
  File "/Library/AutoPkg/autopkglib/__init__.py", line 911, in _compare
    max_length = max(len(self.version), len(other.version))
AttributeError: 'APLooseVersion' object has no attribute 'version'
  File "/Library/AutoPkg/autopkglib/__init__.py", line 840, in process
    self.env = processor.process()
Receipt written to /Library/AutoPkg/Cache/local.Firefox/receipts/local.Firefox-receipt-20220928-160241.plist

The following recipes failed:
    local.Firefox
        Error in local.Firefox: Processor: com.github.grahampugh.jamf-upload.processors/JamfPolicyUploader: Error: 'APLooseVersion' object has no attribute 'version'

I believe this is caused by a concurrency issue that I've been trying to track down and will submit a PR for.