Skip to content

Instantly share code, notes, and snippets.

@akmalharith
Last active February 21, 2024 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akmalharith/60c1b90e69dc622131d74c4311e6015c to your computer and use it in GitHub Desktop.
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.
#!/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