Skip to content

Commit c668a2d

Browse files
authored
Merge pull request #56 from homebysix/pfm-names
v1.12.2 merge to main
2 parents 7d3cd42 + b8784ff commit c668a2d

7 files changed

Lines changed: 56 additions & 13 deletions

File tree

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
select = B,C,E,F,P,W,B9
3+
max-line-length = 88
4+
ignore = E127, E128, E203, E265, E266, E402, E501, E722, P207, P208, W503, F405, F403

.isort.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[settings]
2+
force_grid_wrap=0
3+
include_trailing_comma=True
4+
line_length=88
5+
multi_line_output=3
6+
use_parentheses=True

CHANGELOG.md

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

1515
Nothing yet.
1616

17+
## [1.12.2] - 2022-02-27
18+
19+
### Changed
20+
21+
- Adjusted preference manifest checks to require `pfm_name` for every preference key except immediate descendants of keys whose `pfm_type` is `array` (#54).
22+
- Improved preference manifest output to more accurately specify which key or subkey is failing `pfm_name` or `pfm_type` checks.
23+
- Continued development work on a hook that checks Jamf JSON schema manifests.
24+
1725
## [1.12.1] - 2021-12-22
1826

1927
### Changed

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.12.1
18+
rev: v1.12.2
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.12.1
124+
rev: v1.12.2
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.12.1
134+
rev: v1.12.2
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.12.1
146+
rev: v1.12.2
147147
hooks:
148148
- id: check-munki-pkgsinfo
149149
args: [

pre_commit_hooks/check_jamf_json_manifests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ def validate_default(name, property, type_found, filename):
140140
actual_type = str
141141
else:
142142
actual_type = type(property[test_key])
143-
if actual_type != PLIST_TYPES[type_found]:
143+
if actual_type != PLIST_TYPES.get(type_found):
144144
print(
145145
"{}: {} value for {} should be {}, not {}".format(
146146
filename,
147147
test_key,
148148
name,
149-
PLIST_TYPES[type_found],
149+
PLIST_TYPES.get(type_found),
150150
type(property[test_key]),
151151
)
152152
)

pre_commit_hooks/check_preference_manifests.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def validate_required_keys(input_dict, required_keys, dict_name, filename):
5252
def validate_manifest_key_types(manifest, filename):
5353
"""Validation of manifest key types."""
5454

55-
# manifest keys and their known types. Omitted keys are left unvalidated.
55+
# manifest keys and their known types. Omitted keys are left un-validated.
5656
# Last updated 2021-12-03.
5757
key_types = {
5858
"pfm_conditionals": list,
@@ -164,6 +164,23 @@ def validate_list_item_types(manifest, filename):
164164
return passed
165165

166166

167+
def validate_required_subkeys(subkey, req_keys, filename):
168+
"""Ensure specific keys are defined in subkeys."""
169+
passed = True
170+
171+
for subsubkey in subkey.get("pfm_subkeys", []):
172+
if subsubkey.get("pfm_name"):
173+
display_name = subsubkey["pfm_name"]
174+
elif subkey.get("pfm_name"):
175+
display_name = subkey["pfm_name"] + " subkey"
176+
else:
177+
display_name = "<unnamed key> subkey"
178+
if not validate_required_keys(subsubkey, req_keys, display_name, filename):
179+
passed = False
180+
181+
return passed
182+
183+
167184
def validate_pfm_type_strings(subkey, filename):
168185
"""Ensure subkey pfm_type strings are as expected."""
169186
passed = True
@@ -326,11 +343,19 @@ def validate_subkeys(subkeys, filename):
326343

327344
for subkey in subkeys:
328345

329-
# Check for presence of required keys.
330-
required_keys = ("pfm_type",)
331-
if not validate_required_keys(
332-
subkey, required_keys, subkey.get("pfm_name", "<unnamed key>"), filename
333-
):
346+
# Check for presence of required subkeys
347+
# (Not calling validate_required_keys() directly because the output would not be
348+
# specific enough to indicate *where* in the manifest the problem exists.)
349+
# Example of validate_required_keys() output:
350+
# menu.nomad.NoMADPro.plist: <unnamed key> missing required key pfm_type
351+
# Example of validate_required_subkeys() output:
352+
# menu.nomad.NoMADPro.plist: ChangePasswordItem subkey missing required key pfm_type
353+
if subkey["pfm_type"] != "array":
354+
# pfm_name is required only if the pfm_type is not array
355+
required_keys = ("pfm_type", "pfm_name")
356+
else:
357+
required_keys = ("pfm_type",)
358+
if not validate_required_subkeys(subkey, required_keys, filename):
334359
passed = False
335360
break # No need to continue checking this list of subkeys
336361

setup.py

Lines changed: 1 addition & 1 deletion
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.12.1",
10+
version="1.12.2",
1111
author="Elliot Jordan",
1212
author_email="elliot@elliotjordan.com",
1313
packages=["pre_commit_hooks"],

0 commit comments

Comments
 (0)