diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d08c61..c825a60 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.3.0 + rev: v4.4.0 hooks: - id: debug-statements - id: check-ast @@ -16,7 +16,7 @@ repos: - id: check-merge-conflict - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 22.12.0 hooks: - id: black language_version: python3 diff --git a/README.md b/README.md index c2b79d9..fcf3ac7 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,18 @@ Add this to your `.pre-commit-config.yaml` ```yaml repos: - repo: https://github.com/eitrtechnologies/pre-commit-yamlpolicy - rev: v1.2.0 # Use the ref you want to point to + rev: v1.3.0 # Use the ref you want to point to hooks: - id: bannedk8skinds - id: disallowunquoted - id: valueregex - args: [--jmespath, '*.matchers[].match', --regex, '\([^ ]|[^ ]\)'] + args: + - --jmespath + - '*.matchers[].match' + - --regex + - '\([^ ]|[^ ]\)' + - --error-message + - Found parentheses too close together. Can haz fix plz? ``` ### Hooks Available @@ -44,5 +50,7 @@ values in YAML. the values to run a regex against. *REQUIRED* - `--regex` - Regex which will cause the hook to fail if it matches any of the values returned by the JMESPath query. *REQUIRED* + - `--error-message` - Message to display when a match is found. This allows + a more user-friendly message to be displayed for a given regex match. - `--allow-multiple-documents` - Allow YAML files which use the [multi-document syntax](http://www.yaml.org/spec/1.2/spec.html#YAML) diff --git a/setup.cfg b/setup.cfg index 3ef6fc5..a3634b7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = yamlpolicy -version = 1.2.0 +version = 1.3.0 description = Allows an organization to specify YAML usage policy. long_description = file: README.md long_description_content_type = text/markdown diff --git a/valueregex/valueregex.py b/valueregex/valueregex.py index 89b589e..0bc6292 100755 --- a/valueregex/valueregex.py +++ b/valueregex/valueregex.py @@ -35,6 +35,10 @@ def main(argv: Optional[Sequence[str]] = None) -> int: "--jmespath", required=True, ) + optional.add_argument( + "-e", + "--error-message", + ) required.add_argument("filenames", nargs="*", help="Filenames to check.") args: argparse.Namespace = parser.parse_args(argv) @@ -43,6 +47,10 @@ def main(argv: Optional[Sequence[str]] = None) -> int: retval: int = 0 for filename in args.filenames: + error_message: str = f'Restricted value found for JMESPath "{search}"' + if args.error_message: + error_message = args.error_message + try: with open(filename, encoding="UTF-8") as f: if args.multi: @@ -54,7 +62,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int: match: re.Match = regex.search(val) if match: print( - f'{filename}: Restricted value found for JMESPath "{search}" = {match.group(0).rstrip()}' + f"{filename}: {error_message} = {match.group(0).rstrip()}" ) retval = 1 except ruamel.yaml.YAMLError as exc: