Skip to content

Commit

Permalink
Merge pull request #13 from homebysix/1.0.4
Browse files Browse the repository at this point in the history
Add check for approved catalogs
  • Loading branch information
homebysix authored Mar 14, 2019
2 parents 16c996b + 86afee2 commit 6348f60
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For any hook in this repo you wish to use, add the following to your pre-commit

```
- repo: https://github.com/homebysix/pre-commit-macadmin
rev: v1.0.0
rev: v1.0.4
hooks:
- id: check-plists
# - id: ...
Expand Down Expand Up @@ -63,6 +63,8 @@ For any hook in this repo you wish to use, add the following to your pre-commit

This hook checks Munki pkginfo files to ensure they are valid.

- Specify your preferred list of pkginfo catalogs, if you wish to enforce it:
`[--catalogs, testing, stable]`
- Specify your preferred list of pkginfo categories, if you wish to enforce it:
`[--categories, Productivity, Design, Utilities, 'Web Browsers']`
- Specify required pkginfo keys:
Expand Down
12 changes: 12 additions & 0 deletions pre_commit_hooks/check_munki_pkgsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def build_argument_parser():
)
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
parser.add_argument("--categories", nargs="+", help="List of approved categories.")
parser.add_argument("--catalogs", nargs="+", help="List of approved catalogs.")
parser.add_argument(
"--required-keys",
nargs="+",
Expand Down Expand Up @@ -68,6 +69,17 @@ def main(argv=None):
)
retval = 1

# Check for rogue catalogs.
if args.catalogs:
for catalog in pkginfo.get("catalogs"):
if catalog not in args.catalogs:
print(
'{}: catalog "{}" is not in approved list'.format(
filename, catalog
)
)
retval = 1

# Check for pkg filenames showing signs of duplicate imports.
if pkginfo.get("installer_item_location", "").endswith(tuple(dupe_suffixes)):
print(
Expand Down
2 changes: 1 addition & 1 deletion pre_commit_hooks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def validate_pkginfo_key_types(pkginfo, filename):
"""Main process."""
"""Validation of pkginfo key types. Used for AutoPkg- and Munki-related hooks."""

# Pkginfo keys and their known types. Omitted keys are left unvalidated.
# Source: https://github.com/munki/munki/wiki/Supported-Pkginfo-Keys
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name="pre-commit-macadmin",
description="Pre-commit hooks for Mac admins, client engineers, and IT consultants.",
url="https://github.com/homebysix/pre-commit-macadmin",
version="1.0.0",
version="1.0.4",
author="Elliot Jordan",
author_email="elliot@elliotjordan.com",
packages=["pre_commit_hooks"],
Expand Down

0 comments on commit 6348f60

Please sign in to comment.