certbot.reverter module¶
Reverter class saves configuration checkpoints and allows for recovery.
- class certbot.reverter.Reverter(config: NamespaceConfig)[source]¶
Bases:
object
Reverter Class - save and revert configuration checkpoints.
This class can be used by the plugins, especially Installers, to undo changes made to the user’s system. Modifications to files and commands to do undo actions taken by the plugin should be registered with this class before the action is taken.
Once a change has been registered with this class, there are three states the change can be in. First, the change can be a temporary change. This should be used for changes that will soon be reverted, such as config changes for the purpose of solving a challenge. Changes are added to this state through calls to
add_to_temp_checkpoint()
and reverted whenrevert_temporary_config()
orrecovery_routine()
is called.The second state a change can be in is in progress. These changes are not temporary, however, they also have not been finalized in a checkpoint. A change must become in progress before it can be finalized. Changes are added to this state through calls to
add_to_checkpoint()
and reverted whenrecovery_routine()
is called.The last state a change can be in is finalized in a checkpoint. A change is put into this state by first becoming an in progress change and then calling
finalize_checkpoint()
. Changes in this state can be reverted through calls torollback_checkpoints()
.As a final note, creating new files and registering undo commands are handled specially and use the methods
register_file_creation()
andregister_undo_command()
respectively. Both of these methods can be used to create either temporary or in progress changes.Note
Consider moving everything over to CSV format.
- Parameters:
config (
certbot.configuration.NamespaceConfig
) – Configuration.
- revert_temporary_config() None [source]¶
Reload users original configuration files after a temporary save.
This function should reinstall the users original configuration files for all saves with temporary=True
- Raises:
.ReverterError – when unable to revert config
- rollback_checkpoints(rollback: int = 1) None [source]¶
Revert ‘rollback’ number of configuration checkpoints.
- Parameters:
rollback (int) – Number of checkpoints to reverse. A str num will be cast to an integer. So “2” is also acceptable.
- Raises:
.ReverterError – if there is a problem with the input or if the function is unable to correctly revert the configuration checkpoints
- add_to_temp_checkpoint(save_files: Set[str], save_notes: str) None [source]¶
Add files to temporary checkpoint.
- Parameters:
save_files (set) – set of filepaths to save
save_notes (str) – notes about changes during the save
- add_to_checkpoint(save_files: Set[str], save_notes: str) None [source]¶
Add files to a permanent checkpoint.
- Parameters:
save_files (set) – set of filepaths to save
save_notes (str) – notes about changes during the save
- register_file_creation(temporary: bool, *files: str) None [source]¶
Register the creation of all files during certbot execution.
Call this method before writing to the file to make sure that the file will be cleaned up if the program exits unexpectedly. (Before a save occurs)
- Parameters:
temporary (bool) – If the file creation registry is for a temp or permanent save.
*files – file paths (str) to be registered
- Raises:
certbot.errors.ReverterError – If call does not contain necessary parameters or if the file creation is unable to be registered.
- register_undo_command(temporary: bool, command: Iterable[str]) None [source]¶
Register a command to be run to undo actions taken.
Warning
This function does not enforce order of operations in terms of file modification vs. command registration. All undo commands are run first before all normal files are reverted to their previous state. If you need to maintain strict order, you may create checkpoints before and after the the command registration. This function may be improved in the future based on demand.
- Parameters:
temporary (bool) – Whether the command should be saved in the IN_PROGRESS or TEMPORARY checkpoints.
command (list of str) – Command to be run.
- recovery_routine() None [source]¶
Revert configuration to most recent finalized checkpoint.
Remove all changes (temporary and permanent) that have not been finalized. This is useful to protect against crashes and other execution interruptions.
- Raises:
.errors.ReverterError – If unable to recover the configuration
- finalize_checkpoint(title: str) None [source]¶
Finalize the checkpoint.
Timestamps and permanently saves all changes made through the use of
add_to_checkpoint()
andregister_file_creation()
- Parameters:
title (str) – Title describing checkpoint
- Raises:
certbot.errors.ReverterError – when the checkpoint is not able to be finalized.