Add vault-login script for user authentication
This commit is contained in:
17
bin/vault-login
Executable file
17
bin/vault-login
Executable file
@@ -0,0 +1,17 @@
|
||||
# Check, if we are sourced, that's a requirement for this script
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
echo "This script must be sourced, not executed directly."
|
||||
echo "Use: source bin/vault-login"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# v_login function may be added to .bashrc, .zprofile, etc.
|
||||
function v_login() {
|
||||
local VAULT_USERNAME=${1:-adminslawek}
|
||||
vault login -format=json -method=userpass username="$VAULT_USERNAME" |
|
||||
jq -r '.auth | [.client_token, .accessor] | @tsv' | read -r VAULT_TOKEN TOKEN_ACCESSOR
|
||||
echo "Logged in as $VAULT_USERNAME (Token accessor: $TOKEN_ACCESSOR)"
|
||||
export VAULT_TOKEN TOKEN_ACCESSOR
|
||||
}
|
||||
|
||||
v_login "$@"
|
||||
Reference in New Issue
Block a user