mirror of
https://github.com/aljazceru/gna.git
synced 2025-12-17 05:54:27 +01:00
Git pre-push client to set config variable with nostr auth header
Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
19
Readme.md
19
Readme.md
@@ -1,20 +1,7 @@
|
||||
# Client
|
||||
|
||||
Adds to global config:
|
||||
```
|
||||
[http "https://<host>/<owner>/repo"]
|
||||
extraHeader = "Authorization: Nostr $(./create_nostr_auth_header.sh)"
|
||||
|
||||
```
|
||||
|
||||
TODO:
|
||||
- [ ] add signing for header generation
|
||||
- [ ] add id for header generation
|
||||
- [ ] add base64 encofing for header generation
|
||||
- [ ] add key retrieval mechanism
|
||||
- [ ] add script for extendign config file for speicific urls
|
||||
1. add `./nga` to you `$PATH`
|
||||
2. run `nga` and follow instructions
|
||||
|
||||
# Sever
|
||||
TODO:
|
||||
- [ ] Appache config to intercept and verify header (also for ACL)
|
||||
- [ ] script for auto setup with bare repo and ACL
|
||||
TODO
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
command=($BASH_COMMAND)
|
||||
|
||||
if [[ command[0] -eq 'clone']] ; then
|
||||
echo "base64 of the following json:"
|
||||
# {
|
||||
# "id": "<id>",
|
||||
# "pubkey": "<read pub key >",
|
||||
# "content": "",
|
||||
# "kind": 27235,
|
||||
# "created_at": $(date +%s),
|
||||
# "tags": [
|
||||
# ["u", $command[1]],
|
||||
# ["method", $command[0]],
|
||||
# ],
|
||||
# "sig": "<signature>"
|
||||
# }
|
||||
|
||||
elif [[ command[0] -eq 'push' ]]; then
|
||||
commit=$(git rev-parse HEAD)
|
||||
echo "base64 of the following json:"
|
||||
# {
|
||||
# "id": "<id>",
|
||||
# "pubkey": "<read pub key >",
|
||||
# "content": "",
|
||||
# "kind": 27235,
|
||||
# "created_at": $(date +%s),
|
||||
# "tags": [
|
||||
# ["u", $command[1]],
|
||||
# ["method", $command[0]],
|
||||
# ["payload", $commit],
|
||||
# ],
|
||||
# "sig": "<signature>"
|
||||
# }
|
||||
else
|
||||
echo "Error: command not supported" >&2
|
||||
exit 1
|
||||
fi
|
||||
60
nga.sh
Executable file
60
nga.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
HOOK=`cat <<'EOF'
|
||||
#!/bin/sh\n
|
||||
\n
|
||||
url="$2"\n
|
||||
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')\n
|
||||
commit=$(git rev-parse HEAD)\n
|
||||
privKey=$(cat ~/.nostr/key | jq -r '.private_key')\n
|
||||
EVENT="{\"content\":\"\",\"kind\":27235,\"created_at\":$(date +%s),\"tags\":[[\"u\",\"$url\"],[\"method\",\"push\"],[\"payload\",\"$commit\"]]}"\n
|
||||
SIGNED=$(echo -n $EVENT | nak event -sec $privKey)\n
|
||||
NOSTR_AUTH_HEADER=$(echo -n $SIGNED | base64 -w 0)\n
|
||||
git config http.$url.extraHeader "Authorization: Nostr $NOSTR_AUTH_HEADER"\n
|
||||
EOF
|
||||
`
|
||||
|
||||
|
||||
APP_HOME="$HOME/.nostr"
|
||||
SK_PATH="$APP_HOME/key"
|
||||
|
||||
if [ -d $APP_HOME ]; then
|
||||
echo "$APP_HOME already exists. Skipping..."
|
||||
else
|
||||
echo "Creating $APP_HOME"
|
||||
mkdir $APP_HOME
|
||||
fi
|
||||
|
||||
if [ -f $SK_PATH ]; then
|
||||
echo "$SK_PATH already exists. Skipping..."
|
||||
else
|
||||
echo "Please insert you NSEC:"
|
||||
read -s SK
|
||||
echo $(nak decode $SK) > $SK_PATH
|
||||
fi
|
||||
|
||||
read -p "Provide path to git repository or press \"Enter\" to use curent directory:" GIT_REPO
|
||||
GIT_REPO=${GIT_REPO:-.}
|
||||
|
||||
if [ ! -d $GIT_REPO ]; then
|
||||
echo "$GIT_REPO is not a directory. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$GIT_REPO/.git" ]; then
|
||||
echo "$GIT_REPO is not a directory. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Installing git hooks..."
|
||||
if [ -f "$GIT_REPO/.git/hooks/pre-push" ]; then
|
||||
echo "pre-push hook already exists. Skipping..."
|
||||
else
|
||||
echo "Installing pre-push hook..."
|
||||
echo -e $HOOK >> $GIT_REPO/.git/hooks/pre-push
|
||||
chmod +x $GIT_REPO/.git/hooks/pre-push
|
||||
fi
|
||||
|
||||
echo "Done!"
|
||||
|
||||
Reference in New Issue
Block a user