Add exemple script to get secret from CLI
This commit is contained in:
parent
2348740533
commit
625ddd0a9d
1 changed files with 30 additions and 0 deletions
30
cli_get.sh
Normal file
30
cli_get.sh
Normal 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
|
Loading…
Reference in a new issue