pki.forms.cert_profiles ======================= .. py:module:: pki.forms.cert_profiles .. autoapi-nested-parse:: Django forms for certificate profile configuration. Module Contents --------------- .. py:function:: check_validity_days_against_security_config(total_days) Raise :class:`~django.core.exceptions.ValidationError` if *total_days* exceeds the policy limit. .. py:class:: CertProfileConfigForm Bases: :py:obj:`trustpoint.logger.LoggerMixin`, :py:obj:`django.forms.ModelForm`\ [\ :py:obj:`pki.models.cert_profile.CertificateProfileModel`\ ] Form for creating or updating Certificate Profiles. This form is based on the CertificateProfileModel and allows users to create or update certificate profiles by specifying a unique name and profile JSON configuration. .. attribute:: unique_name A unique name for the certificate profile. :type: CharField .. attribute:: profile_json The JSON configuration for the certificate profile. :type: JSONField .. py:class:: Meta Meta information for the CertProfileConfigForm. .. py:attribute:: model .. py:attribute:: fields :type: ClassVar[list[str]] :value: ['unique_name', 'profile_json', 'is_default'] .. py:method:: clean_unique_name() Validates the unique name to ensure it is not already in use. :raises ValidationError: If the unique name is already associated with an existing certificate profile. .. py:method:: clean_profile_json() Validates the profile JSON to ensure it is a valid certificate profile. :raises ValidationError: If the profile JSON is not a valid certificate profile, or if the configured validity exceeds the security policy limit. .. py:class:: ProfileBasedFormFieldBuilder(profile) Bases: :py:obj:`trustpoint.logger.LoggerMixin` Django form field builder that leverages JSONProfileVerifier. This builder uses JSONProfileVerifier.get_sample_request() to understand the profile structure, eliminating the need for manual profile parsing logic. .. attribute:: profile The certificate profile definition .. attribute:: verifier JSONProfileVerifier instance for profile interpretation .. attribute:: fields Dictionary of generated Django form fields .. py:attribute:: SUBJECT_LABELS :type: ClassVar[dict[str, str]] .. py:attribute:: SAN_LABELS :type: ClassVar[dict[str, str]] .. py:attribute:: VALIDITY_LABELS :type: ClassVar[dict[str, str]] .. py:attribute:: profile .. py:attribute:: verifier .. py:attribute:: fields :type: dict[str, django.forms.Field] .. py:method:: build_all_fields() Build all fields from the profile by analyzing a sample request. This leverages JSONProfileVerifier.get_sample_request() to understand the profile structure, eliminating manual parsing. .. py:class:: CertificateIssuanceForm(profile, *args, **kwargs) Bases: :py:obj:`trustpoint.logger.LoggerMixin`, :py:obj:`django.forms.Form` Form for certificate issuance based on a certificate profile. This form dynamically generates fields based on a certificate profile and leverages existing infrastructure for profile interpretation and certificate building: - Uses JSONProfileVerifier.get_sample_request() to understand what fields to show - Validates user input with JSONProfileVerifier.apply_profile_to_request() - Delegates certificate building to JSONCertRequestConverter.from_json() This eliminates code duplication and ensures consistent profile interpretation across the application (55% code reduction from original implementation). .. attribute:: profile The certificate profile definition .. attribute:: verifier JSONProfileVerifier instance for validation .. attribute:: fields Dynamically generated Django form fields .. py:attribute:: profile .. py:attribute:: verifier .. py:attribute:: fields .. py:method:: get_certificate_builder() Build a CertificateBuilder from the form data. This method converts the form data to JSON format and delegates to JSONCertRequestConverter.from_json() to create the CertificateBuilder. :returns: CertificateBuilder ready for signing .. py:method:: clean() Validate the requested certificate validity against the active security policy.