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:
parent
2348740533
commit
b44139f777
1 changed files with 28 additions and 0 deletions
28
cli_get.sh
Normal file
28
cli_get.sh
Normal 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
|
Loading…
Reference in a new issue