From bfabb222ddb65891117419267522d865c713a013 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 6 Dec 2023 12:02:58 -0500 Subject: [PATCH] Allow error code extraction from GPG by including debug output (#65) * Don't filter GPG debug outputs, but send everything to PassFF --------- Co-authored-by: Thomas Vogt Co-authored-by: Thomas Vogt --- src/passff.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/passff.py b/src/passff.py index da9150e..b45cf2b 100755 --- a/src/passff.py +++ b/src/passff.py @@ -6,6 +6,8 @@ import json import os +import re +import shlex import struct import subprocess import sys @@ -52,6 +54,24 @@ def sendMessage(encodedMessage): sys.stdout.flush() +def setPassGpgOpts(env, opts_dict): + """ Add arguments to PASSWORD_STORE_GPG_OPTS. """ + opts = env.get('PASSWORD_STORE_GPG_OPTS', '') + for opt, value in opts_dict.items(): + re_opt = new_opt = opt + if value is not None: + re_opt = rf"{opt}(?:=|\s+)\S*" + new_opt = ( + f"{opt}={shlex.quote(value)}" + if opt.startswith("--") else + f"{opt} {shlex.quote(value)}" + ) + # If the user's environment sets this opt, remove it. + opts = re.sub(re_opt, '', opts) + opts = f"{new_opt} {opts}" + env['PASSWORD_STORE_GPG_OPTS'] = opts.strip() + + if __name__ == "__main__": # Read message from standard input receivedMessage = getMessage() @@ -93,6 +113,7 @@ if __name__ == "__main__": env["HOME"] = os.path.expanduser('~') for key, val in COMMAND_ENV.items(): env[key] = val + setPassGpgOpts(env, {'--status-fd': '2', '--debug': 'ipc'}) # Set up subprocess params cmd = [COMMAND] + opt_args + ['--'] + pos_args