chore: add Bitwarden credentials helper
This commit is contained in:
parent
91a029f4c3
commit
87d1b84cb8
1 changed files with 47 additions and 0 deletions
47
private_dot_local/bin/executable_git-credential-rbw
Normal file
47
private_dot_local/bin/executable_git-credential-rbw
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/opt/homebrew/Cellar/bash/5.2.21/bin/bash
|
||||
|
||||
# rbw git-credential helper
|
||||
# Based on https://github.com/lastpass/lastpass-cli/blob/master/contrib/examples/git-credential-lastpass
|
||||
|
||||
# A credential helper for git to retrieve usernames and passwords from rbw.
|
||||
# For general usage, see https://git-scm.com/docs/gitcredentials.
|
||||
# Here's a quick version:
|
||||
# 1. Put this somewhere in your path.
|
||||
# 2. git config --global credential.helper rbw
|
||||
|
||||
declare -A params
|
||||
|
||||
if [ "x$1" == "xget" ]; then
|
||||
read line
|
||||
while [ -n "$line" ]; do
|
||||
key=${line%%=*}
|
||||
value=${line#*=}
|
||||
params[$key]=$value
|
||||
read line
|
||||
done
|
||||
|
||||
if [ "x${params['protocol']}" != "xhttps" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -z "${params["host"]}" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
rbw ls > /dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Please login to rbw to use git credential helper" > /dev/stderr
|
||||
exit
|
||||
fi
|
||||
|
||||
user=`rbw get --full ${params["host"]} | grep "Username:" | cut -d' ' -f2-`
|
||||
pass=`rbw get ${params["host"]}`
|
||||
|
||||
if [ "x$user" == "x" ] || [ "x$pass" == "x" ]; then
|
||||
echo "Couldn't find host in rbw DB." > /dev/stderr
|
||||
exit
|
||||
fi
|
||||
|
||||
echo username=$user
|
||||
echo password=$pass
|
||||
fi
|
Loading…
Reference in a new issue