Skip to content

Commit 5159cd2

Browse files
authored
Merge pull request #65 from univ-of-utah-marriott-library-apple/v0.7.3
v0.7.3, records.py: can create records with multiple args (patchpolic…
2 parents 63db5af + 519aa5b commit 5159cd2

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ build
1818
archive
1919
/jamf/VERSION
2020

21-
pref-*.plist
21+
prefs
2222
jctl
2323
pkgctl
24+
patch.py

jamf/records.py

+40-19
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ def __init__(self):
152152
"DirectoryBindings": post_template2,
153153
"Ebooks": post_template2,
154154
"JSONWebTokenConfigurations": post_template2,
155-
# 'LicensedSoftware': post_template2,
156-
# 'LDAPServers': post_template2,
155+
#"LicensedSoftware": post_template2,
156+
#"LDAPServers": post_template2,
157157
"MacApplications": post_template2,
158158
"ManagedPreferenceProfiles": post_template2,
159159
"MobileDevices": post_template2,
@@ -162,7 +162,6 @@ def __init__(self):
162162
"MobileDeviceEnrollmentProfiles": post_template2,
163163
"MobileDeviceProvisioningProfiles": post_template2,
164164
"OSXConfigurationProfiles": post_template2,
165-
"PatchPolicies": post_template2,
166165
"Peripherals": post_template2,
167166
"Policies": post_template2,
168167
"SoftwareUpdateServers": post_template2,
@@ -199,8 +198,11 @@ def __init__(self):
199198
"name": "%NAME%",
200199
"host_name": "example.com",
201200
},
202-
"PatchSoftwareTitles": {"name": "%NAME%", "source_id": "1"},
203-
# 'RestrictedSoftware': {'general':{'name':'%NAME%','process_name':'%NAME%'}},
201+
"PatchPolicies": {
202+
"general": {"name": "%NAME%", "target_version": "%VERSION%"}
203+
},
204+
"PatchSoftwareTitles": {"name_id": "%NAME%", "source_id": "1"},
205+
#"RestrictedSoftware": {"general":{"name":"%NAME%","process_name":"%NAME%"}},
204206
"UserGroups": {"general": {"name": "%NAME%"}, "is_smart": False},
205207
"WebHooks": {
206208
"event": "ComputerAdded",
@@ -359,7 +361,10 @@ def __new__(cls, *a, **kw):
359361
returns existing record if one has been instantiated
360362
"""
361363
jamf_id = int(a[0])
362-
name = a[1]
364+
if type(a[1]) is str:
365+
name = a[1]
366+
else:
367+
name = a[1][0]
363368
if not hasattr(cls, "_instances"):
364369
cls._instances = {}
365370
swag = ClassicSwagger()
@@ -376,11 +381,15 @@ def __new__(cls, *a, **kw):
376381
return None
377382
s1, s2, end = swag.swagger(plural, "s1, s2, end")
378383
if cls.plural_class == "PatchPolicies":
379-
print(
380-
"Use /patchpolicies/softwaretitleconfig/id/{softwaretitleconfigid}"
381-
" instead"
384+
if len(a[1]) < 3:
385+
raise Error(f"patchpolicies requires 3 args to create records")
386+
softwaretitleconfigid = a[1][1]
387+
end = f"patchpolicies/softwaretitleconfig/id/{softwaretitleconfigid}"
388+
out = {s1: swag.post_template(cls.plural_class, name)}
389+
t = out["patch_policy"]["general"]["target_version"]
390+
out["patch_policy"]["general"]["target_version"] = t.replace(
391+
"%VERSION%", a[1][2]
382392
)
383-
return None
384393
else:
385394
end = f"{end}0"
386395
out = {s1: swag.post_template(cls.plural_class, name)}
@@ -1158,15 +1167,6 @@ class PatchPolicy(Record):
11581167
def set_version_update_during(self, pkg_version):
11591168
change_made = False
11601169
cur_ver = self.data["general"]["target_version"]
1161-
1162-
#######################################################################
1163-
# If you don't delete the self_service_icon then it will error
1164-
# <Response [409]>: PUT - https://example.com:8443/JSSResource/patchpolicies/id/18:
1165-
# Conflict: Error: Problem with icon
1166-
# Couldn't save changed record: <Response [409]>
1167-
del self.data["user_interaction"]["self_service_icon"]
1168-
#######################################################################
1169-
11701170
if cur_ver != pkg_version:
11711171
print(f"Set version to {pkg_version}")
11721172
self.data["general"]["target_version"] = pkg_version
@@ -1175,6 +1175,15 @@ def set_version_update_during(self, pkg_version):
11751175
print(f"Version is already {pkg_version}")
11761176
return change_made
11771177

1178+
def save(self):
1179+
# If you don't delete the self_service_icon then it will error
1180+
# <Response [409]>: PUT - https://example.com:8443/JSSResource/patchpolicies/id/18:
1181+
# Conflict: Error: Problem with icon
1182+
# Couldn't save changed record: <Response [409]>
1183+
if "self_service_icon" in self.data["user_interaction"]:
1184+
del self.data["user_interaction"]["self_service_icon"]
1185+
return super().save()
1186+
11781187

11791188
class PatchPolicies(Records, metaclass=Singleton):
11801189
singular_class = PatchPolicy
@@ -1263,6 +1272,17 @@ def set_package_for_version_update_during(self, package, target_version):
12631272
change_made = True
12641273
return change_made
12651274

1275+
def versions_print_during(self):
1276+
print(self.name)
1277+
versions = self.data["versions"]["version"]
1278+
if not type(versions) is list:
1279+
versions = [versions]
1280+
for version in versions:
1281+
if version["package"] != None:
1282+
print(f" {version['software_version']}: {version['package']['name']}")
1283+
else:
1284+
print(f" {version['software_version']}: -")
1285+
12661286

12671287
class PatchSoftwareTitles(Records, metaclass=Singleton):
12681288
singular_class = PatchSoftwareTitle
@@ -1271,6 +1291,7 @@ class PatchSoftwareTitles(Records, metaclass=Singleton):
12711291
"packages": {"required_args": 0, "args_description": ""},
12721292
"set_package_for_version": {"required_args": 2, "args_description": ""},
12731293
"set_all_packages": {"required_args": 0, "args_description": ""},
1294+
"versions": {"required_args": 0, "args_description": ""},
12741295
}
12751296

12761297

0 commit comments

Comments
 (0)