jssimporter / JSSImporter

JSSImporter is deprecated. Please see the wiki for alternatives
Apache License 2.0
145 stars 38 forks source link

policy_category cannot include ampersands #160

Closed grahampugh closed 4 years ago

grahampugh commented 5 years ago

If the policy_category variable contains an ampersand, e.g. Science & Math, a policy will fail. However, this is not the case with the category variable, which adds a category to a package object.

(for the record, the category in XML would be Science & Math)

grahampugh commented 5 years ago

Struggling to figure this out. I've attempted to recreate the basic functions of JSSImporter to understand the process better, using the following script:

#!/usr/bin/python

import sys
from xml.etree import ElementTree

sys.path.insert(0, '/Library/Application Support/JSSImporter')

import jss

jss_prefs = jss.JSSPrefs()
j = jss.JSS(jss_prefs)

# get category from a template XML
final_template_path = '/path/to/functioning/policy.xml'
with open(final_template_path, "r") as template_file:
    text = template_file.read()
obj_cls = jss.Policy
recipe_object = obj_cls.from_string(jss, text)
print('Template policy: {}'.format(recipe_object.name))
print('Template category: {}'.format(recipe_object.general.category.name.text))

# Check for an existing object with this name.
existing_object = None
try:
    existing_object = j.Policy(recipe_object.name)
    print('Existing policy: {}: {}'.format(existing_object.id, existing_object.name))
    new_id = existing_object.id
except jss.GetError:
    pass

if existing_object is not None:
    recipe_object._basic_identity["id"] = new_id
recipe_object.save()

However, when I run the script, I get an error:

AttributeError: 'module' object has no attribute 'put'

If I simply execute existing_object.save() in the same script, it saves the existing policy. So I'm missing something about creating a new policy object from a template and writing it to an existing policy on the JSS, even though I seem to be replicating what JSSImporter does as closely as possible.

I could be writing to the wind here since there aren't many developers left, but if anyone has an idea how to progress, I would be grateful! ( @sheagcraig @mosen ).

grahampugh commented 4 years ago

Solved with #161