Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
90663ef7
Commit
90663ef7
authored
Jun 21, 2018
by
Alessio Caiazza
Committed by
Nick Thomas
Jun 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Direct Upload for User Uploads
parent
3ec9de61
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
7 deletions
+35
-7
internal/upload/accelerate.go
internal/upload/accelerate.go
+8
-6
internal/upload/skip_rails_authorizer.go
internal/upload/skip_rails_authorizer.go
+22
-0
internal/upstream/routes.go
internal/upstream/routes.go
+5
-1
No files found.
internal/upload/accelerate.go
View file @
90663ef7
...
...
@@ -25,13 +25,15 @@ type MultipartClaims struct {
jwt
.
StandardClaims
}
func
Accelerate
(
tempDir
string
,
h
http
.
Handler
)
http
.
Handler
{
// TODO: for Object Store this will need a authorize call
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
localOnlyPreAuth
:=
&
api
.
Response
{
TempPath
:
tempDir
}
type
PreAuthorizer
interface
{
PreAuthorizeHandler
(
next
api
.
HandleFunc
,
suffix
string
)
http
.
Handler
}
func
Accelerate
(
rails
PreAuthorizer
,
h
http
.
Handler
)
http
.
Handler
{
return
rails
.
PreAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
s
:=
&
savedFileTracker
{
request
:
r
}
HandleFileUploads
(
w
,
r
,
h
,
localOnlyPreAuth
,
s
)
})
HandleFileUploads
(
w
,
r
,
h
,
a
,
s
)
}
,
"/authorize"
)
}
func
(
s
*
savedFileTracker
)
ProcessFile
(
_
context
.
Context
,
fieldName
string
,
file
*
filestore
.
FileHandler
,
_
*
multipart
.
Writer
)
error
{
...
...
internal/upload/skip_rails_authorizer.go
0 → 100644
View file @
90663ef7
package
upload
import
(
"net/http"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
)
// SkipRailsAuthorizer implements a fake PreAuthorizer that do not calls rails API and
// authorize each call as a local only upload to TempPath
type
SkipRailsAuthorizer
struct
{
// TempPath is the temporary path for a local only upload
TempPath
string
}
// PreAuthorizeHandler implements PreAuthorizer. It always grant the upload.
// The fake API response contains only TempPath
func
(
l
*
SkipRailsAuthorizer
)
PreAuthorizeHandler
(
next
api
.
HandleFunc
,
_
string
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
next
(
w
,
r
,
&
api
.
Response
{
TempPath
:
l
.
TempPath
})
})
}
internal/upstream/routes.go
View file @
90663ef7
...
...
@@ -145,7 +145,8 @@ func (u *Upstream) configureRoutes() {
sendurl
.
SendURL
,
)
uploadAccelerateProxy
:=
upload
.
Accelerate
(
path
.
Join
(
u
.
DocumentRoot
,
"uploads/tmp"
),
proxy
)
uploadPath
:=
path
.
Join
(
u
.
DocumentRoot
,
"uploads/tmp"
)
uploadAccelerateProxy
:=
upload
.
Accelerate
(
&
upload
.
SkipRailsAuthorizer
{
TempPath
:
uploadPath
},
proxy
)
ciAPIProxyQueue
:=
queueing
.
QueueRequests
(
"ci_api_job_requests"
,
uploadAccelerateProxy
,
u
.
APILimit
,
u
.
APIQueueLimit
,
u
.
APIQueueTimeout
)
ciAPILongPolling
:=
builds
.
RegisterHandler
(
ciAPIProxyQueue
,
redis
.
WatchKey
,
u
.
APICILongPollingDuration
)
...
...
@@ -182,6 +183,9 @@ func (u *Upstream) configureRoutes() {
),
),
// Uploads
route
(
"POST"
,
projectPattern
+
`uploads\z`
,
upload
.
Accelerate
(
api
,
proxy
)),
// For legacy reasons, user uploads are stored under the document root.
// To prevent anybody who knows/guesses the URL of a user-uploaded file
// from downloading it we make sure requests to /uploads/ do _not_ pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment