Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'easy-vault check-encrypted' command #58

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Released: not yet
a vault file in the keyring service. Added a corresponding
'Keyring.delete_password()' method. (issues #33 and #35)

* Added a 'easy-vault check-encrypted' command that checks whether the vault
file is encrypted and exits with 1 if that is ot the case. This can be used
for example if the vault file is stored in a repository to regularly check
whether it is encrypted to ensure it has not been committed by mistake in the
decrypted state. (issue #57)

* Improved error messages when writing vault file during 'EasyVault.encrypt()'
/ 'decrypt()'.

Expand Down
1 change: 1 addition & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ This command displays self-explanatory help, e.g.:
$ easy-vault encrypt --help
$ easy-vault decrypt --help
$ easy-vault check-keyring --help
$ easy-vault check-encrypted --help


.. _`Accessing the secrets in a program`:
Expand Down
24 changes: 24 additions & 0 deletions easy_vault/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ def cli_decrypt(vaultfile, **options):
verbose=verbose, echo=click.echo)


@cli.command('check-encrypted')
@click.argument('vaultfile', type=str, metavar='VAULTFILE', required=True)
@add_options(quiet_option)
@add_options(help_option)
def cli_check_encrypted(vaultfile, **options):
"""
Check whether the vault file is encrypted.

If encrypted, the command exits with 0.
If not encrypted, the command exits with 1.
"""
verbose = not options['quiet']

check_exists(vaultfile)

if not EasyVault(vaultfile).is_encrypted():
if verbose:
click.echo("Error: Vault file is not encrypted")
click.get_current_context().exit(1)

if verbose:
click.echo("Success! Vault file is encrypted")


@cli.command('check-keyring')
@add_options(quiet_option)
@add_options(help_option)
Expand Down