Skip to content

Commit

Permalink
Allow error code extraction from GPG by including debug output (#65)
Browse files Browse the repository at this point in the history
* Don't filter GPG debug outputs, but send everything to PassFF

---------

Co-authored-by: Thomas Vogt <tuxor1337@users.noreply.github.com>
Co-authored-by: Thomas Vogt <acc-framagit@tovotu.de>
  • Loading branch information
3 people authored Dec 6, 2023
1 parent 91ae64f commit bfabb22
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/passff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import json
import os
import re
import shlex
import struct
import subprocess
import sys
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -93,6 +113,7 @@ def sendMessage(encodedMessage):
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
Expand Down

0 comments on commit bfabb22

Please sign in to comment.