From ea04d5be751d913ba8c02521aefcfd5196a7da81 Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Mon, 19 Aug 2024 13:02:01 +0200 Subject: [PATCH 1/2] Added SCRUBBER_VALIDATION_WHITELIST and excluded Django core test model --- CHANGELOG.md | 2 ++ README.md | 7 +++++++ django_scrubber/__init__.py | 3 +++ .../management/commands/scrub_validation.py | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05446fa..3ad27a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [2.0.0] - 2024-06-27 diff --git a/README.md b/README.md index f99c725..f2f10ab 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,13 @@ SCRUBBER_MAPPING = { (default: {}) +### `SCRUBBER_VALIDATION_WHITELIST`: + +Whitelist models you want to exclude from the `scrub_validation` checker command for scrubber-wise undeclared models. +By default, it contains only a test model from Django core which doesn't have to be anonymised. + +(default: ['db.TestModel',]) + ## Logging Scrubber uses the default django logger. The logger name is ``django_scrubber.scrubbers``. diff --git a/django_scrubber/__init__.py b/django_scrubber/__init__.py index 8ff11b9..2e9d0af 100644 --- a/django_scrubber/__init__.py +++ b/django_scrubber/__init__.py @@ -29,6 +29,9 @@ 'sites.Site', 'django_scrubber.FakeData', ], + 'SCRUBBER_VALIDATION_WHITELIST': [ + 'db.TestModel', # Test model from Django core + ], } diff --git a/django_scrubber/management/commands/scrub_validation.py b/django_scrubber/management/commands/scrub_validation.py index d56b10b..973572c 100644 --- a/django_scrubber/management/commands/scrub_validation.py +++ b/django_scrubber/management/commands/scrub_validation.py @@ -2,6 +2,7 @@ from django.core.management.base import BaseCommand +from django_scrubber import settings_with_fallback from django_scrubber.services.validator import ScrubberValidatorService @@ -13,8 +14,17 @@ def handle(self, *args, **options): found_models = 0 found_fields = 0 + + whitelisted_models = settings_with_fallback('SCRUBBER_VALIDATION_WHITELIST') + if len(non_scrubbed_field_list): for model_path, affected_field_list in non_scrubbed_field_list.items(): + + if model_path in whitelisted_models: + print(f'Model {model_path!r} was excluded via \'SCRUBBER_VALIDATION_WHITELIST\' and will ' + f'not be validated.') + continue + print(f'Model {model_path!r}:') found_models += 1 for field in affected_field_list: From 45139fee1dbb4584aac333c7faddcec9098f7c7b Mon Sep 17 00:00:00 2001 From: Ronny Vedrilla Date: Tue, 20 Aug 2024 10:15:01 +0200 Subject: [PATCH 2/2] Removed unnecessary f-string --- django_scrubber/management/commands/scrub_validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_scrubber/management/commands/scrub_validation.py b/django_scrubber/management/commands/scrub_validation.py index 973572c..5db8b34 100644 --- a/django_scrubber/management/commands/scrub_validation.py +++ b/django_scrubber/management/commands/scrub_validation.py @@ -22,7 +22,7 @@ def handle(self, *args, **options): if model_path in whitelisted_models: print(f'Model {model_path!r} was excluded via \'SCRUBBER_VALIDATION_WHITELIST\' and will ' - f'not be validated.') + 'not be validated.') continue print(f'Model {model_path!r}:')