Skip to content

Commit

Permalink
Added 'easy-vault check-encrypted' command
Browse files Browse the repository at this point in the history
Details:

* 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)

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Apr 5, 2021
1 parent fad0ca2 commit a1aadbb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/changes.rst
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
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
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

0 comments on commit a1aadbb

Please sign in to comment.