Implement "list" command

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-01-12 13:11:10 +01:00
parent b5a1d5dc90
commit 801f0ff65c
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5

View file

@ -49,6 +49,16 @@ function hash_hostname() {
echo "$1" | md5sum | cut -d ' ' -f 1 echo "$1" | md5sum | cut -d ' ' -f 1
} }
function list() {
local creds="{}"
for key in $(vault list -format=json secret/docker-credential | jq -r '.[]'); do
creds="$(vault read -field=data -format=json "${PREFIX}/${key}" | jq -c "${creds} + {(.ServerURL): .Username}")"
done
echo "${creds}"
}
function log() { function log() {
[ $NO_LOG -eq 0 ] || return 0 [ $NO_LOG -eq 0 ] || return 0
echo "[$(date +%H:%M:%S)][docker-credential-vault] $@" >&2 echo "[$(date +%H:%M:%S)][docker-credential-vault] $@" >&2
@ -62,6 +72,7 @@ function main() {
case "${1:-}" in case "${1:-}" in
get) get ;; get) get ;;
erase) erase ;; erase) erase ;;
list) list ;;
store) store ;; store) store ;;
*) *)
echo "$(basename $0): Supported are only: get, erase, store (called '${1:-}')" >&2 echo "$(basename $0): Supported are only: get, erase, store (called '${1:-}')" >&2