Commit c8ea51ae 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 0db57aaf
......@@ -243,7 +243,7 @@ type testDownloadOkViaSendArchive struct {
func (aok *testDownloadOkViaSendArchive) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
var param struct{ RepoPath string }
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
}
......@@ -283,8 +283,9 @@ func (a *API) verifyDownloadAccess(project string, user *url.Userinfo, query str
url += "?" + query
}
reqDownloadAccess, err := http.NewRequest("GET", url, nil)
q := http.Request{Header: header}
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
}
if user != nil {
......@@ -337,7 +338,7 @@ func (a *API) verifyDownloadAccess(project string, user *url.Userinfo, query str
url = project + ".git/info/refs?service=git-upload-pack"
reqFetchAccess, err := http.NewRequest("GET", url, 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
}
reqFetchAccess.SetBasicAuth(user.Username(), xpassword(user))
......
......@@ -34,7 +34,7 @@ func handleGetBlobRaw(a *api.API, w http.ResponseWriter, r *http.Request) {
u := r.URL
rawLoc := rawRe.FindStringIndex(u.Path)
if rawLoc == nil {
helper.Fail500(w, errors.New("extract project name"))
helper.Fail500(w, r, errors.New("extract project name"))
return
}
project := u.Path[:rawLoc[0]]
......@@ -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.
_, err := w.Write(authReply.RawReply.Body.Bytes())
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
}
// 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
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
// to shortest prefix in refpath. This way we find longest-match for
// ref and get blob sha1 and content in the end.
queryCmd := gitCommand("", "", "git", "--git-dir="+repopath, "cat-file", "--batch")
queryStdin, err := queryCmd.StdinPipe()
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
}
defer queryStdin.Close()
queryStdout, err := queryCmd.StdoutPipe()
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
}
defer queryStdout.Close()
......@@ -92,7 +92,7 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) {
err = queryCmd.Start()
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
}
defer helper.CleanUpProcessGroup(queryCmd)
......@@ -110,13 +110,13 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) {
path := strings.Join(refpathv[i:], "/")
_, err := fmt.Fprintf(queryStdin, "%s:%s\n", ref, path)
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
}
reply, err := queryReader.ReadString('\n')
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
}
......@@ -128,7 +128,7 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) {
// <sha1> SP <type> SP <size> LF
_, err = fmt.Sscanf(reply, "%s %s %d\n", &sha1, &type_, &size)
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
}
......@@ -163,20 +163,20 @@ func emitBlob(w http.ResponseWriter, repopath string, refpath string) {
// holding some tail bytes in queryReader after chat phase
_, err = io.CopyN(w, queryReader, size)
if err != nil {
helper.LogError(fmt.Errorf("io.CopyN: %v", err))
helper.LogError(r, fmt.Errorf("io.CopyN: %v", err))
return
}
// close git stdin explicitly, so it can exit cleanly
err = queryStdin.Close()
if err != nil {
helper.LogError(fmt.Errorf("queryStdin.Close: %v", err))
helper.LogError(r, fmt.Errorf("queryStdin.Close: %v", err))
return
}
err = queryCmd.Wait()
if err != nil {
helper.LogError(fmt.Errorf("wait: %v", err))
helper.LogError(r, fmt.Errorf("wait: %v", err))
return
}
}
......@@ -183,7 +183,7 @@ func (u *upstream) configureRoutes() {
route("PUT", gitProjectPattern+`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`, lfs.PutStore(api, signingProxy), withMatcher(isContentType("application/octet-stream"))),
// Raw blobs
route{"GET", regexp.MustCompile(projectPattern + `raw/`), git.GetBlobRaw(api)},
route("GET", projectPattern + `raw/`, git.GetBlobRaw(api)),
// CI Artifacts
route("POST", apiPattern+`v4/jobs/[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