Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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-ce
Commits
82f91190
Commit
82f91190
authored
Feb 09, 2022
by
Jacob Vosmaer
Committed by
Patrick Bajao
Feb 14, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Workhorse: rename upload.BodyUploader to upload.RequestBody
parent
0794d819
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
30 deletions
+25
-30
workhorse/internal/dependencyproxy/dependencyproxy_test.go
workhorse/internal/dependencyproxy/dependencyproxy_test.go
+2
-2
workhorse/internal/lfs/lfs.go
workhorse/internal/lfs/lfs.go
+0
-5
workhorse/internal/upload/body_uploader.go
workhorse/internal/upload/body_uploader.go
+8
-8
workhorse/internal/upload/body_uploader_test.go
workhorse/internal/upload/body_uploader_test.go
+6
-6
workhorse/internal/upstream/routes.go
workhorse/internal/upstream/routes.go
+9
-9
No files found.
workhorse/internal/dependencyproxy/dependencyproxy_test.go
View file @
82f91190
...
@@ -91,12 +91,12 @@ func TestInject(t *testing.T) {
...
@@ -91,12 +91,12 @@ func TestInject(t *testing.T) {
}))
}))
defer
originResourceServer
.
Close
()
defer
originResourceServer
.
Close
()
//
BodyUploader
expects http.Handler as its second param, we can create a stub function and verify that
//
RequestBody
expects http.Handler as its second param, we can create a stub function and verify that
// it's only called for successful requests
// it's only called for successful requests
handlerIsCalled
:=
false
handlerIsCalled
:=
false
handlerFunc
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
handlerIsCalled
=
true
})
handlerFunc
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
handlerIsCalled
=
true
})
bodyUploader
:=
upload
.
BodyUploader
(
&
fakePreAuthHandler
{},
handlerFunc
,
&
upload
.
DefaultPreparer
{})
bodyUploader
:=
upload
.
RequestBody
(
&
fakePreAuthHandler
{},
handlerFunc
,
&
upload
.
DefaultPreparer
{})
injector
:=
NewInjector
()
injector
:=
NewInjector
()
injector
.
SetUploadHandler
(
bodyUploader
)
injector
.
SetUploadHandler
(
bodyUploader
)
...
...
workhorse/internal/lfs/lfs.go
View file @
82f91190
...
@@ -6,7 +6,6 @@ package lfs
...
@@ -6,7 +6,6 @@ package lfs
import
(
import
(
"fmt"
"fmt"
"net/http"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/config"
"gitlab.com/gitlab-org/gitlab/workhorse/internal/config"
...
@@ -49,7 +48,3 @@ func (l *uploadPreparer) Prepare(a *api.Response) (*filestore.SaveFileOpts, uplo
...
@@ -49,7 +48,3 @@ func (l *uploadPreparer) Prepare(a *api.Response) (*filestore.SaveFileOpts, uplo
return
opts
,
&
object
{
oid
:
a
.
LfsOid
,
size
:
a
.
LfsSize
},
nil
return
opts
,
&
object
{
oid
:
a
.
LfsOid
,
size
:
a
.
LfsSize
},
nil
}
}
func
PutStore
(
a
*
api
.
API
,
h
http
.
Handler
,
p
upload
.
Preparer
)
http
.
Handler
{
return
upload
.
BodyUploader
(
a
,
h
,
p
)
}
workhorse/internal/upload/body_uploader.go
View file @
82f91190
...
@@ -22,7 +22,7 @@ type Verifier interface {
...
@@ -22,7 +22,7 @@ type Verifier interface {
Verify
(
handler
*
filestore
.
FileHandler
)
error
Verify
(
handler
*
filestore
.
FileHandler
)
error
}
}
// Preparer allows to customize
BodyUploader
configuration
// Preparer allows to customize
RequestBody
configuration
type
Preparer
interface
{
type
Preparer
interface
{
// Prepare converts api.Response into a *SaveFileOpts, it can optionally return an Verifier that will be
// Prepare converts api.Response into a *SaveFileOpts, it can optionally return an Verifier that will be
// invoked after the real upload, before the finalization with rails
// invoked after the real upload, before the finalization with rails
...
@@ -36,26 +36,26 @@ func (s *DefaultPreparer) Prepare(a *api.Response) (*filestore.SaveFileOpts, Ver
...
@@ -36,26 +36,26 @@ func (s *DefaultPreparer) Prepare(a *api.Response) (*filestore.SaveFileOpts, Ver
return
opts
,
nil
,
err
return
opts
,
nil
,
err
}
}
//
BodyUploader
is an http.Handler that perform a pre authorization call to rails before hijacking the request body and
//
RequestBody
is an http.Handler that perform a pre authorization call to rails before hijacking the request body and
// uploading it.
// uploading it.
// Providing an Preparer allows to customize the upload process
// Providing an Preparer allows to customize the upload process
func
BodyUploader
(
rails
PreAuthorizer
,
h
http
.
Handler
,
p
Preparer
)
http
.
Handler
{
func
RequestBody
(
rails
PreAuthorizer
,
h
http
.
Handler
,
p
Preparer
)
http
.
Handler
{
return
rails
.
PreAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
return
rails
.
PreAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
{
opts
,
verifier
,
err
:=
p
.
Prepare
(
a
)
opts
,
verifier
,
err
:=
p
.
Prepare
(
a
)
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
BodyUploader
: preparation failed: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
RequestBody
: preparation failed: %v"
,
err
))
return
return
}
}
fh
,
err
:=
filestore
.
SaveFileFromReader
(
r
.
Context
(),
r
.
Body
,
r
.
ContentLength
,
opts
)
fh
,
err
:=
filestore
.
SaveFileFromReader
(
r
.
Context
(),
r
.
Body
,
r
.
ContentLength
,
opts
)
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
BodyUploader
: upload failed: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
RequestBody
: upload failed: %v"
,
err
))
return
return
}
}
if
verifier
!=
nil
{
if
verifier
!=
nil
{
if
err
:=
verifier
.
Verify
(
fh
);
err
!=
nil
{
if
err
:=
verifier
.
Verify
(
fh
);
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
BodyUploader
: verification failed: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
RequestBody
: verification failed: %v"
,
err
))
return
return
}
}
}
}
...
@@ -63,7 +63,7 @@ func BodyUploader(rails PreAuthorizer, h http.Handler, p Preparer) http.Handler
...
@@ -63,7 +63,7 @@ func BodyUploader(rails PreAuthorizer, h http.Handler, p Preparer) http.Handler
data
:=
url
.
Values
{}
data
:=
url
.
Values
{}
fields
,
err
:=
fh
.
GitLabFinalizeFields
(
"file"
)
fields
,
err
:=
fh
.
GitLabFinalizeFields
(
"file"
)
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
BodyUploader
: finalize fields failed: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
RequestBody
: finalize fields failed: %v"
,
err
))
return
return
}
}
...
@@ -80,7 +80,7 @@ func BodyUploader(rails PreAuthorizer, h http.Handler, p Preparer) http.Handler
...
@@ -80,7 +80,7 @@ func BodyUploader(rails PreAuthorizer, h http.Handler, p Preparer) http.Handler
sft
:=
SavedFileTracker
{
Request
:
r
}
sft
:=
SavedFileTracker
{
Request
:
r
}
sft
.
Track
(
"file"
,
fh
.
LocalPath
)
sft
.
Track
(
"file"
,
fh
.
LocalPath
)
if
err
:=
sft
.
Finalize
(
r
.
Context
());
err
!=
nil
{
if
err
:=
sft
.
Finalize
(
r
.
Context
());
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
BodyUploader
: finalize failed: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"
RequestBody
: finalize failed: %v"
,
err
))
return
return
}
}
...
...
workhorse/internal/upload/body_uploader_test.go
View file @
82f91190
...
@@ -24,7 +24,7 @@ const (
...
@@ -24,7 +24,7 @@ const (
fileLen
=
len
(
fileContent
)
fileLen
=
len
(
fileContent
)
)
)
func
Test
BodyUploader
(
t
*
testing
.
T
)
{
func
Test
RequestBody
(
t
*
testing
.
T
)
{
testhelper
.
ConfigureSecret
()
testhelper
.
ConfigureSecret
()
body
:=
strings
.
NewReader
(
fileContent
)
body
:=
strings
.
NewReader
(
fileContent
)
...
@@ -38,7 +38,7 @@ func TestBodyUploader(t *testing.T) {
...
@@ -38,7 +38,7 @@ func TestBodyUploader(t *testing.T) {
require
.
Equal
(
t
,
fileContent
,
string
(
uploadEcho
))
require
.
Equal
(
t
,
fileContent
,
string
(
uploadEcho
))
}
}
func
Test
BodyUploader
CustomPreparer
(
t
*
testing
.
T
)
{
func
Test
RequestBody
CustomPreparer
(
t
*
testing
.
T
)
{
body
:=
strings
.
NewReader
(
fileContent
)
body
:=
strings
.
NewReader
(
fileContent
)
resp
:=
testUpload
(
&
rails
{},
&
alwaysLocalPreparer
{},
echoProxy
(
t
,
fileLen
),
body
)
resp
:=
testUpload
(
&
rails
{},
&
alwaysLocalPreparer
{},
echoProxy
(
t
,
fileLen
),
body
)
...
@@ -49,7 +49,7 @@ func TestBodyUploaderCustomPreparer(t *testing.T) {
...
@@ -49,7 +49,7 @@ func TestBodyUploaderCustomPreparer(t *testing.T) {
require
.
Equal
(
t
,
fileContent
,
string
(
uploadEcho
))
require
.
Equal
(
t
,
fileContent
,
string
(
uploadEcho
))
}
}
func
Test
BodyUploader
CustomVerifier
(
t
*
testing
.
T
)
{
func
Test
RequestBody
CustomVerifier
(
t
*
testing
.
T
)
{
body
:=
strings
.
NewReader
(
fileContent
)
body
:=
strings
.
NewReader
(
fileContent
)
verifier
:=
&
mockVerifier
{}
verifier
:=
&
mockVerifier
{}
...
@@ -62,11 +62,11 @@ func TestBodyUploaderCustomVerifier(t *testing.T) {
...
@@ -62,11 +62,11 @@ func TestBodyUploaderCustomVerifier(t *testing.T) {
require
.
True
(
t
,
verifier
.
invoked
,
"Verifier.Verify not invoked"
)
require
.
True
(
t
,
verifier
.
invoked
,
"Verifier.Verify not invoked"
)
}
}
func
Test
BodyUploader
AuthorizationFailure
(
t
*
testing
.
T
)
{
func
Test
RequestBody
AuthorizationFailure
(
t
*
testing
.
T
)
{
testNoProxyInvocation
(
t
,
http
.
StatusUnauthorized
,
&
rails
{
unauthorized
:
true
},
&
alwaysLocalPreparer
{})
testNoProxyInvocation
(
t
,
http
.
StatusUnauthorized
,
&
rails
{
unauthorized
:
true
},
&
alwaysLocalPreparer
{})
}
}
func
Test
BodyUploader
Errors
(
t
*
testing
.
T
)
{
func
Test
RequestBody
Errors
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
preparer
*
alwaysLocalPreparer
preparer
*
alwaysLocalPreparer
...
@@ -95,7 +95,7 @@ func testUpload(auth PreAuthorizer, preparer Preparer, proxy http.Handler, body
...
@@ -95,7 +95,7 @@ func testUpload(auth PreAuthorizer, preparer Preparer, proxy http.Handler, body
req
:=
httptest
.
NewRequest
(
"POST"
,
"http://example.com/upload"
,
body
)
req
:=
httptest
.
NewRequest
(
"POST"
,
"http://example.com/upload"
,
body
)
w
:=
httptest
.
NewRecorder
()
w
:=
httptest
.
NewRecorder
()
BodyUploader
(
auth
,
proxy
,
preparer
)
.
ServeHTTP
(
w
,
req
)
RequestBody
(
auth
,
proxy
,
preparer
)
.
ServeHTTP
(
w
,
req
)
return
w
.
Result
()
return
w
.
Result
()
}
}
...
...
workhorse/internal/upstream/routes.go
View file @
82f91190
...
@@ -232,7 +232,7 @@ func configureRoutes(u *upstream) {
...
@@ -232,7 +232,7 @@ func configureRoutes(u *upstream) {
ciAPIProxyQueue
:=
queueing
.
QueueRequests
(
"ci_api_job_requests"
,
tempfileMultipartProxy
,
u
.
APILimit
,
u
.
APIQueueLimit
,
u
.
APIQueueTimeout
)
ciAPIProxyQueue
:=
queueing
.
QueueRequests
(
"ci_api_job_requests"
,
tempfileMultipartProxy
,
u
.
APILimit
,
u
.
APIQueueLimit
,
u
.
APIQueueTimeout
)
ciAPILongPolling
:=
builds
.
RegisterHandler
(
ciAPIProxyQueue
,
redis
.
WatchKey
,
u
.
APICILongPollingDuration
)
ciAPILongPolling
:=
builds
.
RegisterHandler
(
ciAPIProxyQueue
,
redis
.
WatchKey
,
u
.
APICILongPollingDuration
)
dependencyProxyInjector
.
SetUploadHandler
(
upload
.
BodyUploader
(
api
,
signingProxy
,
preparers
.
packages
))
dependencyProxyInjector
.
SetUploadHandler
(
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
packages
))
// Serve static files or forward the requests
// Serve static files or forward the requests
defaultUpstream
:=
static
.
ServeExisting
(
defaultUpstream
:=
static
.
ServeExisting
(
...
@@ -248,7 +248,7 @@ func configureRoutes(u *upstream) {
...
@@ -248,7 +248,7 @@ func configureRoutes(u *upstream) {
u
.
route
(
"GET"
,
gitProjectPattern
+
`info/refs\z`
,
git
.
GetInfoRefsHandler
(
api
)),
u
.
route
(
"GET"
,
gitProjectPattern
+
`info/refs\z`
,
git
.
GetInfoRefsHandler
(
api
)),
u
.
route
(
"POST"
,
gitProjectPattern
+
`git-upload-pack\z`
,
contentEncodingHandler
(
git
.
UploadPack
(
api
)),
withMatcher
(
isContentType
(
"application/x-git-upload-pack-request"
))),
u
.
route
(
"POST"
,
gitProjectPattern
+
`git-upload-pack\z`
,
contentEncodingHandler
(
git
.
UploadPack
(
api
)),
withMatcher
(
isContentType
(
"application/x-git-upload-pack-request"
))),
u
.
route
(
"POST"
,
gitProjectPattern
+
`git-receive-pack\z`
,
contentEncodingHandler
(
git
.
ReceivePack
(
api
)),
withMatcher
(
isContentType
(
"application/x-git-receive-pack-request"
))),
u
.
route
(
"POST"
,
gitProjectPattern
+
`git-receive-pack\z`
,
contentEncodingHandler
(
git
.
ReceivePack
(
api
)),
withMatcher
(
isContentType
(
"application/x-git-receive-pack-request"
))),
u
.
route
(
"PUT"
,
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
,
lfs
.
PutStore
(
api
,
signingProxy
,
preparers
.
lfs
),
withMatcher
(
isContentType
(
"application/octet-stream"
))),
u
.
route
(
"PUT"
,
gitProjectPattern
+
`gitlab-lfs/objects/([0-9a-f]{64})/([0-9]+)\z`
,
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
lfs
),
withMatcher
(
isContentType
(
"application/octet-stream"
))),
// CI Artifacts
// CI Artifacts
u
.
route
(
"POST"
,
apiPattern
+
`v4/jobs/[0-9]+/artifacts\z`
,
contentEncodingHandler
(
artifacts
.
UploadArtifacts
(
api
,
signingProxy
,
preparers
.
artifacts
))),
u
.
route
(
"POST"
,
apiPattern
+
`v4/jobs/[0-9]+/artifacts\z`
,
contentEncodingHandler
(
artifacts
.
UploadArtifacts
(
api
,
signingProxy
,
preparers
.
artifacts
))),
...
@@ -276,14 +276,14 @@ func configureRoutes(u *upstream) {
...
@@ -276,14 +276,14 @@ func configureRoutes(u *upstream) {
// https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56731.
// https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56731.
// Maven Artifact Repository
// Maven Artifact Repository
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/maven/`
,
upload
.
BodyUploader
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/maven/`
,
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
packages
)),
// Conan Artifact Repository
// Conan Artifact Repository
u
.
route
(
"PUT"
,
apiPattern
+
`v4/packages/conan/`
,
upload
.
BodyUploader
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"PUT"
,
apiPattern
+
`v4/packages/conan/`
,
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/conan/`
,
upload
.
BodyUploader
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/conan/`
,
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
packages
)),
// Generic Packages Repository
// Generic Packages Repository
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/generic/`
,
upload
.
BodyUploader
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/generic/`
,
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
packages
)),
// NuGet Artifact Repository
// NuGet Artifact Repository
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/nuget/`
,
upload
.
Multipart
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/nuget/`
,
upload
.
Multipart
(
api
,
signingProxy
,
preparers
.
packages
)),
...
@@ -292,13 +292,13 @@ func configureRoutes(u *upstream) {
...
@@ -292,13 +292,13 @@ func configureRoutes(u *upstream) {
u
.
route
(
"POST"
,
apiProjectPattern
+
`packages/pypi`
,
upload
.
Multipart
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"POST"
,
apiProjectPattern
+
`packages/pypi`
,
upload
.
Multipart
(
api
,
signingProxy
,
preparers
.
packages
)),
// Debian Artifact Repository
// Debian Artifact Repository
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/debian/`
,
upload
.
BodyUploader
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/debian/`
,
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
packages
)),
// Gem Artifact Repository
// Gem Artifact Repository
u
.
route
(
"POST"
,
apiProjectPattern
+
`packages/rubygems/`
,
upload
.
BodyUploader
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"POST"
,
apiProjectPattern
+
`packages/rubygems/`
,
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
packages
)),
// Terraform Module Package Repository
// Terraform Module Package Repository
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/terraform/modules/`
,
upload
.
BodyUploader
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"PUT"
,
apiProjectPattern
+
`packages/terraform/modules/`
,
upload
.
RequestBody
(
api
,
signingProxy
,
preparers
.
packages
)),
// Helm Artifact Repository
// Helm Artifact Repository
u
.
route
(
"POST"
,
apiProjectPattern
+
`packages/helm/api/[^/]+/charts\z`
,
upload
.
Multipart
(
api
,
signingProxy
,
preparers
.
packages
)),
u
.
route
(
"POST"
,
apiProjectPattern
+
`packages/helm/api/[^/]+/charts\z`
,
upload
.
Multipart
(
api
,
signingProxy
,
preparers
.
packages
)),
...
...
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