refactor: move bitwarden functions

This commit is contained in:
2025-10-02 16:22:01 +02:00
parent 8b6a8f37d6
commit fd21d67c43
2 changed files with 24 additions and 21 deletions

View File

@@ -24,3 +24,26 @@ bitwarden_is_locked() {
fi fi
} }
bitwarden_login() {
# Login to Bitwarden
if ! bitwarden_is_authenticated; then
if [ ! -z "${BW_CLIENTID}" ] && [ ! -z "${BW_CLIENTSECRET}" ]; then
echo "Login in to Bitwarden..."
BW_CLIENTID="${BW_CLIENTID}" BW_CLIENTSECRET="${BW_CLIENTSECRET}" BW login --apikey >/dev/null
if [ $? -ne 0 ]; then
echo -e "${BRed}Could not login to Bitwarden. Skipping.${NC}"
fi
else
echo "Skipping Bitwarden authentication, no credentials provided."
fi
fi
if bitwarden_is_authenticated && bitwarden_is_locked; then
if [ ! -z "${BW_PASSWORD}" ]; then
echo "Unlocking Bitwarden vault..."
export BW_SESSION=$(BW unlock --raw ${BW_PASSWORD})
if [ -z "${BW_SESSION}" ]; then
echo -e "${BRed}Could not unlock Bitwarden vault. Skipping.${NC}"
fi
fi
fi
}

View File

@@ -244,27 +244,7 @@ if [ $? -ne 0 ]; then
echo -e "${BRed}Failed to generate grub configuration. Skipping. Be careful !${NC}" echo -e "${BRed}Failed to generate grub configuration. Skipping. Be careful !${NC}"
fi fi
# Login to Bitwarden bitwarden_login
if ! bitwarden_is_authenticated; then
if [ ! -z "${BW_CLIENTID}" ] && [ ! -z "${BW_CLIENTSECRET}" ]; then
echo "Login in to Bitwarden..."
BW_CLIENTID="${BW_CLIENTID}" BW_CLIENTSECRET="${BW_CLIENTSECRET}" BW login --apikey >/dev/null
if [ $? -ne 0 ]; then
echo -e "${BRed}Could not login to Bitwarden. Skipping.${NC}"
fi
else
echo "Skipping Bitwarden authentication, no credentials provided."
fi
fi
if bitwarden_is_authenticated && bitwarden_is_locked; then
if [ ! -z "${BW_PASSWORD}" ]; then
echo "Unlocking Bitwarden vault..."
export BW_SESSION=$(BW unlock --raw ${BW_PASSWORD})
if [ -z "${BW_SESSION}" ]; then
echo -e "${BRed}Could not unlock Bitwarden vault. Skipping.${NC}"
fi
fi
fi
if ! bitwarden_is_locked; then if ! bitwarden_is_locked; then
echo -n "Authenticating with bitwarden... " echo -n "Authenticating with bitwarden... "