Skip to content

Instantly share code, notes, and snippets.

@Mike-Dunton
Forked from aelindeman/vault-copy-unwrap.sh
Created July 6, 2018 21:43
Show Gist options
  • Save Mike-Dunton/394ff436d2bc04e242d9e8238ccb0890 to your computer and use it in GitHub Desktop.
Save Mike-Dunton/394ff436d2bc04e242d9e8238ccb0890 to your computer and use it in GitHub Desktop.
vault with copy, move, and token-unwrap-to-path
#!/bin/bash
set -eo pipefail
export VAULT_BIN="$HOME/.local/bin/vault-0.10.3" # or wherever you've installed vault
oopsie() {
echo "usage: $*"
exit 1
}
vault_copy() {
"$VAULT_BIN" read -format=json -field=data "$1" | "$VAULT_BIN" write -format=json "$2" -
}
vault_unwrap_to() {
"$VAULT_BIN" unwrap -format=json -field=data "$1" | "$VAULT_BIN" write -format=json "$2" -
}
case "$1" in
move|mv)
if [ "$#" -ne 3 ] || [ "$2" == "help" ]; then oopsie "vault move <from> <to>"; fi
vault_copy "$2" "$3"
vault delete "$2"
;;
copy|cp)
if [ "$#" -ne 3 ] || [ "$2" == "help" ]; then oopsie "vault copy <from> <to>"; fi
vault_copy "$2" "$3"
;;
unwrap-to-path)
if [ "$#" -ne 3 ] || [ "$2" == "help" ]; then oopsie "vault unwrap-to-path <token> <path>"; fi
vault_unwrap_to "$2" "$3"
;;
*)
"$VAULT_BIN" "$@"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment