Skip to content

Instantly share code, notes, and snippets.

@aelindeman
Last active July 6, 2018 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aelindeman/a8f1ad0e1095fd7437af147fc3a3277e to your computer and use it in GitHub Desktop.
Save aelindeman/a8f1ad0e1095fd7437af147fc3a3277e 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