Create initial credential helper
This commit is contained in:
commit
a1a77b7daf
1 changed files with 49 additions and 0 deletions
49
git-credential-gbw
Executable file
49
git-credential-gbw
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Function to fetch username and password from Bitwarden
|
||||||
|
get_credentials() {
|
||||||
|
local item_name=$1
|
||||||
|
|
||||||
|
# Fetch the login item
|
||||||
|
item=$(bw get item "$item_name" --session "$BW_SESSION")
|
||||||
|
|
||||||
|
# Extract username and password
|
||||||
|
username=$(echo "$item" | jq -r '.login.username')
|
||||||
|
password=$(echo "$item" | jq -r '.login.password')
|
||||||
|
|
||||||
|
echo -e "username=$username\npassword=$password"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main logic to handle Git credential helper protocol
|
||||||
|
while read -r line; do
|
||||||
|
case "$line" in
|
||||||
|
protocol=*)
|
||||||
|
protocol=${line#protocol=}
|
||||||
|
;;
|
||||||
|
host=*)
|
||||||
|
host=${line#host=}
|
||||||
|
;;
|
||||||
|
username=*)
|
||||||
|
username=${line#username=}
|
||||||
|
;;
|
||||||
|
password=*)
|
||||||
|
password=${line#password=}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$protocol" ] || [ -z "$host" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Define your Bitwarden item name
|
||||||
|
ITEM_NAME="$host"
|
||||||
|
|
||||||
|
# Fetch the credentials
|
||||||
|
credentials=$(get_credentials "$ITEM_NAME")
|
||||||
|
|
||||||
|
# Output the credentials in the format Git expects
|
||||||
|
echo "$credentials"
|
||||||
|
|
Loading…
Reference in a new issue