Last active
February 21, 2024 17:57
-
-
Save akmalharith/60c1b90e69dc622131d74c4311e6015c to your computer and use it in GitHub Desktop.
Wrapper to get Bitwarden Secrets Manager's secret by the secret's name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: ./bws-secret-get.sh <SECRET_NAME> | |
set -eo pipefail | |
if [ -z $BWS_ACCESS_TOKEN ]; then | |
>&2 echo "Missing access token. Please set your access token. Eg: export BWS_ACCESS_TOKEN=REPLACEME" | |
exit 1 | |
fi | |
if [ -z "$1" ]; then | |
>&2 echo "No arguments provided. Usage: ./bws-secret-get.sh <SECRET_NAME>" | |
exit 1 | |
fi | |
SECRET_ID=$(bws secret list | jq -r ". | map(select(.key == \"$1\").id)[0]") | |
if [ $SECRET_ID == null ]; then | |
>&2 echo "No secrets exist by the name of $1." | |
exit 1 | |
fi | |
bws secret get $SECRET_ID | jq -r ".value" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment