routes: disable git push
This commit is contained in:
parent
abe300762f
commit
f8829d9e14
1 changed files with 9 additions and 6 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"github.com/alexedwards/flow"
|
"github.com/alexedwards/flow"
|
||||||
"github.com/sosedoff/gitkit"
|
"github.com/sosedoff/gitkit"
|
||||||
|
@ -16,20 +15,24 @@ type depsWrapper struct {
|
||||||
gitsvc *gitkit.Server
|
gitsvc *gitkit.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks for gitprotocol-http(5) specific query params; if found, passes
|
// Checks for gitprotocol-http(5) specific smells; if found, passes
|
||||||
// the request on to the git http service, else render the web frontend.
|
// the request on to the git http service, else render the web frontend.
|
||||||
func (dw *depsWrapper) Multiplex(w http.ResponseWriter, r *http.Request) {
|
func (dw *depsWrapper) Multiplex(w http.ResponseWriter, r *http.Request) {
|
||||||
path := flow.Param(r.Context(), "...")
|
path := flow.Param(r.Context(), "...")
|
||||||
name := flow.Param(r.Context(), "name")
|
name := flow.Param(r.Context(), "name")
|
||||||
name = filepath.Clean(name)
|
name = filepath.Clean(name)
|
||||||
gitCommand := regexp.MustCompile(`git-(upload|receive)-pack`)
|
|
||||||
|
|
||||||
if path == "info/refs" && gitCommand.MatchString(r.URL.RawQuery) && r.Method == "GET" {
|
if r.URL.RawQuery == "service=git-receive-pack" {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
w.Write([]byte("no pushing allowed!"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if path == "info/refs" && r.URL.RawQuery == "service=git-upload-pack" && r.Method == "GET" {
|
||||||
dw.gitsvc.ServeHTTP(w, r)
|
dw.gitsvc.ServeHTTP(w, r)
|
||||||
} else if gitCommand.MatchString(path) && r.Method == "POST" {
|
} else if path == "git-upload-pack" && r.Method == "POST" {
|
||||||
dw.gitsvc.ServeHTTP(w, r)
|
dw.gitsvc.ServeHTTP(w, r)
|
||||||
} else if r.Method == "GET" {
|
} else if r.Method == "GET" {
|
||||||
log.Println("index:", r.URL.String())
|
|
||||||
dw.actualDeps.RepoIndex(w, r)
|
dw.actualDeps.RepoIndex(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue