preserve environment variables when calling pass show

This commit is contained in:
Franzi 2021-07-02 16:26:53 +02:00
parent c814b8c103
commit d1277326df
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -4,14 +4,19 @@ from subprocess import check_output, CalledProcessError
from bundlewrap.exceptions import FaultUnavailable
from bundlewrap.utils import Fault
from bundlewrap.utils.dict import merge_dict
from bundlewrap.utils.text import bold, yellow
from bundlewrap.utils.ui import io
PASSWORD_STORE_DIR = expanduser(environ.get('BW_PASS_DIR', '~/.password-store'))
ENVIRONMENT = merge_dict(environ, {
'PASSWORD_STORE_DIR': expanduser(environ.get('BW_PASS_DIR', '~/.password-store')).
})
DUMMY_MODE = environ.get('BW_PASS_DUMMY_MODE', '0') == '1'
cache = {}
def _get_contents_from_pass(identifier: str):
try:
return cache[identifier]
@ -26,9 +31,7 @@ def _get_contents_from_pass(identifier: str):
try:
pass_output = check_output(
['pass', 'show', identifier],
env={
'PASSWORD_STORE_DIR': PASSWORD_STORE_DIR,
}
env=ENVIRONMENT,
).decode('UTF-8').splitlines()
except FileNotFoundError:
raise FaultUnavailable('pass not found')