Skip to content

Commit bfabb22

Browse files
drmoosetuxor1337Thomas Vogt
authored
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 <[email protected]> Co-authored-by: Thomas Vogt <[email protected]>
1 parent 91ae64f commit bfabb22

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/passff.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import json
88
import os
9+
import re
10+
import shlex
911
import struct
1012
import subprocess
1113
import sys
@@ -52,6 +54,24 @@ def sendMessage(encodedMessage):
5254
sys.stdout.flush()
5355

5456

57+
def setPassGpgOpts(env, opts_dict):
58+
""" Add arguments to PASSWORD_STORE_GPG_OPTS. """
59+
opts = env.get('PASSWORD_STORE_GPG_OPTS', '')
60+
for opt, value in opts_dict.items():
61+
re_opt = new_opt = opt
62+
if value is not None:
63+
re_opt = rf"{opt}(?:=|\s+)\S*"
64+
new_opt = (
65+
f"{opt}={shlex.quote(value)}"
66+
if opt.startswith("--") else
67+
f"{opt} {shlex.quote(value)}"
68+
)
69+
# If the user's environment sets this opt, remove it.
70+
opts = re.sub(re_opt, '', opts)
71+
opts = f"{new_opt} {opts}"
72+
env['PASSWORD_STORE_GPG_OPTS'] = opts.strip()
73+
74+
5575
if __name__ == "__main__":
5676
# Read message from standard input
5777
receivedMessage = getMessage()
@@ -93,6 +113,7 @@ def sendMessage(encodedMessage):
93113
env["HOME"] = os.path.expanduser('~')
94114
for key, val in COMMAND_ENV.items():
95115
env[key] = val
116+
setPassGpgOpts(env, {'--status-fd': '2', '--debug': 'ipc'})
96117

97118
# Set up subprocess params
98119
cmd = [COMMAND] + opt_args + ['--'] + pos_args

0 commit comments

Comments
 (0)