From 5358e6a758d50244513455c1a3d9fd640cff14ab Mon Sep 17 00:00:00 2001 From: Veinar Date: Mon, 9 Dec 2024 14:25:10 +0100 Subject: [PATCH] Black formatting applied --- envcloak/commands/decrypt.py | 12 +++++++++--- envcloak/commands/encrypt.py | 12 +++++++++--- envcloak/commands/generate_key.py | 7 ++++++- envcloak/commands/generate_key_from_password.py | 7 ++++++- envcloak/commands/rotate_keys.py | 3 ++- envcloak/generator.py | 10 +++++++--- envcloak/utils.py | 10 +++++++--- 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/envcloak/commands/decrypt.py b/envcloak/commands/decrypt.py index 477b259..9e899fc 100644 --- a/envcloak/commands/decrypt.py +++ b/envcloak/commands/decrypt.py @@ -9,7 +9,9 @@ debug_log, calculate_required_space, list_files_to_encrypt, - read_key_file, conditional_echo, conditional_secho + read_key_file, + conditional_echo, + conditional_secho, ) from envcloak.handlers import ( handle_directory_preview, @@ -132,7 +134,9 @@ def decrypt( debug, ) decrypt_file(input, output, key, validate_integrity=not skip_sha_validation) - conditional_echo(f"File {input} decrypted -> {output} using key {key_file}", quiet) + conditional_echo( + f"File {input} decrypted -> {output} using key {key_file}", quiet + ) elif directory: debug_log(f"Debug: Decrypting files in directory {directory}.", debug) traverse_and_process_files( @@ -149,7 +153,9 @@ def decrypt( ), recursion=recursion, ) - conditional_echo(f"All files in directory {directory} decrypted -> {output}", quiet) + conditional_echo( + f"All files in directory {directory} decrypted -> {output}", quiet + ) except FileDecryptionException as e: click.echo( f"Error during decryption: Error: Failed to decrypt the file.\nDetails: {e.details}", diff --git a/envcloak/commands/encrypt.py b/envcloak/commands/encrypt.py index 7964a58..2f4056f 100644 --- a/envcloak/commands/encrypt.py +++ b/envcloak/commands/encrypt.py @@ -10,7 +10,9 @@ calculate_required_space, list_files_to_encrypt, validate_paths, - read_key_file, conditional_echo, conditional_secho + read_key_file, + conditional_echo, + conditional_secho, ) from envcloak.handlers import ( handle_directory_preview, @@ -108,7 +110,9 @@ def encrypt( debug, ) encrypt_file(input, output, key) - conditional_echo(f"File {input} encrypted -> {output} using key {key_file}", quiet) + conditional_echo( + f"File {input} encrypted -> {output} using key {key_file}", quiet + ) elif directory: debug_log(f"Debug: Encrypting files in directory {directory}.", debug) traverse_and_process_files( @@ -122,7 +126,9 @@ def encrypt( ), recursion=recursion, ) - conditional_echo(f"All files in directory {directory} encrypted -> {output}", quiet) + conditional_echo( + f"All files in directory {directory} encrypted -> {output}", quiet + ) except FileEncryptionException as e: click.echo( f"Error: An error occurred during file encryption.\nDetails: {e}", diff --git a/envcloak/commands/generate_key.py b/envcloak/commands/generate_key.py index f83af0b..9a067c0 100644 --- a/envcloak/commands/generate_key.py +++ b/envcloak/commands/generate_key.py @@ -8,7 +8,12 @@ import click from envcloak.validation import check_output_not_exists, check_disk_space from envcloak.generator import generate_key_file -from envcloak.utils import add_to_gitignore, debug_log, conditional_echo, conditional_secho +from envcloak.utils import ( + add_to_gitignore, + debug_log, + conditional_echo, + conditional_secho, +) from envcloak.decorators.common_decorators import ( debug_option, dry_run_option, diff --git a/envcloak/commands/generate_key_from_password.py b/envcloak/commands/generate_key_from_password.py index b6f7ba0..8dd168b 100644 --- a/envcloak/commands/generate_key_from_password.py +++ b/envcloak/commands/generate_key_from_password.py @@ -8,7 +8,12 @@ import click from envcloak.validation import check_output_not_exists, check_disk_space, validate_salt from envcloak.generator import generate_key_from_password_file -from envcloak.utils import debug_log, add_to_gitignore, conditional_echo, conditional_secho +from envcloak.utils import ( + debug_log, + add_to_gitignore, + conditional_echo, + conditional_secho, +) from envcloak.decorators.common_decorators import ( debug_option, dry_run_option, diff --git a/envcloak/commands/rotate_keys.py b/envcloak/commands/rotate_keys.py index 315b147..9963e0e 100644 --- a/envcloak/commands/rotate_keys.py +++ b/envcloak/commands/rotate_keys.py @@ -73,7 +73,8 @@ def rotate_keys( - New key: {new_key_file} will be used to decrypt the encrypted file. - Encrypted file: {input} will be re-encrypted to {output}. """, - fg="cyan", quiet=quiet + fg="cyan", + quiet=quiet, ) return if dry_run: diff --git a/envcloak/generator.py b/envcloak/generator.py index 402c8e2..71cdfbb 100644 --- a/envcloak/generator.py +++ b/envcloak/generator.py @@ -20,10 +20,13 @@ def generate_key_file(output_path: Path, quiet: bool): output_path.parent.mkdir(parents=True, exist_ok=True) # Ensure directory exists with open(output_path, "wb") as key_file: key_file.write(key) - if not quiet: print(f"Encryption key generated and saved to {output_path}") + if not quiet: + print(f"Encryption key generated and saved to {output_path}") -def generate_key_from_password_file(password: str, output_path: Path, quiet: bool, salt: str = None): +def generate_key_from_password_file( + password: str, output_path: Path, quiet: bool, salt: str = None +): """ Derive an encryption key from a password and save it to a file. If no salt is provided, a random one is generated. @@ -49,4 +52,5 @@ def generate_key_from_password_file(password: str, output_path: Path, quiet: boo with open(output_path, "wb") as key_file: key_file.write(key) - if not quiet: print(f"Derived encryption key saved to {output_path}") + if not quiet: + print(f"Derived encryption key saved to {output_path}") diff --git a/envcloak/utils.py b/envcloak/utils.py index 87975ea..fd7d200 100644 --- a/envcloak/utils.py +++ b/envcloak/utils.py @@ -32,12 +32,14 @@ def add_to_gitignore(directory: str, filename: str, quiet: bool): content = gitignore_file.read() if filename not in content: gitignore_file.write(f"\n{filename}") - if not quiet: print(f"Added '{filename}' to {gitignore_path}") + if not quiet: + print(f"Added '{filename}' to {gitignore_path}") else: # Create a new .gitignore file and add the filename with open(gitignore_path, "w", encoding="utf-8") as gitignore_file: gitignore_file.write(f"{filename}\n") - if not quiet: print(f"Created {gitignore_path} and added '{filename}'") + if not quiet: + print(f"Created {gitignore_path} and added '{filename}'") def calculate_required_space(input=None, directory=None): @@ -144,6 +146,7 @@ def read_key_file(key_file, debug): debug_log(f"Debug: Key file {key_file} read successfully.", debug) return key + def conditional_echo(message, quiet, **kwargs): """ Echo a message only if `quiet` is False. @@ -151,9 +154,10 @@ def conditional_echo(message, quiet, **kwargs): if not quiet: click.echo(message, **kwargs) + def conditional_secho(message, quiet, **kwargs): """ Styled echo a message only if `quiet` is False. """ if not quiet: - click.secho(message, **kwargs) \ No newline at end of file + click.secho(message, **kwargs)