diff options
author | Elizabeth Alexander Hunt <me@liz.coffee> | 2025-05-07 18:10:57 -0700 |
---|---|---|
committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2025-05-07 18:10:57 -0700 |
commit | b8ffbfe27eae919750ef4d3facf02393d1004287 (patch) | |
tree | 78a22cffd1a387a1f482aac78a93fb951dcc81bb /playbooks/roles/ci/templates/volumes/laminar/scripts/get_secret | |
parent | 59417f290463d3aabbf3ec2ab8e75703928db217 (diff) | |
download | infra-b8ffbfe27eae919750ef4d3facf02393d1004287.tar.gz infra-b8ffbfe27eae919750ef4d3facf02393d1004287.zip |
.git was corrupted on the machine i worked on these many commits. so here it is all at once :P
Diffstat (limited to 'playbooks/roles/ci/templates/volumes/laminar/scripts/get_secret')
-rwxr-xr-x | playbooks/roles/ci/templates/volumes/laminar/scripts/get_secret | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/playbooks/roles/ci/templates/volumes/laminar/scripts/get_secret b/playbooks/roles/ci/templates/volumes/laminar/scripts/get_secret new file mode 100755 index 0000000..2774651 --- /dev/null +++ b/playbooks/roles/ci/templates/volumes/laminar/scripts/get_secret @@ -0,0 +1,35 @@ +#!/bin/bash + +bw config server "https://{{ passwd_domain }}" +bw login --apikey --quiet +bw unlock --passwordenv BW_PASSWORD --quiet + +# https://github.com/bitwarden/clients/issues/3366 +function bw_get() { + local pwd + local count + local organisation=${2:-notnull} + + count=$(bw list items --pretty --organizationid ${organisation} | jq -r '[.[] | select(.name=="'$1'")] | length') + + if [[ "$count" -gt 1 ]]; then + echo "Multiple items found" + return 1 + fi + + if [[ "$count" -lt 1 ]]; then + echo "No items found" + return 1 + fi + + pwd=$(bw list items --pretty --organizationid ${organisation} | jq -r '.[] | select(.name=="'$1'")') + if [[ -z "$pwd" ]]; then + echo "Password not found" + return 1 + fi + + echo "$pwd" +} + +bw_get $@ +bw --quiet lock |