Skip to content

Commit

Permalink
✨ Add ConfigurationStep for JWTSecrets
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Dec 5, 2024
1 parent fa1b534 commit 000dd95
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions vng_api_common/contrib/setup_configuration/models.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions vng_api_common/contrib/setup_configuration/steps.py
Original file line number Diff line number Diff line change
@@ -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},
)

0 comments on commit 000dd95

Please sign in to comment.