setup_wizard.views

Views for the users application.

Attributes

Exceptions

TrustpointWizardError

Custom exception for Trustpoint wizard-related issues.

TrustpointTlsServerCredentialError

Custom exception for errors related to Trustpoint TLS Server Credentials.

Classes

StartupWizardRedirect

Handles redirection logic based on the current state of the setup wizard.

HsmSetupMixin

Mixin that provides common HSM setup functionality for both initial setup and auto restore.

SetupWizardCryptoStorageView

View for handling crypto storage setup during the setup wizard.

SetupWizardHsmSetupView

View for handling HSM setup during the setup wizard.

SetupWizardSetupModeView

View for the initial step of the setup wizard.

SetupWizardSelectTlsServerCredentialView

View for selecting the TLS server credential during setup.

SetupWizardRestoreOptionsView

View for the restore option during initialization.

SetupWizardBackupPasswordView

View for setting up backup password for PKCS#11 token during the setup wizard.

BackupPasswordRecoveryMixin

Mixin that provides backup password recovery functionality.

AutoRestoreHsmSetupView

View for handling HSM setup during auto restore process.

BackupRestoreView

Upload a dump file and restore the database from it with optional backup password.

BackupAutoRestorePasswordView

View for handling backup password entry during auto restore process.

SetupWizardGenerateTlsServerCredentialView

View for generating TLS Server Credentials in the setup wizard.

SetupWizardImportTlsServerCredentialMethodSelectView

View for selecting the import method for TLS Server Credentials.

SetupWizardImportTlsServerCredentialPkcs12View

View for importing TLS Server Credentials using a PKCS#12 file in the setup wizard.

SetupWizardImportTlsServerCredentialSeparateFilesView

View for importing TLS Server Credentials using separate files in the setup wizard.

SetupWizardTlsServerCredentialApplyView

View for handling the application of TLS Server Credentials in the setup wizard.

SetupWizardTlsServerCredentialApplyCancelView

View for handling the cancellation of TLS Server Credential application.

SetupWizardDemoDataView

View for handling the demo data setup during the setup wizard.

SetupWizardCreateSuperUserView

View for handling the creation of a superuser during the setup wizard.

Functions

execute_shell_script(script, *args)

Execute a shell script with optional arguments.

Module Contents

setup_wizard.views.logger[source]
exception setup_wizard.views.TrustpointWizardError[source]

Bases: Exception

Custom exception for Trustpoint wizard-related issues.

exception setup_wizard.views.TrustpointTlsServerCredentialError(message='Trustpoint TLS Server Credential error occurred.')[source]

Bases: Exception

Custom exception for errors related to Trustpoint TLS Server Credentials.

This exception is raised when specific issues with the TLS Server Credentials occur, such as missing credentials.

Parameters:

message (str)

setup_wizard.views.execute_shell_script(script, *args)[source]

Execute a shell script with optional arguments.

Parameters:
  • script (Path) – The path to the shell script to execute.

  • *args (str) – Additional arguments to pass to the script.

Raises:
  • FileNotFoundError – If the script does not exist.

  • ValueError – If the script path is not a valid file.

  • subprocess.CalledProcessError – If the script fails to execute.

Return type:

None

class setup_wizard.views.StartupWizardRedirect[source]

Handles redirection logic based on the current state of the setup wizard.

This class provides a static method for determining the appropriate redirection URL based on the wizard’s state, ensuring users are guided through the setup process.

static redirect_by_state(wizard_state)[source]

Redirects the user to the appropriate setup wizard page based on the current state.

Parameters:

wizard_state (SetupWizardState) – The current state of the setup wizard.

Returns:

A redirection response to the appropriate page.

Return type:

HttpResponseRedirect

Raises:

ValueError – If the wizard state is unrecognized or invalid.

class setup_wizard.views.HsmSetupMixin[source]

Bases: trustpoint.logger.LoggerMixin

Mixin that provides common HSM setup functionality for both initial setup and auto restore.

request: django.http.HttpRequest[source]
form_valid(form)[source]

Handle form submission for HSM setup.

Parameters:

form (setup_wizard.forms.HsmSetupForm)

Return type:

django.http.HttpResponse

_validate_hsm_inputs(module_path, slot, label)[source]

Validate HSM input fields and add error messages if invalid.

Parameters:
  • module_path (str)

  • slot (str)

  • label (str)

Return type:

bool

_run_hsm_setup_script(module_path, slot, label)[source]

Run the HSM setup shell script.

Parameters:
  • module_path (str)

  • slot (str)

  • label (str)

Return type:

subprocess.CompletedProcess[str]

_get_or_update_token(hsm_type, module_path, slot, label)[source]

Get or update the PKCS11Token object.

Parameters:
  • hsm_type (str)

  • module_path (str)

  • slot (str)

  • label (str)

Return type:

tuple[management.models.PKCS11Token, bool]

_assign_token_to_crypto_storage(token, hsm_type)[source]

Assign the created token to the appropriate crypto storage configuration.

Parameters:
Return type:

None

_generate_kek_and_dek(token)[source]

Generate KEK and DEK for the token, log and warn on failure.

Parameters:

token (management.models.PKCS11Token)

Return type:

None

_raise_called_process_error(returncode)[source]

Raise a subprocess.CalledProcessError with the given return code.

Parameters:

returncode (int)

Return type:

None

_add_success_message(hsm_type, *, created, token)[source]

Add a success message for HSM setup.

Parameters:
Return type:

None

_handle_hsm_setup_exception(exc)[source]

Handle exceptions during HSM setup and add appropriate error messages.

Parameters:

exc (Exception)

Return type:

django.http.HttpResponse

static _map_exit_code_to_message(return_code)[source]

Map script exit codes to meaningful error messages.

Parameters:

return_code (int)

Return type:

str

get_setup_type()[source]

Return the setup type for the HSM script.

Return type:

str

get_error_redirect_url()[source]

Return the URL to redirect to on error.

Return type:

str

get_success_context()[source]

Return context string for success messages.

Return type:

str

get_expected_wizard_state()[source]

Return the expected wizard state for this view.

Return type:

setup_wizard.SetupWizardState

class setup_wizard.views.SetupWizardCryptoStorageView[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[management.forms.KeyStorageConfigForm]

View for handling crypto storage setup during the setup wizard.

http_method_names = ('get', 'post')[source]
template_name = 'setup_wizard/crypto_storage_setup.html'[source]
form_class[source]
dispatch(request, *args, **kwargs)[source]

Handle request dispatch and wizard state validation.

Parameters:
  • request (django.http.HttpRequest)

  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponseBase

form_valid(form)[source]

Handle valid form submission and determine next step based on storage type.

Parameters:

form (management.forms.KeyStorageConfigForm)

Return type:

django.http.HttpResponse

form_invalid(form)[source]

Handle invalid form submission.

Parameters:

form (management.forms.KeyStorageConfigForm)

Return type:

django.http.HttpResponse

static _map_exit_code_to_message(return_code)[source]

Map script exit codes to meaningful error messages.

Parameters:

return_code (int)

Return type:

str

class setup_wizard.views.SetupWizardHsmSetupView[source]

Bases: HsmSetupMixin, django.views.generic.FormView[setup_wizard.forms.HsmSetupForm]

View for handling HSM setup during the setup wizard.

form_class[source]
template_name = 'setup_wizard/hsm_setup.html'[source]
http_method_names = ('get', 'post')[source]
dispatch(request, *args, **kwargs)[source]

Handle request dispatch and wizard state validation.

Parameters:
  • request (django.http.HttpRequest)

  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponseBase

get_form(form_class=None)[source]

Return a form instance with appropriate defaults based on HSM type.

Parameters:

form_class (type[setup_wizard.forms.HsmSetupForm] | None)

Return type:

setup_wizard.forms.HsmSetupForm

get_context_data(**kwargs)[source]

Add HSM type to template context.

Parameters:

kwargs (Any)

Return type:

dict[str, Any]

get_setup_type()[source]

Return the setup type for the HSM script.

Return type:

str

get_success_url()[source]

Return the success URL after HSM setup.

Return type:

str

get_error_redirect_url()[source]

Return the URL to redirect to on error.

Return type:

str

get_success_context()[source]

Return context string for success messages.

Return type:

str

get_expected_wizard_state()[source]

Return the expected wizard state for this view.

Return type:

setup_wizard.SetupWizardState

class setup_wizard.views.SetupWizardSetupModeView(**kwargs)[source]

Bases: django.views.generic.TemplateView

View for the initial step of the setup wizard.

This view is responsible for displaying the initial setup wizard page. It ensures that the application is running in a Docker container and that the setup wizard is in the initial state. If either condition is not met, the user is redirected to the appropriate page, such as the login page or the next setup step.

http_method_names[source]

List of HTTP methods allowed for this view.

Type:

ClassVar[list[str]]

template_name[source]

Path to the template used for rendering the initial page.

Type:

str

http_method_names = ('get',)[source]
template_name = 'setup_wizard/setup_mode.html'[source]
get(*args, **kwargs)[source]

Handle GET requests for the setup mode wizard page.

This method validates the current state of the setup wizard and redirects the user to the appropriate page. If the application is not running in a Docker container, the user is redirected to the login page.

Parameters:
  • *args (Any) – Additional positional arguments.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

A redirect response to the appropriate setup wizard page

or the login page if the setup is not in a Docker container.

Return type:

HttpResponse

class setup_wizard.views.SetupWizardSelectTlsServerCredentialView[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[setup_wizard.forms.EmptyForm]

View for selecting the TLS server credential during setup.

http_method_names = ('get', 'post')[source]
template_name = 'setup_wizard/select_tls_server_credential.html'[source]
form_class[source]
dispatch(request, *args, **kwargs)[source]

Handle request dispatch and wizard state validation.

Parameters:
  • request (django.http.HttpRequest)

  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponseBase

get(*args, **kwargs)[source]

Handle GET requests for the TLS server credential selection page.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponse

form_valid(_)[source]

Handle form submission for TLS server credential selection.

Parameters:

_ (setup_wizard.forms.EmptyForm)

Return type:

django.http.HttpResponse

class setup_wizard.views.SetupWizardRestoreOptionsView(**kwargs)[source]

Bases: django.views.generic.TemplateView

View for the restore option during initialization.

http_method_names[source]

List of HTTP methods allowed for this view.

Type:

ClassVar[list[str]]

template_name[source]

Path to the template used for rendering the initial page.

Type:

str

http_method_names = ('get',)[source]
template_name = 'setup_wizard/restore_options.html'[source]
get(*args, **kwargs)[source]

Handle GET requests for the initial setup wizard page.

This method validates the current state of the setup wizard and redirects the user to the appropriate page. If the application is not running in a Docker container, the user is redirected to the login page.

Parameters:
  • *args (Any) – Additional positional arguments.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

A redirect response to the appropriate setup wizard page

or the login page if the setup is not in a Docker container.

Return type:

HttpResponse

class setup_wizard.views.SetupWizardBackupPasswordView[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[setup_wizard.forms.BackupPasswordForm]

View for setting up backup password for PKCS#11 token during the setup wizard.

This view allows users to set a backup password that can be used to recover the DEK (Data Encryption Key) in case the HSM becomes unavailable. The password is used to derive a BEK (Backup Encryption Key) using Argon2.

http_method_names = ('get', 'post')[source]
template_name = 'setup_wizard/backup_password.html'[source]
success_url[source]
form_class[source]
dispatch(request, *args, **kwargs)[source]

Handle request dispatch and wizard state validation.

Parameters:
  • request (django.http.HttpRequest)

  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponseBase

get_context_data(**kwargs)[source]

Add password requirements to the context.

Parameters:

kwargs (Any)

Return type:

dict[str, Any]

form_valid(form)[source]

Handle valid form submission.

Parameters:

form (setup_wizard.forms.BackupPasswordForm)

Return type:

django.http.HttpResponse

form_invalid(form)[source]

Handle invalid form submission.

Parameters:

form (setup_wizard.forms.BackupPasswordForm)

Return type:

django.http.HttpResponse

static _map_exit_code_to_message(return_code)[source]

Map script exit codes to meaningful error messages.

Parameters:

return_code (int)

Return type:

str

class setup_wizard.views.BackupPasswordRecoveryMixin[source]

Bases: trustpoint.logger.LoggerMixin

Mixin that provides backup password recovery functionality.

request: django.http.HttpRequest[source]
handle_backup_password_recovery(backup_password)[source]

Handle DEK recovery using backup password.

This method handles two scenarios: 1. Standard recovery: KEK exists, use it to wrap the recovered DEK 2. New KEK scenario: No KEK or KEK doesn’t match, generate new KEK first

Parameters:

backup_password (str) – The backup password provided by user

Returns:

True if recovery was successful, False otherwise

Return type:

bool

_get_token_for_recovery()[source]

Get the PKCS11Token for recovery.

Return type:

management.models.PKCS11Token | None

_ensure_kek_exists(token)[source]

Ensure KEK exists on the token, generate if needed.

Returns:

True if KEK already existed, False if newly generated, None on error

Return type:

bool

Parameters:

token (management.models.PKCS11Token)

_recover_dek_with_password(token, backup_password)[source]

Recover DEK using backup password.

Parameters:
Return type:

bytes | None

_wrap_and_save_dek(token, dek_bytes, *, had_kek)[source]

Wrap recovered DEK with KEK and save.

Parameters:
Return type:

bool

_cache_dek(token)[source]

Cache the DEK for immediate use.

Parameters:

token (management.models.PKCS11Token)

Return type:

None

_log_success(token, *, had_kek)[source]

Log successful recovery.

Parameters:
Return type:

None

class setup_wizard.views.AutoRestoreHsmSetupView[source]

Bases: HsmSetupMixin, django.views.generic.FormView[setup_wizard.forms.HsmSetupForm]

View for handling HSM setup during auto restore process.

This view initializes the SoftHSM token when restoring to a new HSM installation where the old KEK is lost. It uses the wizard_setup_hsm.sh script with ‘auto_restore_setup’ mode.

form_class[source]
template_name = 'setup_wizard/hsm_setup.html'[source]
http_method_names = ('get', 'post')[source]
dispatch(request, *args, **kwargs)[source]

Handle request dispatch and wizard state validation.

Parameters:
  • request (django.http.HttpRequest)

  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponseBase

get_form(form_class=None)[source]

Return a form instance with appropriate defaults based on HSM type.

Parameters:

form_class (type[setup_wizard.forms.HsmSetupForm] | None)

Return type:

setup_wizard.forms.HsmSetupForm

get_context_data(**kwargs)[source]

Add HSM type to template context.

Parameters:

kwargs (Any)

Return type:

dict[str, Any]

get_setup_type()[source]

Return the setup type for the HSM script (auto_restore_setup).

Return type:

str

get_success_url()[source]

Return the success URL after HSM setup.

Return type:

str

get_error_redirect_url()[source]

Return the URL to redirect to on error.

Return type:

str

get_success_context()[source]

Return context string for success messages.

Return type:

str

get_expected_wizard_state()[source]

Return the expected wizard state for this view.

Return type:

setup_wizard.SetupWizardState

class setup_wizard.views.BackupRestoreView(**kwargs)[source]

Bases: BackupPasswordRecoveryMixin, trustpoint.logger.LoggerMixin, django.views.generic.View

Upload a dump file and restore the database from it with optional backup password.

post(request)[source]

Handle POST requests to upload a backup file and restore the database.

Parameters:

request (django.http.HttpRequest)

Return type:

django.http.HttpResponse

_handle_invalid_form()[source]

Handle invalid form submission.

Return type:

django.http.HttpResponse

_process_backup_file(backup_file, backup_password)[source]

Process the uploaded backup file.

Parameters:
  • backup_file (Any)

  • backup_password (str | None)

Return type:

django.http.HttpResponse

_save_backup_file(backup_file, temp_path)[source]

Save the uploaded backup file to a temporary location.

Parameters:
  • backup_file (Any)

  • temp_path (pathlib.Path)

Return type:

None

_restore_database(backup_file, backup_password)[source]

Restore the database from the backup file.

Parameters:
  • backup_file (Any)

  • backup_password (str | None)

Return type:

None

_cleanup_temp_file(temp_path)[source]

Clean up the temporary backup file.

Parameters:

temp_path (pathlib.Path)

Return type:

None

static _map_exit_code_to_message(return_code)[source]

Map script exit codes to meaningful error messages.

Parameters:

return_code (int)

Return type:

str

class setup_wizard.views.BackupAutoRestorePasswordView[source]

Bases: BackupPasswordRecoveryMixin, trustpoint.logger.LoggerMixin, django.views.generic.FormView[setup_wizard.forms.PasswordAutoRestoreForm]

View for handling backup password entry during auto restore process.

This view allows users to enter the backup password needed to recover the DEK (Data Encryption Key) during the auto restore process. It validates the current wizard state and processes the password recovery.

http_method_names = ('get', 'post')[source]
template_name = 'setup_wizard/auto_restore_password.html'[source]
success_url[source]
form_class[source]
dispatch(request, *args, **kwargs)[source]

Handle request dispatch and wizard state validation.

Parameters:
  • request (django.http.HttpRequest)

  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponseBase

get_context_data(**kwargs)[source]

Add additional context data.

Parameters:

kwargs (Any)

Return type:

dict[str, Any]

form_valid(form)[source]

Handle valid form submission.

Parameters:

form (setup_wizard.forms.PasswordAutoRestoreForm)

Return type:

django.http.HttpResponse

form_invalid(form)[source]

Handle invalid form submission.

Parameters:

form (setup_wizard.forms.PasswordAutoRestoreForm)

Return type:

django.http.HttpResponse

_raise_runtime_error(message)[source]

Helper method to raise RuntimeError with logging.

Parameters:

message (str)

Return type:

None

_deactivate_all_issuing_cas()[source]

Deactivate all Issuing CAs after HSM change.

When restoring to a new HSM, the private keys from the old HSM are no longer available. This method deactivates all CAs to prevent operations that would require the missing private keys.

Return type:

None

_extract_tls_certificates()[source]

Extract TLS certificates from database and write to files for Nginx configuration.

This is called during auto restore to prepare TLS files before Nginx configuration.

Raises:

RuntimeError – If TLS credential extraction fails.

Return type:

None

static _map_exit_code_to_message(return_code)[source]

Map script exit codes to meaningful error messages.

Parameters:

return_code (int)

Return type:

str

class setup_wizard.views.SetupWizardGenerateTlsServerCredentialView[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[setup_wizard.forms.StartupWizardTlsCertificateForm]

View for generating TLS Server Credentials in the setup wizard.

This view handles the generation of TLS Server Credentials as part of the setup wizard. It provides a form for the user to input necessary information such as IP addresses and domain names, and processes the data to generate the required TLS certificates.

http_method_names[source]

HTTP methods allowed for this view.

Type:

ClassVar[list[str]]

template_name[source]

Path to the template used for rendering the form.

Type:

str

form_class[source]

The form class used to validate user input.

Type:

Form

success_url[source]

The URL to redirect to upon successful credential generation.

Type:

str

http_method_names = ('get', 'post')[source]
template_name = 'setup_wizard/generate_tls_server_credential.html'[source]
form_class[source]
success_url[source]
dispatch(request, *args, **kwargs)[source]

Override the dispatch method to enforce wizard state validation.

This method ensures that the user is redirected appropriately based on the current wizard state. If the application is not running in a Docker container, the user is redirected to the login page.

Parameters:
  • request (HttpRequest) – The incoming HTTP request.

  • *args (Any) – Additional positional arguments.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

A redirect response to the appropriate page or

the next handler in the dispatch chain.

Return type:

HttpResponse

form_valid(form)[source]

Handle a valid form submission for TLS Server Credential generation.

Parameters:

form (setup_wizard.forms.StartupWizardTlsCertificateForm) – The validated form containing user input for generating the TLS Server Credential.

Returns:

Redirect to the success URL upon successful

credential generation, or an error page if an exception occurs.

Return type:

HttpResponseRedirect

Raises:
static _map_exit_code_to_message(return_code)[source]

Map script exit codes to meaningful error messages.

Parameters:

return_code (int)

Return type:

str

class setup_wizard.views.SetupWizardImportTlsServerCredentialMethodSelectView(**kwargs)[source]

Bases: django.views.generic.TemplateView

View for selecting the import method for TLS Server Credentials.

http_method_names = ('get',)[source]
template_name = 'setup_wizard/import_method_select.html'[source]
dispatch(request, *args, **kwargs)[source]

Override the dispatch method to enforce wizard state validation.

Parameters:
  • request (HttpRequest) – The incoming HTTP request.

  • *args (Any) – Additional positional arguments.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

A redirect response to the appropriate page or

the next handler in the dispatch chain.

Return type:

HttpResponse

class setup_wizard.views.SetupWizardImportTlsServerCredentialPkcs12View[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[management.forms.TlsAddFileImportPkcs12Form]

View for importing TLS Server Credentials using a PKCS#12 file in the setup wizard.

http_method_names = ('get', 'post')[source]
template_name = 'setup_wizard/import_tls_server_credential.html'[source]
form_class[source]
success_url[source]
dispatch(request, *args, **kwargs)[source]

Override the dispatch method to enforce wizard state validation.

Parameters:
  • request (HttpRequest) – The incoming HTTP request.

  • *args (Any) – Additional positional arguments.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

A redirect response to the appropriate page or

the next handler in the dispatch chain.

Return type:

HttpResponse

form_valid(form)[source]

Handle a valid form submission for TLS Server Credential import.

Parameters:

form (management.forms.TlsAddFileImportPkcs12Form) – The validated form containing the uploaded PKCS#12 file.

Returns:

Redirect to the success URL upon successful

credential import, or an error page if an exception occurs.

Return type:

HttpResponseRedirect

_get_error_message_from_return_code(return_code)[source]

Maps return codes to error messages.

Parameters:

return_code (int)

Return type:

str

class setup_wizard.views.SetupWizardImportTlsServerCredentialSeparateFilesView[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[management.forms.TlsAddFileImportSeparateFilesForm]

View for importing TLS Server Credentials using separate files in the setup wizard.

http_method_names = ('get', 'post')[source]
template_name = 'setup_wizard/import_tls_server_credential.html'[source]
form_class[source]
success_url[source]
dispatch(request, *args, **kwargs)[source]

Override the dispatch method to enforce wizard state validation.

Parameters:
  • request (HttpRequest) – The incoming HTTP request.

  • *args (Any) – Additional positional arguments.

  • **kwargs (Any) – Additional keyword arguments.

Returns:

A redirect response to the appropriate page or

the next handler in the dispatch chain.

Return type:

HttpResponse

form_valid(form)[source]

Handle a valid form submission for TLS Server Credential import.

Parameters:

form (management.forms.TlsAddFileImportSeparateFilesForm) – The validated form containing the uploaded certificate files.

Returns:

Redirect to the success URL upon successful

credential import, or an error page if an exception occurs.

Return type:

HttpResponseRedirect

_get_error_message_from_return_code(return_code)[source]

Maps return codes to error messages.

Parameters:

return_code (int)

Return type:

str

class setup_wizard.views.SetupWizardTlsServerCredentialApplyView[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[setup_wizard.forms.EmptyForm]

View for handling the application of TLS Server Credentials in the setup wizard.

http_method_names[source]

Allowed HTTP methods for this view (‘get’ and ‘post’).

Type:

list[str]

form_class[source]

The form used for processing TLS Server Credential application.

Type:

Form

template_name[source]

The template used to render the view.

Type:

str

success_url

The URL to redirect to upon successful form submission.

Type:

str

http_method_names = ('get', 'post')[source]
form_class[source]
template_name = 'setup_wizard/tls_server_credential_apply.html'[source]
get_success_url()[source]

Return the success URL based on storage type.

Return type:

str

get(request, *args, **kwargs)[source]

Handle GET requests for the TLS Server Credential application view.

Parameters:
  • request (HttpRequest) – The HTTP request object.

  • *args (Any) – Positional arguments passed to the method.

  • **kwargs (Any) – Keyword arguments passed to the method.

Returns:

A redirect response to the appropriate wizard state or the requested page.

Return type:

HttpResponse

post(*args, **kwargs)[source]

Handle POST requests for the TLS Server Credential application view.

Parameters:
  • *args (Any) – Positional arguments passed to the method.

  • **kwargs (Any) – Keyword arguments passed to the method.

Returns:

A redirect response to the appropriate page based on the wizard state.

Return type:

HttpResponse

form_valid(form)[source]

Process a valid form submission during the TLS Server Credential application.

Parameters:

form (setup_wizard.forms.EmptyForm) – The form instance containing the submitted data.

Returns:

Redirect to the next step or an error page based on the outcome.

Return type:

HttpResponseRedirect

_raise_tls_credential_error(message)[source]

Raise a TrustpointTlsServerCredentialError with a given message.

Parameters:

message (str) – The error message to include in the exception.

Return type:

NoReturn

_map_exit_code_to_message(return_code)[source]

Maps shell script exit codes to user-friendly error messages.

Parameters:

return_code (int)

Return type:

str

_generate_trust_store_response(file_format)[source]

Generate a response containing the trust store in the requested format.

Parameters:

file_format (str) – The desired file format for the trust store (e.g., ‘pem’, ‘pkcs7_der’, ‘pkcs7_pem’).

Returns:

A response with the trust store content or an error message.

Return type:

HttpResponse

static _get_trust_store_and_content_type(file_format, certificate_serializer)[source]

Tries to get the certificate in the requested format and adds the corresponding content type.

Parameters:
  • file_format (str) – The file format requested.

  • certificate_serializer (trustpoint_core.serializer.CertificateSerializer) – The certificate serializer.

Returns:

The tuple of the certificate in the requested format and the content type.

Return type:

tuple[str | bytes, str]

static _write_pem_files(credential_model)[source]

Writes the private key, certificate, and trust store PEM files to disk.

Parameters:
  • credential_model (CredentialModel) – The credential model instance containing

  • certificates. (the keys and)

Return type:

None

class setup_wizard.views.SetupWizardTlsServerCredentialApplyCancelView(**kwargs)[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.View

View for handling the cancellation of TLS Server Credential application.

http_method_names[source]

Allowed HTTP methods for this view.

http_method_names = ('get',)[source]
get(request)[source]

Handle GET requests for the TLS Server Credential import view.

Parameters:

request (django.http.HttpRequest) – The HTTP request object.

Returns:

A redirect to the next step or an error response.

Return type:

HttpResponse

_clear_credential_and_certificate_data_and_execute(request)[source]

Clear the credential and certificate data and executes the corresponding action suing a shell script.

Parameters:

request (django.http.HttpRequest) – The HTTP request object.

Return type:

django.http.HttpResponse

_clear_credential_and_certificate_data()[source]

Clears all credential and certificate data if canceled in the ‘WIZARD_TLS_SERVER_CREDENTIAL_APPLY’ state.

Return type:

None

_map_exit_code_to_message(return_code)[source]

Maps shell script exit codes to user-friendly error messages.

Parameters:

return_code (int)

Return type:

str

class setup_wizard.views.SetupWizardDemoDataView[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[setup_wizard.forms.EmptyForm]

View for handling the demo data setup during the setup wizard.

This view allows the user to either add demo data to the database or proceed without it. It validates the current wizard state and transitions to the next state upon successful completion.

http_method_names = ('get', 'post')[source]
form_class[source]
template_name = 'setup_wizard/demo_data.html'[source]
success_url[source]
dispatch(request, *args, **kwargs)[source]

Handle request dispatch and wizard state validation.

Parameters:
  • request (django.http.HttpRequest)

  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponseBase

form_valid(form)[source]

Handle form submission for demo data setup.

Parameters:

form (setup_wizard.forms.EmptyForm)

Return type:

django.http.HttpResponse

_add_demo_data()[source]

Add demo data to the database.

Return type:

None

_execute_notifications()[source]

Creating notifications.

Return type:

None

static _map_exit_code_to_message(return_code)[source]

Map script exit codes to meaningful error messages.

Parameters:

return_code (int) – The exit code returned by the script.

Returns:

A descriptive error message corresponding to the exit code.

Return type:

str

class setup_wizard.views.SetupWizardCreateSuperUserView[source]

Bases: trustpoint.logger.LoggerMixin, django.views.generic.FormView[django.contrib.auth.forms.UserCreationForm[django.contrib.auth.models.User]]

View for handling the creation of a superuser during the setup wizard.

This view is part of the setup wizard process. It allows an admin to create a superuser account, ensuring that the application has at least one administrative user configured. The view validates the input using the UserCreationForm and transitions the wizard state upon successful completion.

http_method_names = ('get', 'post')[source]
form_class: type[django.contrib.auth.forms.UserCreationForm[django.contrib.auth.models.User]][source]
template_name = 'setup_wizard/create_super_user.html'[source]
success_url[source]
dispatch(request, *args, **kwargs)[source]

Handle request dispatch and wizard state validation.

Parameters:
  • request (django.http.HttpRequest)

  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponseBase

form_valid(form)[source]

Handle form submission for creating a superuser.

Parameters:

form (django.contrib.auth.forms.UserCreationForm[django.contrib.auth.models.User]) – The form containing the data for the superuser creation.

Returns:

Redirect to the next step or login page.

Return type:

HttpResponseRedirect

static _map_exit_code_to_message(return_code)[source]

Map script exit codes to meaningful error messages.

Parameters:

return_code (int)

Return type:

str