Skip to content

Commit 400d052

Browse files
committed
Bump to next major version and add profile manifest hooks
1 parent ffe2db5 commit 400d052

6 files changed

Lines changed: 166 additions & 16 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
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
35+
- id: check-jamf-json-schemas
36+
name: Check Jamf JSON Schemas
37+
description: This hook checks Jamf JSON schemas for inconsistencies and common issues.
38+
entry: check-jamf-json-schemas
3939
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)$'
40+
files: '\.json$'
4341
types: [text]
4442

4543
- id: check-jamf-profiles
@@ -52,20 +50,30 @@
5250
files: '(jamf|jss)/profiles/.*\.(mobileconfig|plist)$'
5351
types: [text]
5452

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

6371
- id: check-munkiadmin-scripts
6472
name: Check MunkiAdmin Scripts
6573
description: This hook ensures MunkiAdmin scripts are executable.
6674
entry: check-munkiadmin-scripts
6775
language: python
68-
files: '^MunkiAdmin/scripts/'
76+
files: "^MunkiAdmin/scripts/"
6977
types: [text]
7078

7179
- id: check-munkipkg-buildinfo
@@ -81,7 +89,7 @@
8189
description: This hook checks Outset scripts to ensure they're executable.
8290
entry: check-outset-scripts
8391
language: python
84-
files: 'usr/local/outset/(boot-once|boot-every|login-once|login-every|login-privileged-once|login-privileged-every|on-demand)/'
92+
files: "usr/local/outset/(boot-once|boot-every|login-once|login-every|login-privileged-once|login-privileged-every|on-demand)/"
8593
types: [text]
8694

8795
- id: check-plists
@@ -92,6 +100,14 @@
92100
files: '\.(plist|recipe|mobileconfig|pkginfo)$'
93101
types: [text]
94102

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

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ All notable changes to this project will be documented in this file. This projec
1414

1515
### Added
1616

17+
- New `check-jamf-json-schemas` hook for checking [Jamf JSON schemas](https://docs.jamf.com/technical-papers/jamf-pro/json-schema/10.19.0/Introduction.html) for management of app settings.
18+
- New `check-profilecreator-manifests` hook for checking ProfileCreator and iMazing Profile Editor [manifest plists](https://github.com/ProfileCreator/ProfileManifests).
1719
- Check for the [recommended order](https://youtu.be/srz4U9RHliQ?list=PLlxHm_Px-Ie1EIRlDHG2lW5H7c2UYvops&t=1010) of JamfUploader processors.
1820

1921
## [1.11.0] - 2021-11-20

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.1
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.1
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.1
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.1
146+
rev: v1.12.0
147147
hooks:
148148
- id: check-munki-pkgsinfo
149149
args: [
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
"""This hook checks Jamf JSON schemas for inconsistencies and common issues."""
4+
5+
import argparse
6+
import json
7+
8+
9+
def build_argument_parser():
10+
"""Build and return the argument parser."""
11+
12+
parser = argparse.ArgumentParser(
13+
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
14+
)
15+
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
16+
return parser
17+
18+
19+
def main(argv=None):
20+
"""Main process."""
21+
22+
# Parse command line arguments.
23+
argparser = build_argument_parser()
24+
args = argparser.parse_args(argv)
25+
26+
retval = 0
27+
for filename in args.filenames:
28+
try:
29+
with open(filename, "rb") as openfile:
30+
schema = json.load(openfile)
31+
except Exception as err:
32+
print("{}: json parsing error: {}".format(filename, err))
33+
retval = 1
34+
35+
return retval
36+
37+
38+
if __name__ == "__main__":
39+
exit(main())
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
"""This hook checks ProfileCreator manifest plists for inconsistencies and common issues."""
4+
5+
import argparse
6+
import plistlib
7+
import sys
8+
from datetime import datetime
9+
from xml.parsers.expat import ExpatError
10+
11+
from pre_commit_hooks.util import validate_required_keys
12+
13+
14+
def build_argument_parser():
15+
"""Build and return the argument parser."""
16+
17+
parser = argparse.ArgumentParser(
18+
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
19+
)
20+
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
21+
return parser
22+
23+
24+
def validate_manifest_key_types(manifest, filename):
25+
"""Validation of manifest key types.
26+
27+
Used for AutoPkg- and Munki-related hooks.
28+
"""
29+
30+
# Remap string type to support unicode in both Python 2 and 3
31+
string = basestring if sys.version_info.major == 2 else str
32+
33+
# manifest keys and their known types. Omitted keys are left unvalidated.
34+
# Last updated 2021-12-03.
35+
key_types = {
36+
"pfm_description_reference": string,
37+
"pfm_description": string,
38+
"pfm_domain": string,
39+
"pfm_format_version": int,
40+
"pfm_format": string,
41+
"pfm_last_modified": datetime,
42+
"pfm_name": string,
43+
"pfm_note": string,
44+
"pfm_platforms": list,
45+
"pfm_require": string,
46+
"pfm_subkeys": list,
47+
"pfm_targets": list,
48+
"pfm_title": string,
49+
"pfm_type": string,
50+
"pfm_unique": bool,
51+
"pfm_version": int,
52+
}
53+
54+
passed = True
55+
for manifest_key, expected_type in key_types.items():
56+
if manifest_key in manifest:
57+
if not isinstance(manifest[manifest_key], expected_type):
58+
print(
59+
"{}: manifest key {} should be type {}, not type {}".format(
60+
filename,
61+
manifest_key,
62+
expected_type,
63+
type(manifest[manifest_key]),
64+
)
65+
)
66+
passed = False
67+
68+
return passed
69+
70+
71+
def main(argv=None):
72+
"""Main process."""
73+
74+
# Parse command line arguments.
75+
argparser = build_argument_parser()
76+
args = argparser.parse_args(argv)
77+
78+
retval = 0
79+
for filename in args.filenames:
80+
try:
81+
with open(filename, "rb") as openfile:
82+
manifest = plistlib.load(openfile)
83+
except (ExpatError, ValueError) as err:
84+
print("{}: plist parsing error: {}".format(filename, err))
85+
retval = 1
86+
87+
return retval
88+
89+
90+
if __name__ == "__main__":
91+
exit(main())

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
name="pre-commit-macadmin",
88
description="Pre-commit hooks for Mac admins, client engineers, and IT consultants.",
99
url="https://github.com/homebysix/pre-commit-macadmin",
10-
version="1.11.1",
10+
version="1.12.0",
1111
author="Elliot Jordan",
1212
author_email="elliot@elliotjordan.com",
1313
packages=["pre_commit_hooks"],
@@ -18,13 +18,15 @@
1818
"check-autopkg-recipes = pre_commit_hooks.check_autopkg_recipes:main",
1919
"check-git-config-email = pre_commit_hooks.check_git_config_email:main",
2020
"check-jamf-extension-attributes = pre_commit_hooks.check_jamf_extension_attributes:main",
21-
"check-jamf-scripts = pre_commit_hooks.check_jamf_scripts:main",
21+
"check-jamf-json-schemas = pre_commit_hooks.check_jamf_json_schemas:main",
2222
"check-jamf-profiles = pre_commit_hooks.check_jamf_profiles:main",
23+
"check-jamf-scripts = pre_commit_hooks.check_jamf_scripts:main",
2324
"check-munki-pkgsinfo = pre_commit_hooks.check_munki_pkgsinfo:main",
2425
"check-munkiadmin-scripts = pre_commit_hooks.check_munkiadmin_scripts:main",
2526
"check-munkipkg-buildinfo = pre_commit_hooks.check_munkipkg_buildinfo:main",
2627
"check-outset-scripts = pre_commit_hooks.check_outset_scripts:main",
2728
"check-plists = pre_commit_hooks.check_plists:main",
29+
"check-profilecreator-manifests = pre_commit_hooks.check_profilecreator_manifests:main",
2830
"forbid-autopkg-overrides = pre_commit_hooks.forbid_autopkg_overrides:main",
2931
"forbid-autopkg-trust-info = pre_commit_hooks.forbid_autopkg_trust_info:main",
3032
"munki-makecatalogs = pre_commit_hooks.munki_makecatalogs:main",

0 commit comments

Comments
 (0)