Add vault-login script for user authentication

This commit is contained in:
2026-01-20 17:43:37 +01:00
parent aeb0080f7c
commit ba8d65173b

17
bin/vault-login Executable file
View 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 "$@"