diff --git a/source/helpers/keepass.py b/source/helpers/keepass.py index 2727e56..b7cd0c5 100644 --- a/source/helpers/keepass.py +++ b/source/helpers/keepass.py @@ -38,6 +38,7 @@ def action_db_create( options = ( { "key_file": None, + "dry_run": False, } | (options or {}) @@ -60,7 +61,10 @@ def action_db_create( ) ) } - ) + ), + { + "dry_run": options["dry_run"], + } ) @@ -69,6 +73,14 @@ def action_mkdir( group_name, options = None ): + options = ( + { + "key_file": None, + "dry_run": False, + } + | + (options or {}) + ) __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli mkdir{{macro_auth}} {{db_path}} {{group_name}}", @@ -77,7 +89,10 @@ def action_mkdir( "group_name": group_name, "macro_auth": macro_auth(options["key_file"]), } - ) + ), + { + "dry_run": options["dry_run"], + } ) @@ -87,6 +102,14 @@ def action_add( member_name, options = None ): + options = ( + { + "key_file": None, + "dry_run": False, + } + | + (options or {}) + ) __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli add{{macro_auth}} {{db_path}} {{entry}}", @@ -95,7 +118,10 @@ def action_add( "entry": compose_entry(group_name, member_name), "macro_auth": macro_auth(options["key_file"]), } - ) + ), + { + "dry_run": options["dry_run"], + } ) @@ -105,6 +131,14 @@ def action_rm( member_name, options = None ): + options = ( + { + "key_file": None, + "dry_run": False, + } + | + (options or {}) + ) __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli rm{{macro_auth}} {{db_path}} {{entry}}", @@ -113,7 +147,10 @@ def action_rm( "entry": compose_entry(group_name, member_name), "macro_auth": macro_auth(options["key_file"]), } - ) + ), + { + "dry_run": options["dry_run"], + } ) @@ -125,6 +162,14 @@ def action_attachment_import( attachment_path, options = None ): + options = ( + { + "key_file": None, + "dry_run": False, + } + | + (options or {}) + ) __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli attachment-import{{macro_auth}} {{db_path}} {{entry}} '{{attachment_label}}' {{attachment_path}}", @@ -135,5 +180,8 @@ def action_attachment_import( "attachment_path": attachment_path, "macro_auth": macro_auth(options["key_file"]), } - ) + ), + { + "dry_run": options["dry_run"], + } ) diff --git a/source/helpers/misc.py b/source/helpers/misc.py index 0ac4647..fdab4df 100644 --- a/source/helpers/misc.py +++ b/source/helpers/misc.py @@ -43,8 +43,19 @@ def directory_create(path): def shell_exec( - command + command, + options = None ): + options = ( + { + "dry_run": False, + } + | + (options or {}) + ) _sys.stderr.write("\n>> %s\n" % command) - _os.system(command) + if (options["dry_run"]): + pass + else: + _os.system(command) diff --git a/source/main.py b/source/main.py index 5d5f8b3..0285c2d 100755 --- a/source/main.py +++ b/source/main.py @@ -11,7 +11,8 @@ import helpers.keepass as __helpers_keepass def action_init( - source_directory + source_directory, + database_file_name ): keepass_db_path = _os.path.join(source_directory, "private_keys.kdbx") keepass_authfile_path = _os.path.join(source_directory, "private_keys.keyx") @@ -37,11 +38,13 @@ def action_key_add( group, name, key_path, + keepass_db_path, options = None ): options = ( { "remove_private_key": False, + "dry_run": False, } | (options or {}) @@ -52,13 +55,15 @@ def action_key_add( __helpers_misc.directory_create(directory_key) ## transfer private key to keepass database if True: - keepass_db_path = _os.path.join(source_directory, "private_keys.kdbx") - keepass_authfile_path = _os.path.join(source_directory, "private_keys.keyx") + # keepass_db_path = _os.path.join(source_directory, "private_keys.kdbx") + # keepass_authfile_path = _os.path.join(source_directory, "private_keys.keyx") + keepass_authfile_path = None # (keepass_db_path + ".auth") __helpers_keepass.action_mkdir( keepass_db_path, group, { "key_file": keepass_authfile_path, + "dry_run": options["dry_run"], } ) __helpers_keepass.action_add( @@ -67,6 +72,7 @@ def action_key_add( name, { "key_file": keepass_authfile_path, + "dry_run": options["dry_run"], } ) __helpers_keepass.action_attachment_import( @@ -77,6 +83,7 @@ def action_key_add( path_key_private, { "key_file": keepass_authfile_path, + "dry_run": options["dry_run"], } ) ## remove private key file @@ -87,7 +94,10 @@ def action_key_add( { "path": path_key_private, } - ) + ), + { + "dry_run": options["dry_run"], + } ) @@ -273,6 +283,12 @@ def main(): metavar = "", help = "options: init | key-add | key-generate | key-remove | put", ) + argument_parser.add_argument( + "-q", + "--dry-run", + action = "store_true", + default = False, + ) argument_parser.add_argument( "-s", "--source-directory", @@ -333,8 +349,10 @@ def main(): args.group, args.name, args.key_path, + args.target_file, { "remove_private_key": args.remove_private_key, + "dry_run": args.dry_run, } ) elif (args.action == "key-generate"):