management.formsΒΆ

Forms definition.

Module ContentsΒΆ

class management.forms.SecurityConfigForm(*args, **kwargs)[source]ΒΆ

Bases: django.forms.ModelForm[management.models.SecurityConfig]

Security configuration model form.

Parameters:
  • args (Any)

  • kwargs (Any)

FEATURE_TO_FIELDS: ClassVar[dict[type[management.security.features.SecurityFeature], list[str]]][source]ΒΆ
helper[source]ΒΆ
security_mode[source]ΒΆ
auto_gen_pki[source]ΒΆ
auto_gen_pki_key_algorithm[source]ΒΆ
class Meta[source]ΒΆ

Meta configuration for SecurityConfigForm.

model[source]ΒΆ
fields: ClassVar[list[str]] = ['security_mode', 'auto_gen_pki', 'auto_gen_pki_key_algorithm'][source]ΒΆ
clean_auto_gen_pki_key_algorithm()[source]ΒΆ

Keep the current value of auto_gen_pki_key_algorithm from the instance if the field was disabled.

Return type:

pki.util.keys.AutoGenPkiKeyAlgorithm

clean()[source]ΒΆ

Validate that existing data complies with the target security mode.

Return type:

dict[str, Any]

class management.forms.NotificationConfigForm(*args, **kwargs)[source]ΒΆ

Bases: django.forms.ModelForm[management.models.NotificationConfig]

Form for managing global notification configuration settings.

Parameters:
  • args (Any)

  • kwargs (Any)

MAX_EXPIRY_WARNING_DAYS = 365[source]ΒΆ
MIN_EXPIRY_WARNING_DAYS = 1[source]ΒΆ
class Meta[source]ΒΆ

Meta configuration for NotificationConfigForm.

model[source]ΒΆ
fields: ClassVar[list[str]] = ['enabled', 'cert_expiry_warning_days', 'issuing_ca_expiry_warning_days'][source]ΒΆ
widgets: ClassVar[dict[str, Any]][source]ΒΆ
helper[source]ΒΆ
clean_cert_expiry_warning_days()[source]ΒΆ

Validate cert_expiry_warning_days field.

Return type:

int | None

clean_issuing_ca_expiry_warning_days()[source]ΒΆ

Validate issuing_ca_expiry_warning_days field.

Return type:

int | None

class management.forms.BackupOptionsForm[source]ΒΆ

Bases: django.forms.ModelForm[management.models.BackupOptions]

Form for editing BackupOptions settings.

class Meta[source]ΒΆ

ModelForm Meta configuration for BackupOptions.

model[source]ΒΆ
fields: ClassVar[list[str]] = ['enable_sftp_storage', 'host', 'port', 'user', 'auth_method', 'password', 'private_key',...[source]ΒΆ
widgets: ClassVar[dict[str, Any]][source]ΒΆ
clean()[source]ΒΆ

Validate required fields based on selected authentication method.

Return type:

dict[str, Any]

class management.forms.IPv4AddressForm(*args, **kwargs)[source]ΒΆ

Bases: 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).

Parameters:
  • args (Any)

  • kwargs (Any)

ipv4_address[source]ΒΆ

A choice field for selecting the IPv4 address.

ipv4_address[source]ΒΆ
class management.forms.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)[source]ΒΆ

Bases: trustpoint.logger.LoggerMixin, 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.

pkcs12_file[source]ΒΆ

The PKCS#12 file containing the private key and certificates.

Type:

FileField

pkcs12_password[source]ΒΆ

An optional password for the PKCS#12 file.

Type:

CharField

pkcs12_file[source]ΒΆ
pkcs12_password[source]ΒΆ
domain_name[source]ΒΆ
clean()[source]ΒΆ

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

  • is already taken or the PKCS#12 file cannot be read or parsed. –

Return type:

None

get_saved_credential()[source]ΒΆ

Return the saved credential.

Return type:

pki.models.CredentialModel

class management.forms.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)[source]ΒΆ

Bases: trustpoint.logger.LoggerMixin, 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.

private_key_file[source]ΒΆ

The private key file (.key, .pem).

Type:

FileField

private_key_file_password[source]ΒΆ

An optional password for the private key.

Type:

CharField

tls_certificate[source]ΒΆ

The Issuing CA certificate file (.cer, .der, .pem, .p7b, .p7c).

Type:

FileField

tls_certificate_chain[source]ΒΆ

An optional certificate chain file.

Type:

FileField

tls_certificate[source]ΒΆ
tls_certificate_chain[source]ΒΆ
private_key_file[source]ΒΆ
private_key_file_password[source]ΒΆ
domain_name[source]ΒΆ
clean_private_key_file()[source]ΒΆ

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.

Return type:

bytes

Raises:

ValidationError – If the private key file is missing or too large.

clean_tls_certificate()[source]ΒΆ

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.

Return type:

CertificateSerializer

Raises:
  • ValidationError – If the file is missing, too large, corrupted, or already

  • associated with an existing TLS. –

clean_tls_certificate_chain()[source]ΒΆ

Validates and parses the uploaded TLS certificate chain file.

Return type:

None | trustpoint_core.serializer.CertificateCollectionSerializer

clean()[source]ΒΆ

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.

Return type:

dict[str, Any] | None

get_saved_credential()[source]ΒΆ

Return the saved credential.

Return type:

pki.models.CredentialModel

class management.forms.KeyStorageConfigForm(*args, **kwargs)[source]ΒΆ

Bases: django.forms.ModelForm[management.models.KeyStorageConfig]

Form for configuring cryptographic material storage options.

Parameters:
  • args (Any)

  • kwargs (Any)

storage_type[source]ΒΆ
class Meta[source]ΒΆ

ModelForm Meta configuration for KeyStorageConfig.

model[source]ΒΆ
fields: ClassVar[list[str]] = ['storage_type'][source]ΒΆ
clean()[source]ΒΆ

Custom validation for the form.

Return type:

dict[str, Any]

save_with_commit()[source]ΒΆ

Save the form with commit, ensuring singleton behavior.

Return type:

management.models.KeyStorageConfig

save_without_commit()[source]ΒΆ

Save the form without commit, ensuring singleton behavior.

Return type:

management.models.KeyStorageConfig

class management.forms.PKCS11ConfigForm(*args, **kwargs)[source]ΒΆ

Bases: django.forms.Form

Form for configuring PKCS#11 settings including HSM PIN and token information.

Parameters:
  • args (Any)

  • kwargs (Any)

HSM_TYPE_CHOICES: ClassVar[list[tuple[str, Any]]][source]ΒΆ
hsm_type[source]ΒΆ
label[source]ΒΆ
slot[source]ΒΆ
module_path[source]ΒΆ
clean()[source]ΒΆ

Custom validation for the form.

Return type:

dict[str, Any]

clean_label()[source]ΒΆ

Validate that label is unique, excluding current token if updating.

Return type:

str

save_token_config()[source]ΒΆ

Save or update token configuration.

Return type:

management.models.PKCS11Token