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