diff --git a/CHANGELOG.md b/CHANGELOG.md index 229f8fe..e6766a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm --- -## [Unreleased] +## [5.0.0] - 2024-02-16 +### Added +- Validation skip functionality for checksums --- diff --git a/README.md b/README.md index bc5c8c1..6ac7e93 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,13 @@ Input: path/to/input is valid Error: path/to/input ``` +#### Validation Skipping + +Certain validations can be skipped through environment variables. +|ENV VAR|Notes| +|:---:|:---:| +|PIPEVAL_SKIP_CHECKSUM|Flag to disable checksum validation. Set to `true` to disable checksum validation within PipeVal.| + ### `pipeval generate-checksum` ``` usage: pipeval generate-checksum [-h] [-t {md5,sha512}] [-v] path [path ...] diff --git a/pipeval/common.py b/pipeval/common.py new file mode 100644 index 0000000..512e934 --- /dev/null +++ b/pipeval/common.py @@ -0,0 +1,29 @@ +""" Common functions for PipeVal """ +import os +from functools import wraps + +# pylint: disable=C0103,W0613 +def skippedValidation(name): + """ + Conditionally mark a validation to be skipped + + If the environment variable f'PIPEVAL_SKIP_{name}' is set to `true`, + the decorated function will skip that validation. + """ + def decorator(func): + return func + + def print_skip_message(func): + @wraps(func) + def skip_message(*args, **kwargs): + print(f'PID:{os.getpid()} - Skipping validation {name.upper()}') + + return skip_message + + value = os.environ.get(f"PIPEVAL_SKIP_{name.upper()}") + should_skip_validate = value is not None and value.lower() == 'true' + + if not should_skip_validate: + return decorator + + return print_skip_message diff --git a/pipeval/generate_checksum/checksum.py b/pipeval/generate_checksum/checksum.py index a48722d..e522c8a 100644 --- a/pipeval/generate_checksum/checksum.py +++ b/pipeval/generate_checksum/checksum.py @@ -5,11 +5,14 @@ from typing import Dict, Union from pathlib import Path +from pipeval.common import skippedValidation + ChecksumArgs = namedtuple( 'args', 'path, type' ) +@skippedValidation('CHECKSUM') def _validate_checksums(path:Path): ''' Validate MD5 and/or SHA512 checksums ''' # Checksum validation diff --git a/test/unit/test_common.py b/test/unit/test_common.py new file mode 100644 index 0000000..4c2c0fa --- /dev/null +++ b/test/unit/test_common.py @@ -0,0 +1,32 @@ +# pylint: disable=C0116 +# pylint: disable=C0114 +# pylint: disable=C0103 +from pipeval.common import skippedValidation + +def test__skippedValidation__properly_skips_function_call(monkeypatch, capsys): + monkeypatch.setenv('PIPEVAL_SKIP_CHECKSUM', 'true') + + @skippedValidation('CHECKSUM') + def to_be_decorated(): + print('Decorated function called') + + to_be_decorated() + + out, _ = capsys.readouterr() + + assert 'Skipping validation CHECKSUM' in out + assert 'Decorated function called' not in out + +def test__skippedValidation__properly_calls_function(monkeypatch, capsys): + monkeypatch.setenv('PIPEVAL_SKIP_CHECKSUM', 'false') + + @skippedValidation('CHECKSUM') + def to_be_decorated(): + print('Decorated function called') + + to_be_decorated() + + out, _ = capsys.readouterr() + + assert 'Skipping validation CHECKSUM' not in out + assert 'Decorated function called' in out