management.forms ================ .. py:module:: management.forms .. autoapi-nested-parse:: Forms definition. Module Contents --------------- .. py:class:: SecurityConfigForm(*args, **kwargs) Bases: :py:obj:`django.forms.ModelForm`\ [\ :py:obj:`management.models.SecurityConfig`\ ] Security configuration model form. .. py:attribute:: FEATURE_TO_FIELDS :type: ClassVar[dict[type[management.security.features.SecurityFeature], list[str]]] .. py:attribute:: helper .. py:attribute:: security_mode .. py:attribute:: auto_gen_pki .. py:attribute:: auto_gen_pki_key_algorithm .. py:class:: Meta Meta configuration for SecurityConfigForm. .. py:attribute:: model .. py:attribute:: fields :type: ClassVar[list[str]] :value: ['security_mode', 'auto_gen_pki', 'auto_gen_pki_key_algorithm'] .. py:method:: clean_auto_gen_pki_key_algorithm() Keep the current value of `auto_gen_pki_key_algorithm` from the instance if the field was disabled. .. py:method:: clean() Validate that existing data complies with the target security mode. .. py:class:: NotificationConfigForm(*args, **kwargs) Bases: :py:obj:`django.forms.ModelForm`\ [\ :py:obj:`management.models.NotificationConfig`\ ] Form for managing global notification configuration settings. .. py:attribute:: MAX_EXPIRY_WARNING_DAYS :value: 365 .. py:attribute:: MIN_EXPIRY_WARNING_DAYS :value: 1 .. py:class:: Meta Meta configuration for NotificationConfigForm. .. py:attribute:: model .. py:attribute:: fields :type: ClassVar[list[str]] :value: ['enabled', 'cert_expiry_warning_days', 'issuing_ca_expiry_warning_days'] .. py:attribute:: widgets :type: ClassVar[dict[str, Any]] .. py:attribute:: helper .. py:method:: clean_cert_expiry_warning_days() Validate cert_expiry_warning_days field. .. py:method:: clean_issuing_ca_expiry_warning_days() Validate issuing_ca_expiry_warning_days field. .. py:class:: BackupOptionsForm Bases: :py:obj:`django.forms.ModelForm`\ [\ :py:obj:`management.models.BackupOptions`\ ] Form for editing BackupOptions settings. .. py:class:: Meta ModelForm Meta configuration for BackupOptions. .. py:attribute:: model .. py:attribute:: fields :type: ClassVar[list[str]] :value: ['enable_sftp_storage', 'host', 'port', 'user', 'auth_method', 'password', 'private_key',... .. py:attribute:: widgets :type: ClassVar[dict[str, Any]] .. py:method:: clean() Validate required fields based on selected authentication method. .. py:class:: IPv4AddressForm(*args, **kwargs) Bases: :py:obj:`django.forms.Form` A form for selecting and updating an IPv4 address. This form provides an interface for selecting an IPv4 address from a list of Subject Alternative Names (SANs). .. attribute:: ipv4_address A choice field for selecting the IPv4 address. .. py:attribute:: ipv4_address .. py:class:: TlsAddFileImportPkcs12Form(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None, bound_field_class=None) Bases: :py:obj:`trustpoint.logger.LoggerMixin`, :py:obj:`django.forms.Form` Form for importing an TLS-Server Credential using a PKCS#12 file. This form allows the user to upload a PKCS#12 file containing the private key and certificate chain, along with an optional password. It validates the uploaded file and its contents. .. attribute:: pkcs12_file The PKCS#12 file containing the private key and certificates. :type: FileField .. attribute:: pkcs12_password An optional password for the PKCS#12 file. :type: CharField .. py:attribute:: pkcs12_file .. py:attribute:: pkcs12_password .. py:attribute:: domain_name .. py:method:: clean() Cleans and validates the entire form. This method performs additional validation on the cleaned data to ensure all required fields are valid and consistent. It checks the uploaded PKCS#12 file and its password (if provided). Any issues during validation raise appropriate errors. :raises ValidationError: If the data is invalid, such as when the unique name :raises is already taken or the PKCS#12 file cannot be read or parsed.: .. py:method:: get_saved_credential() Return the saved credential. .. py:class:: TlsAddFileImportSeparateFilesForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None, bound_field_class=None) Bases: :py:obj:`trustpoint.logger.LoggerMixin`, :py:obj:`django.forms.Form` Form for importing a TLS-Server Credential using separate files. This form allows the user to upload a private key file, its password (optional), an TLS certificate file, and an optional certificate chain. The form validates the uploaded files, ensuring they are correctly formatted, within size limits, and not already associated with an existing Issuing CA. .. attribute:: private_key_file The private key file (.key, .pem). :type: FileField .. attribute:: private_key_file_password An optional password for the private key. :type: CharField .. attribute:: tls_certificate The Issuing CA certificate file (.cer, .der, .pem, .p7b, .p7c). :type: FileField .. attribute:: tls_certificate_chain An optional certificate chain file. :type: FileField .. py:attribute:: tls_certificate .. py:attribute:: tls_certificate_chain .. py:attribute:: private_key_file .. py:attribute:: private_key_file_password .. py:attribute:: domain_name .. py:method:: clean_private_key_file() Validates the uploaded private key file. This method checks if the private key file is provided and ensures it meets size constraints. The actual parsing happens in clean() where the password is available. :returns: The raw bytes of the private key file. :rtype: bytes :raises ValidationError: If the private key file is missing or too large. .. py:method:: clean_tls_certificate() Validates and parses the uploaded TLS certificate file. This method ensures the provided TLS certificate file is valid and not already associated with an existing TLS in the database. If the file is too large, corrupted, or already in use, a validation error is raised. :returns: A serializer containing the parsed certificate. :rtype: CertificateSerializer :raises ValidationError: If the file is missing, too large, corrupted, or already :raises associated with an existing TLS.: .. py:method:: clean_tls_certificate_chain() Validates and parses the uploaded TLS certificate chain file. .. py:method:: clean() Cleans and validates the form data. This method performs additional validation on the provided data, such as ensuring the private key file, and certificates are valid. It also activates and saves the TLS certificate if all checks pass. :raises ValidationError: If the form data is invalid or there is an error during processing. .. py:method:: get_saved_credential() Return the saved credential. .. py:class:: KeyStorageConfigForm(*args, **kwargs) Bases: :py:obj:`django.forms.ModelForm`\ [\ :py:obj:`management.models.KeyStorageConfig`\ ] Form for configuring cryptographic material storage options. .. py:attribute:: storage_type .. py:class:: Meta ModelForm Meta configuration for KeyStorageConfig. .. py:attribute:: model .. py:attribute:: fields :type: ClassVar[list[str]] :value: ['storage_type'] .. py:method:: clean() Custom validation for the form. .. py:method:: save_with_commit() Save the form with commit, ensuring singleton behavior. .. py:method:: save_without_commit() Save the form without commit, ensuring singleton behavior. .. py:class:: PKCS11ConfigForm(*args, **kwargs) Bases: :py:obj:`django.forms.Form` Form for configuring PKCS#11 settings including HSM PIN and token information. .. py:attribute:: HSM_TYPE_CHOICES :type: ClassVar[list[tuple[str, Any]]] .. py:attribute:: hsm_type .. py:attribute:: label .. py:attribute:: slot .. py:attribute:: module_path .. py:method:: clean() Custom validation for the form. .. py:method:: clean_label() Validate that label is unique, excluding current token if updating. .. py:method:: save_token_config() Save or update token configuration.