Skip to content

Commit e260d1d

Browse files
committed
Add check for deprecated pkginfo keys, expand typo checks
1 parent beedf3f commit e260d1d

File tree

4 files changed

+80
-35
lines changed

4 files changed

+80
-35
lines changed

CHANGELOG.md

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

1717
- `check-munki-pkgsinfo` now produces an error if `uninstall_method` is set to `uninstall_script` but no uninstall script is present in the pkginfo.
18+
- `check-munki-pkgsinfo` now checks for deprecated pkginfo keys.
19+
- `check-munki-pkgsinfo` now includes checks for many possible pkginfo key typos, not just `minimum_os_version` and `maximum_os_version`. Suggestions welcome if you think of more.
1820
- `check-munkiadmin-scripts` now checks whether scripts are named correctly, not just executable.
1921

2022
## [1.17.0] - 2024-12-22

pre_commit_hooks/check_autopkg_recipes.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from packaging.version import Version
1111

1212
from pre_commit_hooks.util import (
13+
detect_deprecated_keys,
14+
detect_typoed_keys,
1315
load_autopkg_recipe,
1416
validate_pkginfo_key_types,
1517
validate_required_keys,
@@ -611,24 +613,10 @@ def main(argv=None):
611613
retval = 1
612614
if not validate_restart_action_key(input_key["pkginfo"], filename):
613615
retval = 1
614-
615-
# Check for common mistakes in min/max OS version keys
616-
os_vers_corrections = {
617-
"min_os": "minimum_os_version",
618-
"max_os": "maximum_os_version",
619-
"min_os_vers": "minimum_os_version",
620-
"max_os_vers": "maximum_os_version",
621-
"minimum_os": "minimum_os_version",
622-
"maximum_os": "maximum_os_version",
623-
"minimum_os_vers": "minimum_os_version",
624-
"maximum_os_vers": "maximum_os_version",
625-
}
626-
for os_vers_key in os_vers_corrections:
627-
if os_vers_key in input_key["pkginfo"]:
628-
print(
629-
f"{filename}: You used {os_vers_key} when you probably meant {os_vers_corrections[os_vers_key]}."
630-
)
631-
retval = 1
616+
if not detect_deprecated_keys(input_key["pkginfo"], filename):
617+
retval = 1
618+
if not detect_typoed_keys(input_key["pkginfo"], filename):
619+
retval = 1
632620

633621
# TODO: Additional pkginfo checks here.
634622

pre_commit_hooks/check_munki_pkgsinfo.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from xml.parsers.expat import ExpatError
99

1010
from pre_commit_hooks.util import (
11+
detect_deprecated_keys,
12+
detect_typoed_keys,
1113
validate_pkginfo_key_types,
1214
validate_required_keys,
1315
validate_restart_action_key,
@@ -114,23 +116,13 @@ def main(argv=None):
114116
if not validate_restart_action_key(pkginfo, filename):
115117
retval = 1
116118

117-
# Check for common mistakes in min/max OS version keys.
118-
os_vers_corrections = {
119-
"min_os": "minimum_os_version",
120-
"max_os": "maximum_os_version",
121-
"min_os_vers": "minimum_os_version",
122-
"max_os_vers": "maximum_os_version",
123-
"minimum_os": "minimum_os_version",
124-
"maximum_os": "maximum_os_version",
125-
"minimum_os_vers": "minimum_os_version",
126-
"maximum_os_vers": "maximum_os_version",
127-
}
128-
for os_vers_key in os_vers_corrections:
129-
if os_vers_key in pkginfo:
130-
print(
131-
f"{filename}: You used {os_vers_key} when you probably meant {os_vers_corrections[os_vers_key]}."
132-
)
133-
retval = 1
119+
# Check for deprecated pkginfo keys.
120+
if not detect_deprecated_keys(pkginfo, filename):
121+
retval = 1
122+
123+
# Check for common mistakes key names.
124+
if not detect_typoed_keys(pkginfo, filename):
125+
retval = 1
134126

135127
# Check for rogue categories.
136128
if args.categories and pkginfo.get("category") not in args.categories:

pre_commit_hooks/util.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,69 @@ def validate_required_keys(input_dict, filename, required_keys):
7777
return passed
7878

7979

80+
def detect_deprecated_keys(input_dict, filename):
81+
"""Verifies that no deprecated keys are present in dictionary."""
82+
# List from: https://github.com/munki/munki/wiki/Supported-Pkginfo-Keys
83+
deprecated_keys = (
84+
"suppress_bundle_relocation",
85+
"forced_install",
86+
"forced_uninstall",
87+
)
88+
passed = True
89+
for dep_key in deprecated_keys:
90+
if input_dict.get(dep_key):
91+
print(f"{filename}: {dep_key} key is deprecated")
92+
passed = False
93+
return passed
94+
95+
96+
def detect_typoed_keys(input_dict, filename):
97+
"""Verifies that specific key name typos are not present in dictionary."""
98+
key_corrections = {
99+
"appleitem": "apple_item",
100+
"blocking_apps": "blocking_applications",
101+
"blockingapplications": "blocking_applications",
102+
"choices_xml": "installer_choices_xml",
103+
"icon": "icon_name",
104+
"install_check_script": "installcheck_script",
105+
"installer_choices": "installer_choices_xml",
106+
"max_os_vers": "maximum_os_version",
107+
"max_os": "maximum_os_version",
108+
"maximum_os_vers": "maximum_os_version",
109+
"maximum_os": "maximum_os_version",
110+
"min_munki_vers": "minimum_munki_version",
111+
"min_munki": "minimum_munki_version",
112+
"min_os_vers": "minimum_os_version",
113+
"min_os": "minimum_os_version",
114+
"minimum_munki_vers": "minimum_munki_version",
115+
"minimum_munki": "minimum_munki_version",
116+
"minimum_os_vers": "minimum_os_version",
117+
"minimum_os": "minimum_os_version",
118+
"on_demand": "OnDemand",
119+
"post_install_script": "postinstall_script",
120+
"post_uninstall_script": "postuninstall_script",
121+
"pre_cache": "precache",
122+
"pre_install_alert": "preinstall_alert",
123+
"pre_install_script": "preinstall_script",
124+
"pre_uninstall_alert": "preuninstall_alert",
125+
"pre_uninstall_script": "preuninstall_script",
126+
"pre_upgrade_alert": "preupgrade_alert",
127+
"receipt": "receipts",
128+
"require": "requires",
129+
"supported_architecture": "supported_architectures",
130+
"uninstall_check_script": "uninstallcheck_script",
131+
}
132+
passed = True
133+
for found_key, expected_key in key_corrections.items():
134+
if found_key in input_dict:
135+
print(
136+
f"{filename}: You used {found_key} when you "
137+
f"probably meant {expected_key}."
138+
)
139+
passed = False
140+
return passed
141+
142+
80143
def validate_restart_action_key(pkginfo, filename):
81144
"""Verifies that required_keys are present in pkginfo dictionary."""
82145
passed = True

0 commit comments

Comments
 (0)