forked from tangled.org/core
this repo has no description

appview,knotserver: pass repo handle to knot when proxying git ops

Adds 'x-tangled-repo-owner-handle' header when proxying git requests to
the knot. This allows knotserver to attempt to suggest the correct
git+ssh URL when rejecting a HTTP git push.

Changed files
+16
appview
state
knotserver
+3
appview/state/git_http.go
···
// Copy original headers
proxyReq.Header = r.Header
+
repoOwnerHandle := chi.URLParam(r, "user")
+
proxyReq.Header.Add("x-tangled-repo-owner-handle", repoOwnerHandle)
+
// Execute request
resp, err := client.Do(proxyReq)
if err != nil {
+13
knotserver/git.go
···
"io"
"net/http"
"path/filepath"
+
"strings"
securejoin "github.com/cyphar/filepath-securejoin"
"github.com/go-chi/chi/v5"
···
w.WriteHeader(http.StatusForbidden)
fmt.Fprintf(w, "Welcome to Tangled.sh!\n\nPushes are currently only supported over SSH.")
+
+
// If the appview gave us the repository owner's handle we can attempt to
+
// construct the correct ssh url.
+
ownerHandle := r.Header.Get("x-tangled-repo-owner-handle")
+
if ownerHandle != "" && !strings.ContainsAny(ownerHandle, ":") {
+
hostname := d.c.Server.Hostname
+
if strings.Contains(hostname, ":") {
+
hostname = strings.Split(hostname, ":")[0]
+
}
+
+
fmt.Fprintf(w, " Try:\ngit remote set-url --push origin git@%s:%s/%s\n\n... and push again.", hostname, ownerHandle, unqualifiedRepoName)
+
}
fmt.Fprintf(w, "\n\n")
}