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
3a4910c4
Commit
3a4910c4
authored
Sep 12, 2019
by
Steve Abrams
Committed by
Nick Thomas
Sep 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add route for handling Conan package uploads
Accelerated upload route for conan package files
parent
a0d68429
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
internal/upstream/routes.go
internal/upstream/routes.go
+3
-0
upload_test.go
upload_test.go
+67
-0
No files found.
internal/upstream/routes.go
View file @
3a4910c4
...
...
@@ -202,6 +202,9 @@ func (u *upstream) configureRoutes() {
// Maven Artifact Repository
route
(
"PUT"
,
apiPattern
+
`v4/projects/[0-9]+/packages/maven/`
,
filestore
.
BodyUploader
(
api
,
proxy
,
nil
)),
// Conan Artifact Repository
route
(
"PUT"
,
apiPattern
+
`v4/packages/conan/`
,
filestore
.
BodyUploader
(
api
,
proxy
,
nil
)),
// We are porting API to disk acceleration
// we need to declare each routes until we have fixed all the routes on the rails codebase.
// Overall status can be seen at https://gitlab.com/groups/gitlab-org/-/epics/1802#current-status
...
...
upload_test.go
View file @
3a4910c4
...
...
@@ -8,6 +8,7 @@ import (
"mime/multipart"
"net/http"
"net/http/httptest"
"os"
"regexp"
"strconv"
"strings"
...
...
@@ -263,3 +264,69 @@ func TestLfsUpload(t *testing.T) {
require
.
Equal
(
t
,
200
,
resp
.
StatusCode
)
require
.
Equal
(
t
,
rspBody
,
string
(
rspData
))
}
func
packageUploadTestServer
(
t
*
testing
.
T
,
resource
string
,
reqBody
string
,
rspBody
string
)
*
httptest
.
Server
{
return
testhelper
.
TestServerWithHandler
(
regexp
.
MustCompile
(
`.`
),
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
require
.
Equal
(
t
,
r
.
Method
,
"PUT"
)
apiResponse
:=
fmt
.
Sprintf
(
`{"TempPath":%q, "Size": %d}`
,
scratchDir
,
len
(
reqBody
),
)
switch
r
.
RequestURI
{
case
resource
+
"/authorize"
:
// Expect the authorization call to be signed
_
,
err
:=
jwt
.
Parse
(
r
.
Header
.
Get
(
secret
.
RequestHeader
),
parseJWT
)
require
.
NoError
(
t
,
err
)
// Instruct workhorse to accept the upload
w
.
Header
()
.
Set
(
"Content-Type"
,
api
.
ResponseContentType
)
_
,
err
=
fmt
.
Fprint
(
w
,
apiResponse
)
require
.
NoError
(
t
,
err
)
case
resource
:
// Expect the request to point to a file on disk containing the data
require
.
NoError
(
t
,
r
.
ParseForm
())
len
:=
strconv
.
Itoa
(
len
(
reqBody
))
require
.
Equal
(
t
,
len
,
r
.
Form
.
Get
(
"file.size"
),
"Invalid size populated"
)
tmpFilePath
:=
r
.
Form
.
Get
(
"file.path"
)
fileData
,
err
:=
ioutil
.
ReadFile
(
tmpFilePath
)
defer
os
.
Remove
(
tmpFilePath
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
reqBody
,
string
(
fileData
),
"Temporary file has the wrong body"
)
fmt
.
Fprint
(
w
,
rspBody
)
default
:
t
.
Fatalf
(
"Unexpected request to upstream! %v %q"
,
r
.
Method
,
r
.
RequestURI
)
}
})
}
func
testPackageFileUpload
(
t
*
testing
.
T
,
resource
string
)
{
reqBody
:=
"test data"
rspBody
:=
"test success"
ts
:=
packageUploadTestServer
(
t
,
resource
,
reqBody
,
rspBody
)
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
req
,
err
:=
http
.
NewRequest
(
"PUT"
,
ws
.
URL
+
resource
,
strings
.
NewReader
(
reqBody
))
require
.
NoError
(
t
,
err
)
resp
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
require
.
NoError
(
t
,
err
)
respData
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
rspBody
,
string
(
respData
),
"Temporary file has the wrong body"
)
defer
resp
.
Body
.
Close
()
require
.
Equal
(
t
,
200
,
resp
.
StatusCode
)
}
func
TestPackageFilesUpload
(
t
*
testing
.
T
)
{
testPackageFileUpload
(
t
,
`/api/v4/packages/conan/v1/files`
)
}
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