Git-proxy includes a REST-based API for managing certain aspects of repositories & git operations (pushes, pulls). This API is fronted by a web UI. The web interface is under active development and is missing some key features to allow Git Proxy to push commits through it.
The below procedure will allow you to "authorize" a push through git-proxy using the included API. The following assumptions are made and must be modified to match your deployment of git-proxy:
- Both the proxy & API server is running. This is the default behaviour.
- git-proxy is running on
localhost
on ports 8000 (proxy) and 8080 (API) - The instructions from the quick start have been followed. This includes modifying the configuration to add a new repository to the
authorisedList
. For this doc, we assume the upstream repository is https://github.com/RBC/git-proxy. curl
is installed
-
Attempted to push a new commit or branch through git-proxy. Expect to receive an error message similar to the output below. Note the "tracking id" value, which is the last part of the URL:
$ git remote -v origin https://github.com/finos/git-proxy.git (fetch) origin https://github.com/finos/git-proxy.git (push) proxy http://localhost:8000/RBC/git-proxy.git (fetch) proxy http://localhost:8000/RBC/git-proxy.git (push) $ git push proxy chore/test-branch Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 10 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 470 bytes | 470.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 remote: ERR Your push request is waiting authorisation, tracking id http://localhost:8080/requests/0000000000000000000000000000000000000000__79b4d8953cbc324bcc1eb53d6412ff89666c241f fatal: the remote end hung up unexpectedly fatal: the remote end hung up unexpectedly error: failed to push some refs to 'http://localhost:8000/RBC/git-proxy.git' $ _request_id="0000000000000000000000000000000000000000__79b4d8953cbc324bcc1eb53d6412ff89666c241f"
-
Authenticate to the API using the default
admin/admin
credentials and obtain a cookie. The cookie value is saved to a file calledgit-proxy-cookie
.curl -H "Content-Type: application/json" -c git-proxy-cookie -X POST \ -d '{"username":"admin","password":"admin"}' http://localhost:8080/auth/login
-
Validate that the request is received and exists in the database. This request should succeed and you should get back a JSON blob returned in the response. Note that we are reusing the cookie generated from step 2:
curl -b ./git-proxy-cookie http://localhost:8080/api/v1/push/${_request_id}
-
Send a POST to authorise the push:
curl -b ./git-proxy-cookie \ -X POST http://localhost:8080/api/v1/push/${_request_id}/authorise
-
Push the new code again. It should be now successfully push through git-proxy:
$ git push proxy chore/test-branch Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 10 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 470 bytes | 470.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (2/2), completed with 2 local objects. remote: remote: Create a pull request for 'chore/test-branch' on GitHub by visiting: remote: https://github.com/RBC/git-proxy/pull/new/chore/test-branch remote: To http://localhost:8000/RBC/git-proxy.git * [new branch] chore/test-branch -> chore/test-branch