autopep8 and bump alpine
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Tobias Trabelsi
2023-04-21 14:39:06 +02:00
parent 4f92bfe86a
commit 3bb40cdcb4
7 changed files with 147 additions and 46 deletions

View File

@ -2,12 +2,15 @@ import os
import json
import subprocess
class BitwardenCommandException(Exception):
pass
def get_secret_from_bitwarden(id):
return command_wrapper(command=f"get item {id}")
def unlock_bw(logger):
status_output = command_wrapper("status")
status = json.loads(status_output)['status']
@ -19,17 +22,26 @@ def unlock_bw(logger):
os.environ["BW_SESSION"] = tokens[1]
logger.info("Signin successful. Session exported")
def command_wrapper(command):
system_env = dict(os.environ)
sp = subprocess.Popen([f"bw {command}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True, env=system_env)
sp = subprocess.Popen(
[f"bw {command}"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
shell=True,
env=system_env)
out, err = sp.communicate()
if err:
raise BitwardenCommandException(err)
return out.decode(encoding='UTF-8')
def parse_login_scope(secret_json, key):
return secret_json["login"][key]
def parse_fields_scope(secret_json, key):
if "fields" not in secret_json:
return None