Coder Social home page Coder Social logo

univ-of-utah-marriott-library-apple / jctl Goto Github PK

View Code? Open in Web Editor NEW
50.0 6.0 7.0 384 KB

`jctl` uses `python-jamf` to select objects to create, delete, print and update. It allows performing Jamf Pro repetitive tasks quickly and provides options not available in the web GUI. It is similar to SQL statements, but far less complex.

License: MIT License

Python 100.00%
python macos patch jamf-pro automation jamf installer-packages jamf-pro-api autopkg

jctl's People

Contributors

homebysix avatar magnusviri avatar sambarufus avatar tophernad avatar uurazzle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jctl's Issues

Change "master" to "main"

Topher, can you change "master" to "main"? The python-jamf project is using "main". All new github projects will be created with "main" from now on. It's making me bonkers trying to remember which one is main or master.

Subcommand `spreadsheet` fails for policies

I was trying to get a detailed list of the policies that have the checkin trigger by running jctl policies -s general/trigger_checkin==true -S spreadsheet but it failed with the following error:

File "/Users/bprieto/.pyenv/versions/3.9.10/bin/jctl", line 559, in <module>
    main(sys.argv[1:])
  File "/Users/bprieto/.pyenv/versions/3.9.10/bin/jctl", line 405, in main
    method(record, *args.sub_command["args"])
  File "/Users/bprieto/.pyenv/versions/3.9.10/lib/python3.9/site-packages/jamf/records.py", line 1321, in spreadsheet_print_during
    print(self.spreadsheet())
  File "/Users/bprieto/.pyenv/versions/3.9.10/lib/python3.9/site-packages/jamf/records.py", line 1342, in spreadsheet
    if self.data["general"]["trigger_logout"] == "true":
KeyError: 'trigger_logout'

I also tried without the search with the same result.

Errors when executing `jctl packages -S usage`

In limited testing, I’m observing the following errors when using jctl packages -S usage:

% sw_vers
ProductName:	macOS
ProductVersion:	11.6.1
BuildVersion:	20G224

% python3 --version
Python 3.10.0

% jctl patchsoftwaretitles -S patchpolicies 
…
Citrix Workspace
 Citrix Workspace Automatic
…
Microsoft Office 2019 (msupdate)
 Microsoft Office 2019 (msupdate) Beta Tester
 Microsoft Office 2019 (msupdate) Automatic
…
VMware Fusion 12
 VMware Fusion 12 Self Service
Zoom Client for Meetings
 Zoom Client for Meetings Beta Testers
 Zoom Client for Meetings Automatic
 Zoom Client for Meetings Self Service
…
Count: 31

% jctl packages -S usage 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/jctl", line 547, in <module>
    main(sys.argv[1:])
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/jctl", line 401, in main
    method(record, *args.sub_command['args'])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/jamf/records.py", line 1093, in usage_print_during
    related = self.related
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/jamf/records.py", line 1086, in related
    self.refresh_related()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/jamf/records.py", line 1075, in refresh_related
    if re.search(".pkg|.zip|.dmg", pkg[-4:]):
TypeError: 'NoneType' object is not subscriptable

Also …

% jctl policies -S spreadsheet > ~/Desktop/policies.csv
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/jctl", line 547, in <module>
    main(sys.argv[1:])
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/jctl", line 401, in main
    method(record, *args.sub_command['args'])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/jamf/records.py", line 1296, in spreadsheet_print_during
    print(self.spreadsheet())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/jamf/records.py", line 1317, in spreadsheet
    if self.data['general']['trigger_logout'] == "true":
KeyError: 'trigger_logout'

Same experience with Python 3.7.5:

% python3 --version                        
Python 3.7.5

% jctl packages -S usage                                          
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/jctl", line 547, in <module>
    main(sys.argv[1:])
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/jctl", line 401, in main
    method(record, *args.sub_command['args'])
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jamf/records.py", line 1093, in usage_print_during
    related = self.related
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jamf/records.py", line 1086, in related
    self.refresh_related()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jamf/records.py", line 1075, in refresh_related
    if re.search(".pkg|.zip|.dmg", pkg[-4:]):
TypeError: 'NoneType' object is not subscriptable

@uurazzle was able to duplicate.

Inconsistent use of `-d` for deletion

Thanks for creating python-jamf and jctl. I think these projects may be something I can build on for my organization.

I did notice that jctl -d deletes an object, while pkgctl -d sets patch definitions. Is it too late to make -d mean the same thing across both tools? The inconsistency increases the likelihood that somebody might inadvertently delete an object by calling the wrong tool (although the risk is lessened by the confirmation prompt).

Thanks for considering!

"Couldnt Save Changed Record"

image (20)

Get a weird error when trying to change the category for a mobile device app. Looks like a translation issue that is getting Latin-1 when expecting UTF-8.
App Name: Adobe Photoshop
Bundle ID: com.adobe.photoshop.ios
Category Name: Applications

Issue persistent in Terminal and CodeRunner text editor where default setting is UTF-8.

Failure message on successful -promote subcommand

After running the promote subcommand for a policy (e.g. GitHub Desktop) as a result I first get the picker, and then once a selection is made, the following:

{'package': [{'action': 'Install',
              'feu': 'false',
              'fut': 'false',
              'name': 'GitHubDesktop-M1-3.1.1.pkg'}],
 'size': '1'}
Sub command failed

What is puzzling here is that the promotion was in fact successful and my policy is updated, so the Sub command failed part is wrong or not clear.

Thanks.

conf-python-jamf not saving config

When attempting to setup jctl, running conf-python-jamf results in this error:

$ conf-python-jamf
Hostname (don't forget https:// and :8443): website
username: name
Password: 
Traceback (most recent call last):
  File "/Library/Python/3.7/site-packages/keyring/backends/macOS/__init__.py", line 41, in set_password
    api.set_generic_password(self.keychain, service, username, password)
  File "/Library/Python/3.7/site-packages/keyring/backends/macOS/api.py", line 161, in set_generic_password
    Error.raise_for_status(status)
  File "/Library/Python/3.7/site-packages/keyring/backends/macOS/api.py", line 114, in raise_for_status
    raise cls(status, "Unknown Error")
keyring.backends.macOS.api.Error: (-25308, 'Unknown Error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/conf-python-jamf", line 10, in <module>
    sys.exit(main())
  File "/Library/Python/3.7/site-packages/jamf/setconfig.py", line 119, in main
    setconfig(sys.argv[1:])
  File "/Library/Python/3.7/site-packages/jamf/setconfig.py", line 113, in setconfig
    conf.save(config_path=config_path)
  File "/Library/Python/3.7/site-packages/jamf/config.py", line 122, in save
    keyring.set_password(self.hostname, self.username, self.password)
  File "/Library/Python/3.7/site-packages/keyring/core.py", line 60, in set_password
    get_keyring().set_password(service_name, username, password)
  File "/Library/Python/3.7/site-packages/keyring/backends/macOS/__init__.py", line 45, in set_password
    raise PasswordSetError("Can't store password on keychain: " "{}".format(e))
keyring.errors.PasswordSetError: Can't store password on keychain: (-25308, 'Unknown Error')

While your document mentions support for python 3.7, after looking at keyring I tried updating to 3.8.10 but I am still getting the same error

jctl Version:

$ jctl --version
jctl 1.1.15
python_jamf 0.7.4 (0.6.9 required)

I also get a similar error with trying to set a plist:

$ conf-python-jamf -C ~/Library/Preferences/edu.utah.mlib.jamfutil.plist
Hostname (don't forget https:// and :8443): hs
username: a
Password: 
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keyring/backends/macOS/__init__.py", line 41, in set_password
    api.set_generic_password(self.keychain, service, username, password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keyring/backends/macOS/api.py", line 161, in set_generic_password
    Error.raise_for_status(status)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keyring/backends/macOS/api.py", line 114, in raise_for_status
    raise cls(status, "Unknown Error")
keyring.backends.macOS.api.Error: (-25308, 'Unknown Error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/bin/conf-python-jamf", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/jamf/setconfig.py", line 119, in main
    setconfig(sys.argv[1:])
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/jamf/setconfig.py", line 113, in setconfig
    conf.save(config_path=config_path)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/jamf/config.py", line 122, in save
    keyring.set_password(self.hostname, self.username, self.password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keyring/core.py", line 60, in set_password
    get_keyring().set_password(service_name, username, password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/keyring/backends/macOS/__init__.py", line 45, in set_password
    raise PasswordSetError("Can't store password on keychain: " "{}".format(e))
keyring.errors.PasswordSetError: Can't store password on keychain: (-25308, 'Unknown Error')

pkgctl - 10 Minute "Analyzing Jamf Data" Stage

We recently started using jctl and pkgctl with a Jamf hosted server and cloud distribution point. The primary computer is running macOS Monetary 12.6, but I have seen the same behavior on a clean machine running macOS Ventura 13.01 both from corporate and home networks.

jctl works without issue, but pkgctl consistently takes around 10 minutes to get beyond the "Analyzing Jamf Data" stage.

Initially pkgctl was failing more often than not with 502 errors and I assumed the excessive run times were related, but the 502 errors seem to have sorted themselves out (I have made no changes that I'm aware of that would explain this). Now the command is consistently successful but it predictably takes just over 10 minutes to return the initial results. Once this step is complete, I'm able to make changes and updates that go through instantaneously. I do not see the same delay with any jctl commands that I have used.

Any combination of arguments that trigger the "Analyzing Jamf Data" stage generate the same behavior (pkgctl, pkgctl -c, pkgctl -g, pkgctl -u, pkgctl -n, pkgctl -r, pkgctl -i).

pkgctl -p updates the patch definitions quickly, but returns "No packages match patch software titles", which is unexpected but I'm uncertain if this is related to the same issue.

Error for subcommands

Hey there,

I shared this in Slack, but I figured it would be better to have it here:

After running subcommands I get an error that says

Traceback (most recent call last):
  File "/Users/XXXX/.pyenv/versions/3.9.10/bin/jctl", line 593, in <module>
    main(sys.argv[1:])
  File "/Users/XXXX/.pyenv/versions/3.9.10/bin/jctl", line 371, in main
    print("Server: " + api.url)
AttributeError: 'API' object has no attribute 'url'

I made the subcommand work by manually editing line 371 in jctl and removing the call to api.url but I fear there might be something bigger in the background, so I guess it's worth checking.

Thanks!

"jctl computers -d -s general/last_contact_time~=2021" leads to ValueError

I'm trying to delete computers that did not contacted our Jamf Pro instance since 2020 and 2021. I'm running jctl 1.1.15 with python_jamf 0.7.4. In my case I could run the following line successfully;

jctl computers -d -s general/last_contact_time~=2021

But the following line exited with a ValueError:

jctl computers -d -s general/last_contact_time~=2020

Here's the stack trace;

Traceback (most recent call last): File "/usr/local/bin/jctl", line 559, in <module> main(sys.argv[1:]) File "/usr/local/bin/jctl", line 389, in main path_data = record.get_path(m[1]) File "/Library/Python/3.8/site-packages/jamf/records.py", line 508, in get_path self.refresh() File "/Library/Python/3.8/site-packages/jamf/records.py", line 449, in refresh results = self.api.get(end) File "/Library/Python/3.8/site-packages/jamf/api.py", line 193, in get self.set_session_auth() File "/Library/Python/3.8/site-packages/jamf/api.py", line 154, in set_session_auth deadline = datetime.strptime(expires.split('.')[0], '%Y-%m-%dT%H:%M:%S') File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/_strptime.py", line 568, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/_strptime.py", line 352, in _strptime raise ValueError("unconverted data remains: %s" % ValueError: unconverted data remains: Z

pkgctl crash during data read from server

Versions: pkgctl -v gives jctl 1.1.21 and python_jamf 0.9.0. macOS 14.2.1, Python 3.9.6 from macOS. Jamf Pro cloud server on 11.1.3

Traceback:
% ./pkgctl
Reading Jamf data (this could take several minutes, depending on the size of your data)
Warning Extra admins enabled specifies non-existant package: macautopkg
Traceback (most recent call last):
File "/Users/macautopkg/Library/Python/3.9/bin/./pkgctl", line 448, in
main(sys.argv[1:])
File "/Users/macautopkg/Library/Python/3.9/bin/./pkgctl", line 441, in main
interactive(all_packages)
File "/Users/macautopkg/Library/Python/3.9/bin/./pkgctl", line 377, in interactive
loadRelatedData(all_packages)
File "/Users/macautopkg/Library/Python/3.9/bin/./pkgctl", line 106, in loadRelatedData
record.related
File "/Users/macautopkg/Library/Python/3.9/lib/python/site-packages/python_jamf/records.py", line 1412, in related
self.refresh_related()
File "/Users/macautopkg/Library/Python/3.9/lib/python/site-packages/python_jamf/records.py", line 1406, in refresh_related
self.refresh_groups(related)
File "/Users/macautopkg/Library/Python/3.9/lib/python/site-packages/python_jamf/records.py", line 1379, in refresh_groups
criterions = jamf_record.get_path("criteria/criterion/value")
File "/Users/macautopkg/Library/Python/3.9/lib/python/site-packages/python_jamf/records.py", line 280, in get_path
result = self.get_path_worker(path.rstrip("/").split("/"), self.data)
File "/Users/macautopkg/Library/Python/3.9/lib/python/site-packages/python_jamf/records.py", line 253, in get_path_worker
raise JamfRecordInvalidPath
python_jamf.exceptions.JamfRecordInvalidPath

improved jctl error message

Change jctl output from

Please specify a record type:advancedcomputersearches, advancedmobiledevicesearches, advancedusersearches, buildings, byoprofiles, categories, classes, computerconfigurations, computerextensionattributes, computergroups, computerreports, computers, departments, directorybindings, diskencryptionconfigurations, distributionpoints, dockitems, ebooks, ibeacons, jsonwebtokenconfigurations, ldapservers, macapplications, managedpreferenceprofiles, mobiledeviceapplications, mobiledevicecommands, mobiledeviceconfigurationprofiles, mobiledeviceenrollmentprofiles, mobiledeviceextensionattributes, mobiledeviceinvitations, mobiledeviceprovisioningprofiles, mobiledevices, netbootservers, networksegments, osxconfigurationprofiles, packages, patchexternalsources, patchinternalsources, patchpolicies, patchsoftwaretitles, peripherals, peripheraltypes, policies, printers, removablemacaddresses, scripts, sites, softwareupdateservers, userextensionattributes, usergroups, users, vppaccounts, vppassignments, vppinvitations, webhooks

to

Please specify a record type:

  • advancedcomputersearches
  • advancedmobiledevicesearches
  • advancedusersearches
  • buildings
  • byoprofiles
  • categories
  • classes
  • computerconfigurations
  • computerextensionattributes
  • computergroups
  • computerreports
  • computers
  • departments
  • directorybindings
  • diskencryptionconfigurations
  • distributionpoints
  • dockitems
  • ebooks
  • ibeacons
  • jsonwebtokenconfigurations
  • ldapservers
  • macapplications
  • managedpreferenceprofiles
  • mobiledeviceapplications
  • mobiledevicecommands
  • mobiledeviceconfigurationprofiles
  • mobiledeviceenrollmentprofiles
  • mobiledeviceextensionattributes
  • mobiledeviceinvitations
  • mobiledeviceprovisioningprofiles
  • mobiledevices
  • netbootservers
  • networksegments
  • osxconfigurationprofiles
  • packages
  • patchexternalsources
  • patchinternalsources
  • patchpolicies
  • patchsoftwaretitles
  • peripherals
  • peripheraltypes
  • policies
  • printers
  • removablemacaddresses
  • scripts
  • sites
  • softwareupdateservers
  • userextensionattributes
  • usergroups
  • users
  • vppaccounts
  • vppassignments
  • vppinvitations
  • webhooks (edited)

Add Bearer Token Authentication

Hi:

Please add support to add bearer token authentication and provide backward compatibility with if use of Basic authentication is required (v10.34.0 and earlier).

Beginning in version 10.35.0 of Jamf Pro (scheduled for release in early January), the Classic API will now support Bearer Token authentication. This is the same authentication mechanism used by the Jamf Pro API, which brings further feature parity between our APIs as well as an added layer of security.

The 10.35.0 release of Jamf Pro will also include the deprecation of basic authentication via the Classic API which will be removed at a future time (estimated removal date: August-December 2022). Customers will have the ability to disable basic authentication before support is fully removed and we anticipate security conscientious customers will be eager to adopt these changes.

Jamf recommends providing backwards compatibility for your applications that interface with the Classic API. By implementing a version check of Jamf Pro, your application can determine whether Bearer Token authentication is supported (v10.35.0 or later) or if use of Basic authentication is required (v10.34.0 and earlier). The jamf-pro-version endpoint within the Jamf Pro API returns the version of the Jamf Pro Server, to help your application determine authentication compatibility with a given Jamf Pro Server. Jamf recommends including a preference to allow users to select the authentication schema based on their environment configuration or dynamically determining which authentication mechanism to use based on the Jamf Pro Server version.

Attempting to interact with a Jamf Pro environment that has disabled support for Basic authentication will result in a 401 Unauthorized response. It is also worth noting that this response is no different than the response received when using invalid credentials to interact with the Classic API via Basic authentication.

All existing integrations that leverage Jamf Pro’s Classic API will require an update to support bearer token authentication. More details regarding specific timelines will be communicated as they become available, but please plan for these changes to occur in 2022.

See the following Jamf web site for details:
https://developer.jamf.com/jamf-pro/docs/classic-api-authentication-changes

Variable not set before use in jctl 1.1.19

For jctl 1.1.19 with python-jamf 0.8.3 (but works with jctl 1.1.18 and the same python-jamf):

jctl patchsoftwaretitles -r Something -S set_all_packages

...
Count: 2
Traceback (most recent call last):
File "/Users/macautopkg/JCTL/jctl-git/jctl/./jctl", line 692, in
main(sys.argv[1:])
File "/Users/macautopkg/JCTL/jctl-git/jctl/./jctl", line 621, in main
confirmed = change_confirmation(args, rec_class, filtered_results)
File "/Users/macautopkg/JCTL/jctl-git/jctl/./jctl", line 475, in change_confirmation
f"Are you sure you want to {change_type_} "
UnboundLocalError: local variable 'change_type_' referenced before assignment

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.