From 9d58407e25a3be61db0764ef15ee217a381b72d7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 18 Aug 2022 19:23:50 +0200 Subject: [PATCH] blueprints: remove _state from exporter blueprints Signed-off-by: Jens Langhammer --- .../tests/{test_bundled.py => test_packaged.py} | 6 +++--- authentik/blueprints/v1/common.py | 8 +++++++- authentik/blueprints/v1/importer.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) rename authentik/blueprints/tests/{test_bundled.py => test_packaged.py} (86%) diff --git a/authentik/blueprints/tests/test_bundled.py b/authentik/blueprints/tests/test_packaged.py similarity index 86% rename from authentik/blueprints/tests/test_bundled.py rename to authentik/blueprints/tests/test_packaged.py index 300cd16c1..21188e893 100644 --- a/authentik/blueprints/tests/test_bundled.py +++ b/authentik/blueprints/tests/test_packaged.py @@ -10,7 +10,7 @@ from authentik.blueprints.v1.importer import Importer from authentik.tenants.models import Tenant -class TestBundled(TransactionTestCase): +class TestPackaged(TransactionTestCase): """Empty class, test methods are added dynamically""" @apply_blueprint("default/90-default-tenant.yaml") @@ -22,7 +22,7 @@ class TestBundled(TransactionTestCase): def blueprint_tester(file_name: Path) -> Callable: """This is used instead of subTest for better visibility""" - def tester(self: TestBundled): + def tester(self: TestPackaged): base = Path("blueprints/") rel_path = Path(file_name).relative_to(base) importer = Importer(BlueprintInstance(path=str(rel_path)).retrieve()) @@ -33,4 +33,4 @@ def blueprint_tester(file_name: Path) -> Callable: for blueprint_file in Path("blueprints/").glob("**/*.yaml"): - setattr(TestBundled, f"test_blueprint_{blueprint_file}", blueprint_tester(blueprint_file)) + setattr(TestPackaged, f"test_blueprint_{blueprint_file}", blueprint_tester(blueprint_file)) diff --git a/authentik/blueprints/v1/common.py b/authentik/blueprints/v1/common.py index 1197c0b9e..bc98e342e 100644 --- a/authentik/blueprints/v1/common.py +++ b/authentik/blueprints/v1/common.py @@ -232,7 +232,13 @@ class BlueprintDumper(SafeDumper): def represent(self, data) -> None: if is_dataclass(data): - data = asdict(data) + + def factory(items): + final_dict = dict(items) + final_dict.pop("_state", None) + return final_dict + + data = asdict(data, dict_factory=factory) return super().represent(data) diff --git a/authentik/blueprints/v1/importer.py b/authentik/blueprints/v1/importer.py index c4fc44a34..6c9744aa5 100644 --- a/authentik/blueprints/v1/importer.py +++ b/authentik/blueprints/v1/importer.py @@ -231,7 +231,7 @@ class Importer: self.logger.debug("Starting blueprint import validation") orig_import = deepcopy(self.__import) if self.__import.version != 1: - self.logger.warning("Invalid bundle version") + self.logger.warning("Invalid blueprint version") return False, [] with ( transaction_rollback(),