def _check_prefs_values(prefs_file_no_keychain, prefs_data): """ Check that the values in a JSSPrefs object instantiated using the file `test_prefs` match the values in `prefs_data` """ jss_prefs = jss.JSSPrefs(preferences_file=prefs_file_no_keychain) assert jss_prefs.user == prefs_data.get('jss_user') assert jss_prefs.url == prefs_data.get('jss_url') assert jss_prefs.password == prefs_data.get('jss_pass')
def main(argv=None, prefs_file=None): """ Main function """ options = _get_args(argv) prefs_file = prefs_file or options.prefs_file or find_prefs_file() target_type = set_mode(options) try: if options.no_keychain: jss_prefs = jss.JSSPrefs(preferences_file=prefs_file) else: # Use our subclass for keychain support jss_prefs = KJSSPrefs(preferences_file=prefs_file) except xml.parsers.expat.ExpatError as err: raise Git2JSSError("Preferences file {} invalid: {}".format( prefs_file, err)) # Create a new JSS object _jss = jss.JSS(jss_prefs) # If '--jss-info' was requested, just give the information if options.jss_info: print_jss_info(jss_prefs) sys.exit(0) _repo = GitRepo(tag=options.tag, branch=options.branch, sourcedir=options.local_repo) try: if options.push_all: files = list_matching_files(options.local_repo, pattern=r'.*\.(sh|py|pl)$') else: files = [options.source_file] for this_file in files: # Work out which type of processor to use processor_type = getattr(processors, target_type) # Instantiate the processor processor = processor_type(repo=_repo, _jss=_jss, source_file=this_file, target=options.target_name) processor.update() processor.save() finally: # Make sure the repo tmpdir is # cleaned up. _repo.__del__()
def test_jssprefs_no_repos(self): # Make sure that if you don't specify any repository information in # your preference file, everything still works correctly (just no # repos). Of course, needs a preferences file with no repos in it. no_repos_prefs = "com.github.sheagcraig.python-jss-no-repos.plist" if jss.is_osx(): pref_path = os.path.join("~/Library/Preferences", no_repos_prefs) elif jss.is_linux(): pref_path = os.path.join("~", "." + no_repos_prefs) else: raise Exception("Unknown/unsupported OS.") jssPrefs = jss.JSSPrefs(pref_path) assert_is_instance(jssPrefs, jss.JSSPrefs)
def setup(cls, args=None): """Set up the jss connection class variable. Each client that imports jss_connection.JSSConnection has its own class variables. This function will configure properties on the current namespace's JSSConnection prior to use. Args: args: Argparser namespace with properties: ssl: (Bool) Verify SSL traffic. verbose: (Bool) Verbose output. """ cls._jss_prefs = jss.JSSPrefs() cls._jss = jss.JSS(jss_prefs=cls._jss_prefs) if args: args_dict = vars(args) if "ssl" in args_dict: cls._jss.session.verify = args.ssl if "verbose" in args_dict: cls._jss.verbose = args.verbose
#!/usr/bin/env python """Tests for distribution points. These tests will FAIL! A few of the tests assert values local to my institution. Edit them to work in your environment, or find a better way to do it and send me an email! """ from nose.tools import * import os import jss global j_global jp = jss.JSSPrefs() j_global = jss.JSS(jss_prefs=jp) class TestJSSPrefs(object): def test_jssprefs_no_repos(self): # Make sure that if you don't specify any repository information in # your preference file, everything still works correctly (just no # repos). Of course, needs a preferences file with no repos in it. no_repos_prefs = "com.github.sheagcraig.python-jss-no-repos.plist" if jss.is_osx(): pref_path = os.path.join("~/Library/Preferences", no_repos_prefs) elif jss.is_linux(): pref_path = os.path.join("~", "." + no_repos_prefs) else: raise Exception("Unknown/unsupported OS.") jssPrefs = jss.JSSPrefs(pref_path)
import random import string import sys import jss try: USER = sys.argv[1] ATTR = sys.argv[2] except IndexError: print "Usage: {} username attributename".format(sys.argv[0]) print "Use this script to test whether it's possible to modify a User Extension Attribute on a JSS" print "User <username> should have <attributename> set to some value that you don't mind losing" print "WARNING: we will not set the value back to what it was before!" sys.exit(255) jss_prefs = jss.JSSPrefs() j = jss.JSS(jss_prefs) user = j.User(USER) print "Testing Extension Attribute {} on user {}".format(ATTR, USER) print "Using JSS at ", j.base_url init_val = user.find( ".//extension_attribute[name='{}']/value".format(ATTR)).text print "Initial value is: ", init_val newval = ''.join( random.choice(string.ascii_letters + string.digits) for _ in range(5)) print "Trying to change value to: ", newval
def make_selection(): selected = raw_input("Select release channel to switch to: ") try: selected = int(selected) except ValueError: print "Select from the options above." return make_selection() if selected < 1 or selected > len(CHANNELS): print "Select from the options above." return make_selection() return selected j = jss.JSS(jss.JSSPrefs()) udid = subprocess.check_output( "system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }'", shell=True) for num, channel in enumerate(CHANNELS, 1): print '{}. {}'.format(num, channel) selected = make_selection() new_channel = CHANNELS[selected - 1] c = j.Computer('udid=%s' % udid) v = c.find('extension_attributes/extension_attribute/[id="%s"]/value' % EXT_ATTR) old_channel = v.text v.text = new_channel
if args.verbose > 0: print "Attempting to connect to Postgres Database..." try: conn = psycopg2.connect( host=accessPreferences['postgres_host'], dbname=accessPreferences['postgres_db'], user=accessPreferences['postgres_user'], password=accessPreferences['postgres_password']) except psycopg2.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) sys.exit(1) if args.verbose > 0: print "Attempting to connect to JSS..." try: jss_prefs = jss.JSSPrefs(jssprefs_file) j = jss.JSS(jss_prefs) except: print "Couldn't access JSS preferences file." sys.exit(1) if args.verbose > 0: print "Attempting to create database table..." CreateCasperImportTable(conn) if args.verbose > 0: print "Attempting to access JSS device list..." deviceList = j.MobileDevice()