From 6f5d37f99558e4ee13c3a80b1bca074d035aff85 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Thu, 5 Dec 2024 14:09:24 +0100 Subject: [PATCH] :sparkles: Add ConfigurationStep for JWTSecrets required for https://github.com/open-zaak/open-zaak/issues/1825 and https://github.com/open-zaak/open-notificaties/issues/200 --- vng_api_common/contrib/__init__.py | 0 .../contrib/setup_configuration/__init__.py | 0 .../contrib/setup_configuration/models.py | 18 +++++++++++++++ .../contrib/setup_configuration/steps.py | 23 +++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 vng_api_common/contrib/__init__.py create mode 100644 vng_api_common/contrib/setup_configuration/__init__.py create mode 100644 vng_api_common/contrib/setup_configuration/models.py create mode 100644 vng_api_common/contrib/setup_configuration/steps.py diff --git a/vng_api_common/contrib/__init__.py b/vng_api_common/contrib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vng_api_common/contrib/setup_configuration/__init__.py b/vng_api_common/contrib/setup_configuration/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vng_api_common/contrib/setup_configuration/models.py b/vng_api_common/contrib/setup_configuration/models.py new file mode 100644 index 00000000..ad96049e --- /dev/null +++ b/vng_api_common/contrib/setup_configuration/models.py @@ -0,0 +1,18 @@ +from django_setup_configuration.models import ConfigurationModel +from pydantic import Field + +from vng_api_common.models import JWTSecret + + +class SingleJWTSecretConfigurationModel(ConfigurationModel): + class Meta: + django_model_refs = { + JWTSecret: [ + "identifier", + "secret", + ] + } + + +class JWTSecretsConfigurationModel(ConfigurationModel): + items: list[SingleJWTSecretConfigurationModel] = Field(default_factory=list) diff --git a/vng_api_common/contrib/setup_configuration/steps.py b/vng_api_common/contrib/setup_configuration/steps.py new file mode 100644 index 00000000..a6bf2a7b --- /dev/null +++ b/vng_api_common/contrib/setup_configuration/steps.py @@ -0,0 +1,23 @@ +from django_setup_configuration.configuration import BaseConfigurationStep + +from vng_api_common.models import JWTSecret + +from .models import JWTSecretsConfigurationModel + + +class JWTSecretsConfigurationStep(BaseConfigurationStep[JWTSecretsConfigurationModel]): + """ + Configure credentials for Applications that need access + """ + + verbose_name = "Configuration to create credentials" + config_model = JWTSecretsConfigurationModel + namespace = "vng_api_common_credentials" + enable_setting = "vng_api_common_credentials_config_enable" + + def execute(self, model: JWTSecretsConfigurationModel): + for config in model.items: + JWTSecret.objects.update_or_create( + identifier=config.identifier, + defaults={"secret": config.secret}, + )