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.exceptions import FaultUnavailable
from bundlewrap.utils import Fault from bundlewrap.utils import Fault
from bundlewrap.utils.dict import merge_dict
from bundlewrap.utils.text import bold, yellow from bundlewrap.utils.text import bold, yellow
from bundlewrap.utils.ui import io 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' DUMMY_MODE = environ.get('BW_PASS_DUMMY_MODE', '0') == '1'
cache = {} cache = {}
def _get_contents_from_pass(identifier: str): def _get_contents_from_pass(identifier: str):
try: try:
return cache[identifier] return cache[identifier]
@ -26,9 +31,7 @@ def _get_contents_from_pass(identifier: str):
try: try:
pass_output = check_output( pass_output = check_output(
['pass', 'show', identifier], ['pass', 'show', identifier],
env={ env=ENVIRONMENT,
'PASSWORD_STORE_DIR': PASSWORD_STORE_DIR,
}
).decode('UTF-8').splitlines() ).decode('UTF-8').splitlines()
except FileNotFoundError: except FileNotFoundError:
raise FaultUnavailable('pass not found') raise FaultUnavailable('pass not found')