diff options
Diffstat (limited to 'workhorse/internal/upload/multipart_uploader.go')
-rw-r--r-- | workhorse/internal/upload/multipart_uploader.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/workhorse/internal/upload/multipart_uploader.go b/workhorse/internal/upload/multipart_uploader.go index 34675d2aa14..2456a2c8626 100644 --- a/workhorse/internal/upload/multipart_uploader.go +++ b/workhorse/internal/upload/multipart_uploader.go @@ -1,11 +1,9 @@ package upload import ( - "fmt" "net/http" "gitlab.com/gitlab-org/gitlab/workhorse/internal/api" - "gitlab.com/gitlab-org/gitlab/workhorse/internal/helper" ) // Multipart is a request middleware. If the request has a MIME multipart @@ -17,12 +15,27 @@ func Multipart(rails PreAuthorizer, h http.Handler, p Preparer) http.Handler { return rails.PreAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *api.Response) { s := &SavedFileTracker{Request: r} - opts, err := p.Prepare(a) - if err != nil { - helper.Fail500(w, r, fmt.Errorf("Multipart: error preparing file storage options")) - return + interceptMultipartFiles(w, r, h, s, &eagerAuthorizer{a}, p) + }, "/authorize") +} + +// SkipRailsPreAuthMultipart behaves like Multipart except it does not +// pre-authorize with Rails. It is intended for use on catch-all routes +// where we cannot pre-authorize both because we don't know which Rails +// endpoint to call, and because eagerly pre-authorizing would add too +// much overhead. +func SkipRailsPreAuthMultipart(tempPath string, myAPI *api.API, h http.Handler, p Preparer) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + s := &SavedFileTracker{Request: r} + + // We use testAuthorizer as a temporary measure. When + // https://gitlab.com/groups/gitlab-com/gl-infra/-/epics/742 is done, we + // should only be using apiAuthorizer. + fa := &testAuthorizer{ + test: &apiAuthorizer{myAPI}, + actual: &eagerAuthorizer{&api.Response{TempPath: tempPath}}, } - interceptMultipartFiles(w, r, h, a, s, opts) - }, "/authorize") + interceptMultipartFiles(w, r, h, s, fa, p) + }) } |