Commit 5f44f59c authored by Alain Takoudjou's avatar Alain Takoudjou

NXD: fix patches to match changes on gitlab-workhorse up to v1.3.0

helper method: helper.Fail500 now require 3 arguments, the second argument is now an *http.Request. See: 3aaadb1b
parent 6d08450d
...@@ -243,7 +243,7 @@ type testDownloadOkViaSendArchive struct { ...@@ -243,7 +243,7 @@ type testDownloadOkViaSendArchive struct {
func (aok *testDownloadOkViaSendArchive) Inject(w http.ResponseWriter, r *http.Request, sendData string) { func (aok *testDownloadOkViaSendArchive) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
var param struct{ RepoPath string } var param struct{ RepoPath string }
if err := aok.Unpack(&param, sendData); err != nil { if err := aok.Unpack(&param, sendData); err != nil {
helper.Fail500(w, fmt.Errorf("testDownloadOkViaSendArchive: unpack sendData: %v", err)) helper.Fail500(w, r, fmt.Errorf("testDownloadOkViaSendArchive: unpack sendData: %v", err))
return return
} }
...@@ -283,8 +283,9 @@ func (a *API) verifyDownloadAccess(project string, user *url.Userinfo, query str ...@@ -283,8 +283,9 @@ func (a *API) verifyDownloadAccess(project string, user *url.Userinfo, query str
url += "?" + query url += "?" + query
} }
reqDownloadAccess, err := http.NewRequest("GET", url, nil) reqDownloadAccess, err := http.NewRequest("GET", url, nil)
q := http.Request{Header: header}
if err != nil { if err != nil {
helper.Fail500(authReply.RawReply, fmt.Errorf("GET git-upload-pack: %v", err)) helper.Fail500(authReply.RawReply, &q, fmt.Errorf("GET git-upload-pack: %v", err))
return authReply return authReply
} }
if user != nil { if user != nil {
...@@ -337,7 +338,7 @@ func (a *API) verifyDownloadAccess(project string, user *url.Userinfo, query str ...@@ -337,7 +338,7 @@ func (a *API) verifyDownloadAccess(project string, user *url.Userinfo, query str
url = project + ".git/info/refs?service=git-upload-pack" url = project + ".git/info/refs?service=git-upload-pack"
reqFetchAccess, err := http.NewRequest("GET", url, nil) reqFetchAccess, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
helper.Fail500(authReply.RawReply, fmt.Errorf("GET git-upload-pack: %v", err)) helper.Fail500(authReply.RawReply, &q, fmt.Errorf("GET git-upload-pack: %v", err))
return authReply return authReply
} }
reqFetchAccess.SetBasicAuth(user.Username(), xpassword(user)) reqFetchAccess.SetBasicAuth(user.Username(), xpassword(user))
......
...@@ -34,7 +34,7 @@ func handleGetBlobRaw(a *api.API, w http.ResponseWriter, r *http.Request) { ...@@ -34,7 +34,7 @@ func handleGetBlobRaw(a *api.API, w http.ResponseWriter, r *http.Request) {
u := r.URL u := r.URL
rawLoc := rawRe.FindStringIndex(u.Path) rawLoc := rawRe.FindStringIndex(u.Path)
if rawLoc == nil { if rawLoc == nil {
helper.Fail500(w, errors.New("extract project name")) helper.Fail500(w, r, errors.New("extract project name"))
return return
} }
project := u.Path[:rawLoc[0]] project := u.Path[:rawLoc[0]]
...@@ -61,30 +61,30 @@ func handleGetBlobRaw(a *api.API, w http.ResponseWriter, r *http.Request) { ...@@ -61,30 +61,30 @@ func handleGetBlobRaw(a *api.API, w http.ResponseWriter, r *http.Request) {
// this way it will be read one time only and next reads will be empty. // this way it will be read one time only and next reads will be empty.
_, err := w.Write(authReply.RawReply.Body.Bytes()) _, err := w.Write(authReply.RawReply.Body.Bytes())
if err != nil { if err != nil {
helper.LogError(fmt.Errorf("writing authReply.RawReply.Body: %v", err)) helper.LogError(r, fmt.Errorf("writing authReply.RawReply.Body: %v", err))
} }
return return
} }
// Access granted - we can emit the blob // Access granted - we can emit the blob
emitBlob(w, authReply.RepoPath, refpath) emitBlob(w, authReply.RepoPath, refpath, r)
} }
// Emit content of blob located at <ref>/path (jointly denoted as 'refpath') to output // Emit content of blob located at <ref>/path (jointly denoted as 'refpath') to output
func emitBlob(w http.ResponseWriter, repopath string, refpath string) { func emitBlob(w http.ResponseWriter, repopath string, refpath string, r *http.Request) {
// Communicate with `git cat-file --batch` trying refs from longest // Communicate with `git cat-file --batch` trying refs from longest
// to shortest prefix in refpath. This way we find longest-match for // to shortest prefix in refpath. This way we find longest-match for
// ref and get blob sha1 and content in the end. // ref and get blob sha1 and content in the end.
queryCmd := gitCommand("", "git", "--git-dir="+repopath, "cat-file", "--batch") queryCmd := gitCommand("", "git", "--git-dir="+repopath, "cat-file", "--batch")
queryStdin, err := queryCmd.StdinPipe() queryStdin, err := queryCmd.StdinPipe()
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("git cat-file --batch; stdin: %v", err)) helper.Fail500(w, r, fmt.Errorf("git cat-file --batch; stdin: %v", err))
return return
} }
defer queryStdin.Close() defer queryStdin.Close()
queryStdout, err := queryCmd.StdoutPipe() queryStdout, err := queryCmd.StdoutPipe()
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("git cat-file --batch; stdout: %v", err)) helper.Fail500(w, r, fmt.Errorf("git cat-file --batch; stdout: %v", err))
return return
} }
defer queryStdout.Close() defer queryStdout.Close()
...@@ -92,7 +92,7 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) { ...@@ -92,7 +92,7 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) {
err = queryCmd.Start() err = queryCmd.Start()
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("git cat-file --batch; start: %v", err)) helper.Fail500(w, r, fmt.Errorf("git cat-file --batch; start: %v", err))
return return
} }
defer helper.CleanUpProcessGroup(queryCmd) defer helper.CleanUpProcessGroup(queryCmd)
...@@ -110,13 +110,13 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) { ...@@ -110,13 +110,13 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) {
path := strings.Join(refpathv[i:], "/") path := strings.Join(refpathv[i:], "/")
_, err := fmt.Fprintf(queryStdin, "%s:%s\n", ref, path) _, err := fmt.Fprintf(queryStdin, "%s:%s\n", ref, path)
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("git cat-file --batch; write: %v", err)) helper.Fail500(w, r, fmt.Errorf("git cat-file --batch; write: %v", err))
return return
} }
reply, err := queryReader.ReadString('\n') reply, err := queryReader.ReadString('\n')
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("git cat-file --batch; read: %v", err)) helper.Fail500(w, r, fmt.Errorf("git cat-file --batch; read: %v", err))
return return
} }
...@@ -128,7 +128,7 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) { ...@@ -128,7 +128,7 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) {
// <sha1> SP <type> SP <size> LF // <sha1> SP <type> SP <size> LF
_, err = fmt.Sscanf(reply, "%s %s %d\n", &sha1, &type_, &size) _, err = fmt.Sscanf(reply, "%s %s %d\n", &sha1, &type_, &size)
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("git cat-file --batch; reply parse: %v", err)) helper.Fail500(w, r, fmt.Errorf("git cat-file --batch; reply parse: %v", err))
return return
} }
...@@ -163,20 +163,20 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) { ...@@ -163,20 +163,20 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) {
// holding some tail bytes in queryReader after chat phase // holding some tail bytes in queryReader after chat phase
_, err = io.CopyN(w, queryReader, size) _, err = io.CopyN(w, queryReader, size)
if err != nil { if err != nil {
helper.LogError(fmt.Errorf("io.CopyN: %v", err)) helper.LogError(r, fmt.Errorf("io.CopyN: %v", err))
return return
} }
// close git stdin explicitly, so it can exit cleanly // close git stdin explicitly, so it can exit cleanly
err = queryStdin.Close() err = queryStdin.Close()
if err != nil { if err != nil {
helper.LogError(fmt.Errorf("queryStdin.Close: %v", err)) helper.LogError(r, fmt.Errorf("queryStdin.Close: %v", err))
return return
} }
err = queryCmd.Wait() err = queryCmd.Wait()
if err != nil { if err != nil {
helper.LogError(fmt.Errorf("wait: %v", err)) helper.LogError(r, fmt.Errorf("wait: %v", err))
return return
} }
} }
...@@ -127,7 +127,7 @@ func (u *Upstream) configureRoutes() { ...@@ -127,7 +127,7 @@ func (u *Upstream) configureRoutes() {
route("PUT", gitProjectPattern+`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`, lfs.PutStore(api, proxy), isContentType("application/octet-stream")), route("PUT", gitProjectPattern+`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`, lfs.PutStore(api, proxy), isContentType("application/octet-stream")),
// Raw blobs // Raw blobs
route{"GET", regexp.MustCompile(projectPattern + `raw/`), git.GetBlobRaw(api)}, route("GET", projectPattern + `raw/`, git.GetBlobRaw(api)),
// CI Artifacts // CI Artifacts
route("POST", ciAPIPattern+`v1/builds/[0-9]+/artifacts\z`, contentEncodingHandler(artifacts.UploadArtifacts(api, proxy))), route("POST", ciAPIPattern+`v1/builds/[0-9]+/artifacts\z`, contentEncodingHandler(artifacts.UploadArtifacts(api, proxy))),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment