Source code for pki.models.cert_profile

"""Module for certificate profile related models."""

import json
from typing import Any, cast

from django.db import models
from django.utils.translation import gettext_lazy as _
from django_stubs_ext.db.models import TypedModelMeta


[docs] class CertificateProfileModel(models.Model): """Model representing a certificate profile."""
[docs] unique_name = models.CharField(max_length=255, unique=True)
[docs] display_name = models.CharField(max_length=255, blank=True, default='')
[docs] profile_json = models.JSONField()
[docs] created_at = models.DateTimeField(verbose_name=_('Created-At'), auto_now_add=True)
[docs] updated_at = models.DateTimeField(verbose_name=_('Updated-At'), auto_now=True)
[docs] is_default = models.BooleanField(default=False)
[docs] class Meta(TypedModelMeta): """Meta information."""
def __str__(self) -> str: """String representation of the CertificateProfileModel.""" return self.unique_name @property
[docs] def profile(self) -> dict[str, Any]: """Get the profile as a parsed dict.""" if isinstance(self.profile_json, str): return cast('dict[str, Any]', json.loads(self.profile_json)) return cast('dict[str, Any]', self.profile_json)