Skip to content

Commit 485a0ca

Browse files
authored
Merge pull request #50 from homebysix/profile-manifests
Add check-preference-manifests hook, and prepare check-jamf-json-manifests hook for future development
2 parents 174898c + ab21865 commit 485a0ca

8 files changed

Lines changed: 792 additions & 24 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
files: '(jamf|jss)/extension.?attributes/.*\.(sh|bash|py|rb|js|pl)$'
3333
types: [text]
3434

35-
- id: check-jamf-scripts
36-
name: Check Jamf Scripts
37-
description: This hook checks Jamf scripts for common issues.
38-
entry: check-jamf-scripts
39-
language: python
40-
# Switch from files regex to "OR" types when that feature is available:
41-
# https://github.com/pre-commit/pre-commit/issues/607
42-
files: '(jamf|jss)/scripts/.*\.(sh|bash|py|rb|js|pl)$'
43-
types: [text]
35+
# WORK IN PROGRESS
36+
# - id: check-jamf-json-manifests
37+
# name: Check Jamf JSON Manifests
38+
# description: This hook checks Jamf JSON manifests for inconsistencies and common issues.
39+
# entry: check-jamf-json-manifests
40+
# language: python
41+
# files: '\.json$'
42+
# types: [text]
4443

4544
- id: check-jamf-profiles
4645
name: Check Jamf Profiles
@@ -52,20 +51,30 @@
5251
files: '(jamf|jss)/profiles/.*\.(mobileconfig|plist)$'
5352
types: [text]
5453

54+
- id: check-jamf-scripts
55+
name: Check Jamf Scripts
56+
description: This hook checks Jamf scripts for common issues.
57+
entry: check-jamf-scripts
58+
language: python
59+
# Switch from files regex to "OR" types when that feature is available:
60+
# https://github.com/pre-commit/pre-commit/issues/607
61+
files: '(jamf|jss)/scripts/.*\.(sh|bash|py|rb|js|pl)$'
62+
types: [text]
63+
5564
- id: check-munki-pkgsinfo
5665
name: Check Munki Pkginfo Files
5766
description: This hook checks Munki pkginfo files to ensure they are valid.
5867
entry: check-munki-pkgsinfo
5968
language: python
60-
files: '^pkgsinfo/'
69+
files: "^pkgsinfo/"
6170
types: [text]
6271

6372
- id: check-munkiadmin-scripts
6473
name: Check MunkiAdmin Scripts
6574
description: This hook ensures MunkiAdmin scripts are executable.
6675
entry: check-munkiadmin-scripts
6776
language: python
68-
files: '^MunkiAdmin/scripts/'
77+
files: "^MunkiAdmin/scripts/"
6978
types: [text]
7079

7180
- id: check-munkipkg-buildinfo
@@ -81,7 +90,7 @@
8190
description: This hook checks Outset scripts to ensure they're executable.
8291
entry: check-outset-scripts
8392
language: python
84-
files: 'usr/local/outset/(boot-once|boot-every|login-once|login-every|login-privileged-once|login-privileged-every|on-demand)/'
93+
files: "usr/local/outset/(boot-once|boot-every|login-once|login-every|login-privileged-once|login-privileged-every|on-demand)/"
8594
types: [text]
8695

8796
- id: check-plists
@@ -92,6 +101,14 @@
92101
files: '\.(plist|recipe|mobileconfig|pkginfo)$'
93102
types: [text]
94103

104+
- id: check-preference-manifests
105+
name: Check Apple Preference Manifests
106+
description: This hook checks preference manifest plists for inconsistencies and common issues.
107+
entry: check-preference-manifests
108+
language: python
109+
files: '\.plist$'
110+
types: [text]
111+
95112
- id: forbid-autopkg-overrides
96113
name: Forbid AutoPkg Overrides
97114
description: This hook prevents AutoPkg overrides from being added to the repo.

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ All notable changes to this project will be documented in this file. This projec
1414

1515
Nothing yet.
1616

17+
## [1.12.0] - 2021-12-19
18+
19+
### Added
20+
21+
- New `check-preference-manifests` hook for checking Apple preference manifests like those used by ProfileCreator and iMazing Profile Editor [manifests](https://github.com/ProfileCreator/ProfileManifests).
22+
- Check for the [recommended order](https://youtu.be/srz4U9RHliQ?list=PLlxHm_Px-Ie1EIRlDHG2lW5H7c2UYvops&t=1010) of JamfUploader processors.
23+
1724
## [1.11.0] - 2021-11-20
1825

1926
### Added
@@ -262,7 +269,8 @@ Nothing yet.
262269

263270
- Initial release
264271

265-
[Unreleased]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.11.0...HEAD
272+
[Unreleased]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.12.0...HEAD
273+
[1.12.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.11.0...v1.12.0
266274
[1.11.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.10.1...v1.11.0
267275
[1.10.1]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.9.0...v1.10.1
268276
[1.9.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.8.2...v1.9.0

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For any hook in this repo you wish to use, add the following to your pre-commit
1515

1616
```yaml
1717
- repo: https://github.com/homebysix/pre-commit-macadmin
18-
rev: v1.11.0
18+
rev: v1.12.0
1919
hooks:
2020
- id: check-plists
2121
# - id: ...
@@ -121,7 +121,7 @@ When combining arguments that take lists (for example: `--required-keys`, `--cat
121121

122122
```yaml
123123
- repo: https://github.com/homebysix/pre-commit-macadmin
124-
rev: v1.11.0
124+
rev: v1.12.0
125125
hooks:
126126
- id: check-munki-pkgsinfo
127127
args: ['--catalogs', 'testing', 'stable', '--']
@@ -131,7 +131,7 @@ But if you also use the `--categories` argument, you would move the trailing `--
131131

132132
```yaml
133133
- repo: https://github.com/homebysix/pre-commit-macadmin
134-
rev: v1.11.0
134+
rev: v1.12.0
135135
hooks:
136136
- id: check-munki-pkgsinfo
137137
args: ['--catalogs', 'testing', 'stable', '--categories', 'Design', 'Engineering', 'Web Browsers', '--']
@@ -143,7 +143,7 @@ If it looks better to your eye, feel free to use a multi-line list for long argu
143143

144144
```yaml
145145
- repo: https://github.com/homebysix/pre-commit-macadmin
146-
rev: v1.11.0
146+
rev: v1.12.0
147147
hooks:
148148
- id: check-munki-pkgsinfo
149149
args: [

pre_commit_hooks/check_autopkg_recipes.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,46 @@ def validate_no_superclass_procs(process, filename):
279279
return passed
280280

281281

282+
def validate_jamf_processor_order(process, filename):
283+
"""Warn if JamfUploader processors are not in their conventional order.
284+
https://youtu.be/srz4U9RHliQ?list=PLlxHm_Px-Ie1EIRlDHG2lW5H7c2UYvops&t=1010
285+
"""
286+
287+
# Recommended order of Jamf processors
288+
rec_order = (
289+
"com.github.grahampugh.jamf-upload.processors/JamfCategoryUploader",
290+
"com.github.grahampugh.jamf-upload.processors/JamfExtensionAttributeUploader",
291+
"com.github.grahampugh.jamf-upload.processors/JamfPackageUploader",
292+
"com.github.grahampugh.jamf-upload.processors/JamfScriptUploader",
293+
"com.github.grahampugh.jamf-upload.processors/JamfComputerGroupUploader",
294+
# TODO: The three below may depend on computer groups, but there's no
295+
# easy way to ignore relative order if multiple are used. Focusing on
296+
# JamfPolicyUploader only for now.
297+
"com.github.grahampugh.jamf-upload.processors/JamfPolicyUploader",
298+
# "com.github.grahampugh.jamf-upload.processors/JamfComputerProfileUploader",
299+
# "com.github.grahampugh.jamf-upload.processors/JamfSoftwareRestrictionUploader",
300+
)
301+
302+
passed = True
303+
# All JamfUploader processors in recipe, ignoring duplicates, preserving order.
304+
actual_order = list(
305+
dict.fromkeys(
306+
[x.get("Processor") for x in process if x.get("Processor") in rec_order]
307+
)
308+
)
309+
desired_order = [x for x in rec_order if x in actual_order]
310+
if desired_order != actual_order:
311+
print(
312+
"{}: WARNING: JamfUploader processors are not in "
313+
"the recommended order: {}.".format(
314+
filename,
315+
", ".join([x.split("/")[-1] for x in desired_order]),
316+
)
317+
)
318+
319+
return passed
320+
321+
282322
# def validate_unused_input_vars(recipe, recipe_text, filename):
283323
# """Warn if any input variables are not referenced in the recipe."""
284324

@@ -367,7 +407,6 @@ def validate_proc_type_conventions(process, filename):
367407
"com.github.grahampugh.jamf-upload.processors/JamfPolicyUploader",
368408
"com.github.grahampugh.jamf-upload.processors/JamfScriptUploader",
369409
"com.github.grahampugh.jamf-upload.processors/JamfSoftwareRestrictionUploader",
370-
"com.github.grahampugh.jamf-upload.processors/JamfUploaderSlacker",
371410
],
372411
# https://github.com/autopkg/filewave
373412
"filewave": ["FileWaveImporter"],
@@ -610,6 +649,9 @@ def main(argv=None):
610649
if not validate_no_superclass_procs(process, filename):
611650
retval = 1
612651

652+
if not validate_jamf_processor_order(process, filename):
653+
retval = 1
654+
613655
if HAS_AUTOPKGLIB:
614656
if not validate_proc_args(process, filename):
615657
retval = 1

0 commit comments

Comments
 (0)