From 6a324e66da622ea608119cbdf52733eecfcb2abe Mon Sep 17 00:00:00 2001 From: Thibault Cohen <47721+titilambert@users.noreply.github.com> Date: Wed, 18 Jan 2023 20:57:21 -0500 Subject: [PATCH] Unlock vault only when it's needed --- src/utils/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utils/utils.py b/src/utils/utils.py index 9c1f543..dd65b55 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -1,4 +1,5 @@ import os +import json import subprocess class BitwardenCommandException(Exception): @@ -8,6 +9,11 @@ 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'] + if status == 'unlocked': + logger.info("Already unlocked") + return token_output = command_wrapper("unlock --passwordenv BW_PASSWORD") tokens = token_output.split('"')[1::2] os.environ["BW_SESSION"] = tokens[1]