setup_wizard.views¶
Views for the users application.
Attributes¶
Exceptions¶
Custom exception for Trustpoint wizard-related issues. |
|
Custom exception for errors related to Trustpoint TLS Server Credentials. |
Classes¶
Handles redirection logic based on the current state of the setup wizard. |
|
View for the initial step of the setup wizard. |
|
View for the restore option during initialization. |
|
Upload a dump file and restore the database from it. |
|
View for generating TLS Server Credentials in the setup wizard. |
|
View for handling the import of TLS Server Credentials. |
|
View for handling the application of TLS Server Credentials in the setup wizard. |
|
View for handling the cancellation of TLS Server Credential application. |
|
View for handling the demo data setup during the setup wizard. |
|
View for handling the creation of a superuser during the setup wizard. |
Functions¶
|
Execute a shell script. |
Module Contents¶
- exception setup_wizard.views.TrustpointWizardError[source]¶
Bases:
ExceptionCustom exception for Trustpoint wizard-related issues.
- exception setup_wizard.views.TrustpointTlsServerCredentialError(message='Trustpoint TLS Server Credential error occurred.')[source]¶
Bases:
ExceptionCustom 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)[source]¶
Execute a shell script.
- Parameters:
script (Path) – The path to the shell script to execute.
- 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.SetupWizardInitialView(**kwargs)[source]¶
Bases:
django.views.generic.TemplateViewView 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.
- 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.SetupWizardOptionsView(**kwargs)[source]¶
Bases:
django.views.generic.TemplateViewView for the restore option during initialization.
- 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.BackupRestoreView(**kwargs)[source]¶
Bases:
django.views.generic.View,trustpoint.logger.LoggerMixinUpload a dump file and restore the database from it.
- 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.
- 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:
TrustpointTlsServerCredentialError – If no TLS server credential is found.
subprocess.CalledProcessError – If the associated shell script fails.
- class setup_wizard.views.SetupWizardImportTlsServerCredentialView(**kwargs)[source]¶
Bases:
django.views.generic.ViewView for handling the import of TLS Server Credentials.
- 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.
- 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:
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
- _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 the keys and certificates.
- Return type:
None
- class setup_wizard.views.SetupWizardTlsServerCredentialApplyCancelView(**kwargs)[source]¶
Bases:
trustpoint.logger.LoggerMixin,django.views.generic.ViewView for handling the cancellation of TLS Server Credential application.
- 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
- 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.
- 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
- 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.
- 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