Source code for pki.serializer.issuing_ca
"""Serializers for Issuing CA-related API endpoints.
Defines classes that handle validation and transformation
of Issuing CA model instances to and from JSON.
"""
from typing import ClassVar
from rest_framework import serializers
from pki.models import CaModel
[docs]
class IssuingCaSerializer(serializers.ModelSerializer[CaModel]):
"""Serializer for Issuing CA instances."""
[docs]
common_name = serializers.SerializerMethodField()
[docs]
ca_type = serializers.CharField(read_only=True)
[docs]
ca_type_display = serializers.CharField(
source='get_ca_type_display',
read_only=True
)
[docs]
last_crl_issued_at = serializers.SerializerMethodField()
[docs]
has_crl = serializers.SerializerMethodField()
[docs]
def get_has_crl(self, obj: CaModel) -> bool:
"""Check if the CA has a CRL available."""
return bool(obj.crl_pem)
[docs]
def get_last_crl_issued_at(self, obj: CaModel) -> str | None:
"""Get the last CRL issued at timestamp."""
timestamp = obj.last_crl_issued_at
return timestamp.isoformat() if timestamp else None
[docs]
def get_common_name(self, obj: CaModel) -> str:
"""Get the common name of the CA."""
return obj.common_name