Add example script to get secret from CLI (#18)

commit a8a28a4c327bfe74244f32444ed173e65ff35db3
Author: Knut Ahlers <knut@ahlers.me>
Date:   Tue Jun 2 14:55:31 2020 +0200

    Adjust coding-style to match other scripts, simplify a little

    Signed-off-by: Knut Ahlers <knut@ahlers.me>

commit 625ddd0a9d
Author: bestlibre <github@bestlibre.org>
Date:   Mon May 11 14:51:10 2020 +0200

    Add exemple script to get secret from CLI

closes #18

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-06-02 14:56:25 +02:00
parent 2348740533
commit b44139f777
No known key found for this signature in database
GPG Key ID: DC2729FDD34BE99E

28
cli_get.sh Normal file
View File

@ -0,0 +1,28 @@
#!/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="${1:-}"
[[ -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}"
# fetch secret and decrypt to STDOUT
curl -sSf "${geturl}" | jq -r ".secret" |
openssl aes-256-cbc -base64 -pass "pass:${pass}" -md md5 -d 2>/dev/null