-
Notifications
You must be signed in to change notification settings - Fork 1
102 lines (89 loc) · 3.76 KB
/
bitwarden-vault-stats.yaml
File metadata and controls
102 lines (89 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: "🔐 Generating Bitwarden Vault Stats ..."
on: [workflow_dispatch]
jobs:
build:
name: "📊 Vault Stats, Members, and Send"
runs-on: ubuntu-latest
steps:
- name: "🔑 Get Bitwarden Secrets"
uses: bitwarden/sm-action@v2
with:
access_token: ${{ secrets.BW_ACCESS_TOKEN }}
base_url: https://vault.bitwarden.com
secrets: |
9a09d304-790e-40ec-be5a-b15c008f30af > MASTER_PASSWORD
29adc4e7-1a97-4e4f-9644-b40500a6a4b2 > BW_CLIENTID
81404c9c-3d9c-4ddd-a32e-b40500a6c212 > BW_CLIENTSECRET
id: bitwarden-secrets
- name: "⚙️ Install Bitwarden CLI (Standalone)"
run: |
set -e
curl -L "https://vault.bitwarden.com/download/?app=cli&platform=linux" -o bw.zip
unzip bw.zip
sudo mv bw /usr/local/bin/
bw --version # Verify installation
- name: "🔐 Log in to Bitwarden CLI"
run: |
set -e
bw login --apikey
env:
BW_CLIENTID: ${{ steps.bitwarden-secrets.outputs.BW_CLIENTID }}
BW_CLIENTSECRET: ${{ steps.bitwarden-secrets.outputs.BW_CLIENTSECRET }}
shell: bash
- name: "🔓 Unlock Vault"
run: |
set -e
BW_SESSION=$(bw unlock --passwordenv MASTER_PASSWORD --raw)
echo "BW_SESSION=$BW_SESSION" >> $GITHUB_ENV
EMAIL=$(bw status --session "$BW_SESSION" | jq -r '.userEmail')
echo "EMAIL=$EMAIL" >> $GITHUB_ENV
env:
MASTER_PASSWORD: ${{ steps.bitwarden-secrets.outputs.MASTER_PASSWORD }}
shell: bash
- name: "📊 Count Specific Item Types"
run: |
set -e
BW_SESSION="${{ env.BW_SESSION }}"
# Function to count item types
count_items() {
local type=$1
bw list items --session $BW_SESSION | jq "[.[] | select(.type == $type)] | length"
}
# Declare an associative array to store item types
declare -A item_types=(
[LOGIN_COUNT]=1
[CARD_COUNT]=3
[IDENTITY_COUNT]=4
[NOTE_COUNT]=2
[SSH_KEY_COUNT]=5
)
# Count item types and export to GITHUB_ENV and shell
for item in "${!item_types[@]}"; do
count=$(count_items "${item_types[$item]}")
echo "$item=$count" >> $GITHUB_ENV
export $item=$count
done
# Print the counts
echo "======================"
echo "🔐 Bitwarden Item Counts"
echo "======================"
echo "🔑 Logins: $LOGIN_COUNT"
echo "💳 Cards: $CARD_COUNT"
echo "🆔 Identities: $IDENTITY_COUNT"
echo "📝 Secure Notes: $NOTE_COUNT"
echo "🔐 SSH Keys: $SSH_KEY_COUNT"
shell: bash
- name: "📤 Create a Bitwarden Send with Item Counts"
run: |
set -e
BW_SESSION="${{ env.BW_SESSION }}"
EMAIL="${{ env.EMAIL }}"
# Format the stats message
STATS=$(printf "Bitwarden Vault Stats\n=====================\n\nAccount: %s\n\n🔑 Logins: %s\n💳 Cards: %s\n🆔 Identities: %s\n📝 Secure Notes: %s\n🔐 SSH Keys: %s" "$EMAIL" "${{ env.LOGIN_COUNT }}" "${{ env.CARD_COUNT }}" "${{ env.IDENTITY_COUNT }}" "${{ env.NOTE_COUNT }}" "${{ env.SSH_KEY_COUNT }}")
# Send the stats and capture the result
SEND_RESULT=$(bw send -n "Bitwarden Item Counts ($EMAIL)" -d 7 --hidden "$STATS" --session $BW_SESSION)
# Parse the accessUrl from the result
ACCESS_URL=$(echo $SEND_RESULT | jq -r '.accessUrl')
# Display the URL
echo "🔗 Bitwarden Send URL for $EMAIL: $ACCESS_URL"
shell: bash