fetch attachments of items

This commit is contained in:
Nico Angelo 2023-09-29 17:16:12 +02:00
parent 94bc6b10b1
commit 382b6776ce
2 changed files with 15 additions and 4 deletions

View File

@ -1,9 +1,11 @@
import json
from utils.utils import get_secret_from_bitwarden, parse_fields_scope, parse_login_scope
from utils.utils import get_secret_from_bitwarden, get_attachment, parse_fields_scope, parse_login_scope
def bitwarden_lookup(id, scope, field):
if scope == "attachment":
return get_attachment(None, id, field)
_secret_json = get_secret_from_bitwarden(None, id)
if scope == "login":
return parse_login_scope(_secret_json, field)

View File

@ -39,6 +39,10 @@ def sync_bw(logger, force=False):
logger.info(f"Sync successful {status_output}")
def get_attachment(logger, id, name):
return command_wrapper(logger, command=f"get attachment {name} {id}", raw=True)
def unlock_bw(logger):
status_output = command_wrapper(logger, "status", False)
status = status_output['data']['template']['status']
@ -50,17 +54,22 @@ def unlock_bw(logger):
logger.info("Signin successful. Session exported")
def command_wrapper(logger, command, use_success: bool = True):
def command_wrapper(logger, command, use_success: bool = True, raw: bool = False):
system_env = dict(os.environ)
response_flag = "--raw" if raw else "--response"
sp = subprocess.Popen(
[f"bw --response {command}"],
[f"bw {response_flag} {command}"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
shell=True,
env=system_env)
out, err = sp.communicate()
if err:
logger.warn(err)
return None
if raw:
return out.decode(encoding='UTF-8')
if "DEBUG" in system_env:
logger.info(out.decode(encoding='UTF-8'))
resp = json.loads(out.decode(encoding='UTF-8'))