This commit is contained in:
Johan Rooijakkers 2025-02-26 17:49:53 +01:00
parent bcebea6713
commit b22ebd4ac7

View File

@ -28,7 +28,7 @@ runs:
steps: steps:
- name: Configure Bitwarden Server - name: Configure Bitwarden Server
shell: sh shell: sh
run: bw config server ${{ inputs.server }} run: bw config server "${{ inputs.server }}"
- name: Unlock Vault - name: Unlock Vault
shell: sh shell: sh
@ -36,36 +36,34 @@ runs:
bw login --apikey bw login --apikey
echo "BW_SESSION=$(bw unlock '${{ inputs.password }}' --raw)" >> "$GITHUB_ENV" echo "BW_SESSION=$(bw unlock '${{ inputs.password }}' --raw)" >> "$GITHUB_ENV"
env: env:
BW_CLIENTID: ${{ inputs.client-id }} BW_CLIENTID: "${{ inputs.client-id }}"
BW_CLIENTSECRET: ${{ inputs.client-secret }} BW_CLIENTSECRET: "${{ inputs.client-secret }}"
- name: Retrieve Requested Secrets - name: Retrieve Requested Secrets
shell: bash shell: bash
run: | run: |
if [[ -z "$BW_SESSION" ]]; then if [[ -z "$BW_SESSION" ]]; then
echo "❌ BW_SESSION is not set. Please log in to Bitwarden first." echo "❌ BW_SESSION is not set. Please log in to Bitwarden first."
exit 1 exit 1
fi fi
echo "${{ inputs.secrets }}" | while IFS='>' read -r SECRET_ID ENV_VAR; do
echo "${{ inputs.secrets }}" | while IFS='>' read -r SECRET_ID ENV_VAR; do
# Trim whitespace
SECRET_ID=$(echo "$SECRET_ID" | xargs) SECRET_ID=$(echo "$SECRET_ID" | xargs)
ENV_VAR=$(echo "$ENV_VAR" | xargs) ENV_VAR=$(echo "$ENV_VAR" | xargs)
# Skip empty or invalid lines # Skip empty or invalid lines
if [[ -z "$SECRET_ID" || -z "$ENV_VAR" ]]; then if [[ -z "$SECRET_ID" || -z "$ENV_VAR" ]]; then
continue continue
fi fi
echo "🔍 Retrieving secret: $SECRET_ID..." echo "🔍 Retrieving secret: $SECRET_ID..."
SECRET_VALUE=$(bw get notes "$SECRET_ID" --session "$BW_SESSION" 2>/dev/null) SECRET_VALUE=$(bw get notes "$SECRET_ID" --session "$BW_SESSION" 2>/dev/null)
if [[ -n "$SECRET_VALUE" ]]; then if [[ -n "$SECRET_VALUE" ]]; then
echo "$ENV_VAR=$SECRET_VALUE" >> "$GITHUB_ENV" echo "$ENV_VAR=\"$SECRET_VALUE\"" >> "$GITHUB_ENV"
echo "✅ Stored $SECRET_ID in $ENV_VAR" echo "✅ Stored $SECRET_ID in $ENV_VAR"
else else
echo "❌ Failed to retrieve secret: $SECRET_ID" echo "❌ Failed to retrieve secret: $SECRET_ID"
fi fi
done done