import helpers.misc as __helpers_misc def compose_entry( group_name, member_name ): return __helpers_misc.string_coin( "{{group}}/{{member}}", { "group": group_name, "member": member_name, } ) def macro_auth( key_file ): return ( "" if (key_file is None) else __helpers_misc.string_coin( " --no-password --key-file={{authfile_path}}", { "authfile_path": key_file, } ) ) def action_db_create( db_path, options = None ): options = ( { "key_file": None, } | (options or {}) ) __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli db-create{{macro_auth}} {{db_path}}", { "db_path": db_path, "macro_auth": ( "" if (options["key_file"] is None) else __helpers_misc.string_coin( " --set-key-file={{authfile_path}}", { "authfile_path": options["key_file"], } ) ) } ) ) def action_mkdir( db_path, group_name, options = None ): __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli mkdir{{macro_auth}} {{db_path}} {{group_name}}", { "db_path": db_path, "group_name": group_name, "macro_auth": macro_auth(options["key_file"]), } ) ) def action_add( db_path, group_name, member_name, options = None ): __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli add{{macro_auth}} {{db_path}} {{entry}}", { "db_path": db_path, "entry": compose_entry(group_name, member_name), "macro_auth": macro_auth(options["key_file"]), } ) ) def action_rm( db_path, group_name, member_name, options = None ): __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli rm{{macro_auth}} {{db_path}} {{entry}}", { "db_path": db_path, "entry": compose_entry(group_name, member_name), "macro_auth": macro_auth(options["key_file"]), } ) ) def action_attachment_import( db_path, group_name, member_name, attachment_label, attachment_path, options = None ): __helpers_misc.shell_exec( __helpers_misc.string_coin( "keepassxc-cli attachment-import{{macro_auth}} {{db_path}} {{entry}} '{{attachment_label}}' {{attachment_path}}", { "db_path": db_path, "entry": compose_entry(group_name, member_name), "attachment_label": attachment_label, "attachment_path": attachment_path, "macro_auth": macro_auth(options["key_file"]), } ) )