DEV Community

Cover image for Bash Functions for Vault
πŸ¦„N BπŸ›‘
πŸ¦„N BπŸ›‘

Posted on

Bash Functions for Vault

For those of us who've used Vault a lot, we all know and love the Vault CLI.

But, well, it has its quirks. If not outright shortcomings.

And if something isn't working in the CLI, my first instinct is to check the API, using a curl command from the Vault API Docs. But that takes a lot of typing.

Here's how to solve that:

  • Bash Aliases
  • Bash Functions

It's like you can build your own custom CLI commands. If the first thing that comes to your mind when you read that is, "Why. Why would anyone want that." You haven't experienced enough pain. Close this blog and come back to it later when you've lain awake at night haunted by WALs.

Anyway, back to the Bash Aliases and Bash Functions for Vault. I'll give a couple examples of each.

Bash Aliases for Vault

tknchk

## This alias gets you your token's permissions, and assumes you have the jq CLI utility installed
alias tknchk='curl -s --header "X-Vault-Namespace: $VAULT_NAMESPACE" --header "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/sys/internal/ui/resultant-acl | jq'
Enter fullscreen mode Exit fullscreen mode

getVaultMounts

## This alias gets the mounts on the current Vault
alias getvaultmounts='curl -s --header "X-Vault-Namespace: $VAULT_NAMESPACE" --header "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/sys/mounts'
Enter fullscreen mode Exit fullscreen mode

Bash Functions for Vault

getVaultToken

## Get the damn Vault Token without needing to show it on the screen or do the whole set +o history thing
export VAULT_TOKEN
function getVaultToken(){
    read -rsp "Enter the damn Vault Token:" entered_value
    export VAULT_TOKEN="$entered_value"
    echo ""
Enter fullscreen mode Exit fullscreen mode

muhVault

function muhVault(){
echo "____   ____            .__   __    ___________.__              ._.
\   \ /   /____   __ __|  |_/  |_  \__    ___/|__| _____   ____| |
 \   Y   /\__  \ |  |  \  |\   __\   |    |   |  |/     \_/ __ \ |
  \     /  / __ \|  |  /  |_|  |     |    |   |  |  Y Y  \  ___/\|
   \___/  (____  /____/|____/__|     |____|   |__|__|_|  /\___  >_
               \/                                      \/     \/\/"

}
Enter fullscreen mode Exit fullscreen mode

Well, there you go!

Which of these did you find useful? Got any of your own that you use?

Top comments (0)