Commit c165c876 authored by Marin Jankovski's avatar Marin Jankovski

Remove parsing of url and receive required data from GitLab Rails.

parent e6c7d974
......@@ -10,11 +10,9 @@ import (
"errors"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
)
......@@ -31,43 +29,40 @@ func lfsAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
return
}
if r.LfsOid == "" {
fail500(w, "lfsAuthorizeHandler", errors.New("Lfs object oid not specified."))
return
}
if r.LfsSize == "" {
fail500(w, "lfsAuthorizeHandler", errors.New("Lfs object size not specified."))
return
}
tmpDir := r.StoreLFSPath
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
if err := os.Mkdir(tmpDir, 0700); err != nil {
fail500(w, "Couldn't create directory for storing LFS tmp objects.", err)
return
}
}
handleFunc(w, r)
}, "")
}
func handleStoreLfsObject(handleFunc serviceHandleFunc) serviceHandleFunc {
return func(w http.ResponseWriter, r *gitRequest) {
urlPath := r.URL.Path
regExp := regexp.MustCompile(`([0-9a-f]{64})/([0-9]+)`)
matches := regExp.FindStringSubmatch(urlPath)
if matches == nil {
log.Printf("Found no object info in path: %s", urlPath)
return
}
oid := matches[1]
size := matches[2]
log.Printf("Found oid: %s and size: %s", oid, size)
sha := sha256.New()
sha.Write([]byte(oid))
tmp_hash := hex.EncodeToString(sha.Sum(nil))
tmpPath := filepath.Join(r.StoreLFSPath, "tmp")
oid := r.LfsOid
size := r.LfsSize
var body io.ReadCloser
body = r.Body
defer body.Close()
dir := filepath.Dir(tmpPath)
if err := os.MkdirAll(dir, 0700); err != nil {
fail500(w, "Couldn't create directory for storing LFS objects.", err)
return
}
file, err := ioutil.TempFile(tmpPath, tmp_hash)
tmpPath := r.StoreLFSPath
file, err := ioutil.TempFile(tmpPath, "")
if err != nil {
fail500(w, "Couldn't open tmp file for writing.", err)
return
......
......@@ -44,10 +44,13 @@ type authorizationResponse struct {
// CommitId is used do prevent race conditions between the 'time of check'
// in the GitLab Rails app and the 'time of use' in gitlab-workhorse.
CommitId string
// StoreLFSPath is provided by the GitLab Rails application
// to mark where the tmp file should be placed
StoreLFSPath string
// LFS object id
LfsOid string
// LFS object size
LfsSize string
}
// A gitReqest is an *http.Request decorated with attributes returned by the
......
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