Skip to content

Nautobot SSL Manager API Package

nautobot_ssl_manager.api

REST API module for nautobot_ssl_manager app.

serializers

API serializers for nautobot_ssl_manager.

CertificateAuthoritySerializer

Bases: NautobotModelSerializer, TaggedModelSerializerMixin, TreeModelSerializerMixin

CertificateAuthority Serializer.

Source code in nautobot_ssl_manager/api/serializers.py
class CertificateAuthoritySerializer(  # pylint: disable=too-many-ancestors
    NautobotModelSerializer, TaggedModelSerializerMixin, TreeModelSerializerMixin
):
    """CertificateAuthority Serializer."""

    chain_role = serializers.CharField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.CertificateAuthority
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ssl_manager/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.CertificateAuthority
    fields = "__all__"

CertificateProviderSerializer

Bases: NautobotModelSerializer, TaggedModelSerializerMixin

CertificateProvider Serializer.

Source code in nautobot_ssl_manager/api/serializers.py
class CertificateProviderSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):  # pylint: disable=too-many-ancestors
    """CertificateProvider Serializer."""

    class Meta:
        """Meta attributes."""

        model = models.CertificateProvider
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ssl_manager/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.CertificateProvider
    fields = "__all__"

CertificateSerializer

Bases: NautobotModelSerializer, TaggedModelSerializerMixin

Certificate Serializer.

Source code in nautobot_ssl_manager/api/serializers.py
class CertificateSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):  # pylint: disable=too-many-ancestors
    """Certificate Serializer."""

    days_remaining = serializers.IntegerField(read_only=True, allow_null=True)
    is_expired = serializers.BooleanField(read_only=True, allow_null=True)
    is_wildcard = serializers.BooleanField(read_only=True)

    class Meta:
        """Meta attributes."""

        model = models.Certificate
        fields = "__all__"
Meta

Meta attributes.

Source code in nautobot_ssl_manager/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.Certificate
    fields = "__all__"

DomainValidationRecordSerializer

Bases: NautobotModelSerializer, TaggedModelSerializerMixin

DomainValidationRecord Serializer.

Source code in nautobot_ssl_manager/api/serializers.py
class DomainValidationRecordSerializer(NautobotModelSerializer, TaggedModelSerializerMixin):  # pylint: disable=too-many-ancestors
    """DomainValidationRecord Serializer."""

    fqdn = serializers.CharField(read_only=True)
    dns_models_match = serializers.SerializerMethodField(
        help_text="Comparison with Nautobot DNS Models: present, different, absent (null when it is not installed)"
    )

    class Meta:
        """Meta attributes."""

        model = models.DomainValidationRecord
        fields = "__all__"
        # The unique constraint involves optional fields (text, alias): DRF would make them required. It is validated
        # by the model instead (`full_clean()`).
        validators = []

    @extend_schema_field(
        serializers.ChoiceField(choices=choices.DNSModelsMatchChoices.CHOICES, allow_null=True, read_only=True)
    )
    def get_dns_models_match(self, obj):
        """State annotated by the viewset (see `dns_models.annotate`)."""
        return dns_models.get_match(obj)
Meta

Meta attributes.

Source code in nautobot_ssl_manager/api/serializers.py
class Meta:
    """Meta attributes."""

    model = models.DomainValidationRecord
    fields = "__all__"
    # The unique constraint involves optional fields (text, alias): DRF would make them required. It is validated
    # by the model instead (`full_clean()`).
    validators = []
get_dns_models_match(obj)

State annotated by the viewset (see dns_models.annotate).

Source code in nautobot_ssl_manager/api/serializers.py
@extend_schema_field(
    serializers.ChoiceField(choices=choices.DNSModelsMatchChoices.CHOICES, allow_null=True, read_only=True)
)
def get_dns_models_match(self, obj):
    """State annotated by the viewset (see `dns_models.annotate`)."""
    return dns_models.get_match(obj)

urls

Django API urlpatterns declaration for nautobot_ssl_manager app.

views

API views for nautobot_ssl_manager.

CertificateAuthorityViewSet

Bases: NautobotModelViewSet

CertificateAuthority viewset.

Source code in nautobot_ssl_manager/api/views.py
class CertificateAuthorityViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """CertificateAuthority viewset."""

    queryset = models.CertificateAuthority.objects.all()
    serializer_class = serializers.CertificateAuthoritySerializer
    filterset_class = filters.CertificateAuthorityFilterSet

CertificateProviderViewSet

Bases: NautobotModelViewSet

CertificateProvider viewset.

Source code in nautobot_ssl_manager/api/views.py
class CertificateProviderViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """CertificateProvider viewset."""

    queryset = models.CertificateProvider.objects.all()
    serializer_class = serializers.CertificateProviderSerializer
    filterset_class = filters.CertificateProviderFilterSet

CertificateViewSet

Bases: NautobotModelViewSet

Certificate viewset.

Source code in nautobot_ssl_manager/api/views.py
class CertificateViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """Certificate viewset."""

    queryset = models.Certificate.objects.all()
    serializer_class = serializers.CertificateSerializer
    filterset_class = filters.CertificateFilterSet

    @extend_schema(
        filters=False,
        parameters=[
            OpenApiParameter(
                name="file_format",
                location="query",
                required=False,
                type=OpenApiTypes.STR,
                enum=list(downloads.FORMATS),
                description="pem (default), der (single certificate only) or p7b (PKCS#7, DER encoded)",
            ),
            OpenApiParameter(
                name="chain",
                location="query",
                required=False,
                type=OpenApiTypes.BOOL,
                description="Append the CA certificates of the chain (issuing CA first)",
            ),
            OpenApiParameter(
                name="include_root",
                location="query",
                required=False,
                type=OpenApiTypes.BOOL,
                description="With chain: also include the self-signed Root CA certificate",
            ),
        ],
        responses={
            200: OpenApiResponse(response=OpenApiTypes.BINARY, description="Certificate file (attachment)"),
            400: OpenApiResponse(description="The file cannot be built (no PEM, incomplete or inconsistent chain)"),
            403: OpenApiResponse(description="A Certificate Authority or certificate of the chain is not visible"),
        },
    )
    @action(detail=True, methods=["get"], url_path="download")
    def download(self, request, pk=None):
        """Download the public certificate, optionally with its chain."""
        # Not `get_object()`: its strict filtering would reject the download parameters as unknown filters.
        certificate = get_object_or_404(self.get_queryset(), pk=pk)
        try:
            download = downloads.build_download(
                certificate,
                file_format=request.query_params.get("file_format"),
                chain=downloads.parse_bool(request.query_params.get("chain")),
                include_root=downloads.parse_bool(request.query_params.get("include_root")),
                user=request.user,
            )
        except downloads.CertificateDownloadPermissionError as exc:
            return Response({"detail": str(exc)}, status=status.HTTP_403_FORBIDDEN)
        except downloads.CertificateDownloadError as exc:
            return Response({"detail": str(exc)}, status=status.HTTP_400_BAD_REQUEST)
        return downloads.download_response(download)
download(request, pk=None)

Download the public certificate, optionally with its chain.

Source code in nautobot_ssl_manager/api/views.py
@extend_schema(
    filters=False,
    parameters=[
        OpenApiParameter(
            name="file_format",
            location="query",
            required=False,
            type=OpenApiTypes.STR,
            enum=list(downloads.FORMATS),
            description="pem (default), der (single certificate only) or p7b (PKCS#7, DER encoded)",
        ),
        OpenApiParameter(
            name="chain",
            location="query",
            required=False,
            type=OpenApiTypes.BOOL,
            description="Append the CA certificates of the chain (issuing CA first)",
        ),
        OpenApiParameter(
            name="include_root",
            location="query",
            required=False,
            type=OpenApiTypes.BOOL,
            description="With chain: also include the self-signed Root CA certificate",
        ),
    ],
    responses={
        200: OpenApiResponse(response=OpenApiTypes.BINARY, description="Certificate file (attachment)"),
        400: OpenApiResponse(description="The file cannot be built (no PEM, incomplete or inconsistent chain)"),
        403: OpenApiResponse(description="A Certificate Authority or certificate of the chain is not visible"),
    },
)
@action(detail=True, methods=["get"], url_path="download")
def download(self, request, pk=None):
    """Download the public certificate, optionally with its chain."""
    # Not `get_object()`: its strict filtering would reject the download parameters as unknown filters.
    certificate = get_object_or_404(self.get_queryset(), pk=pk)
    try:
        download = downloads.build_download(
            certificate,
            file_format=request.query_params.get("file_format"),
            chain=downloads.parse_bool(request.query_params.get("chain")),
            include_root=downloads.parse_bool(request.query_params.get("include_root")),
            user=request.user,
        )
    except downloads.CertificateDownloadPermissionError as exc:
        return Response({"detail": str(exc)}, status=status.HTTP_403_FORBIDDEN)
    except downloads.CertificateDownloadError as exc:
        return Response({"detail": str(exc)}, status=status.HTTP_400_BAD_REQUEST)
    return downloads.download_response(download)

DomainValidationRecordViewSet

Bases: NautobotModelViewSet

DomainValidationRecord viewset.

Source code in nautobot_ssl_manager/api/views.py
class DomainValidationRecordViewSet(NautobotModelViewSet):  # pylint: disable=too-many-ancestors
    """DomainValidationRecord viewset."""

    queryset = models.DomainValidationRecord.objects.prefetch_related("certificates")
    serializer_class = serializers.DomainValidationRecordSerializer
    filterset_class = filters.DomainValidationRecordFilterSet

    def get_queryset(self):
        """Annotate the comparison with Nautobot DNS Models (records visible to the user only)."""
        return dns_models.annotate(super().get_queryset(), user=self.request.user)
get_queryset()

Annotate the comparison with Nautobot DNS Models (records visible to the user only).

Source code in nautobot_ssl_manager/api/views.py
def get_queryset(self):
    """Annotate the comparison with Nautobot DNS Models (records visible to the user only)."""
    return dns_models.annotate(super().get_queryset(), user=self.request.user)