Add exemple script to get secret from CLI

This commit is contained in:
bestlibre 2020-05-11 14:51:10 +02:00 committed by GitHub
parent 2348740533
commit 625ddd0a9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

30
cli_get.sh Normal file
View file

@ -0,0 +1,30 @@
#!/bin/bash
set -euo pipefail
deps=(curl jq)
for cmd in "${deps[@]}"; do
which ${cmd} >/dev/null || {
echo "'${cmd}' util is required for this script"
exit 1
}
done
# Get URL from CLI argument
URL=${@:-}
[[ -n $URL ]] || {
echo "Usage: $0 'URL to get the secret'"
exit 1
}
# normalize url and extract parts
URL=${URL/|/%7C}
HOST=${URL%%/\#*}
IDPASS=${URL##*\#}
PASS=${IDPASS##*\%7C}
ID=${IDPASS%%\%7C*}
GETURL=${HOST}/api/get/${ID}
# Get the secret
resp=$(curl -s $GETURL)
# decrypt
deciphertext=$(echo $resp| jq -r ".secret" | openssl aes-256-cbc -base64 -pass "pass:$PASS" -md md5 -d 2> /dev/null)
echo $deciphertext