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
2c2e57ac
Commit
2c2e57ac
authored
Mar 06, 2018
by
Alessio Caiazza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More consistent API naming. ObjectStore -> RemoteObject
parent
948e94fb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
35 deletions
+34
-35
internal/api/api.go
internal/api/api.go
+6
-7
internal/artifacts/artifacts_store_test.go
internal/artifacts/artifacts_store_test.go
+12
-12
internal/filestore/file_handler.go
internal/filestore/file_handler.go
+2
-2
internal/filestore/file_handler_test.go
internal/filestore/file_handler_test.go
+2
-2
internal/filestore/save_file_opts.go
internal/filestore/save_file_opts.go
+5
-5
internal/filestore/save_file_opts_test.go
internal/filestore/save_file_opts_test.go
+7
-7
No files found.
internal/api/api.go
View file @
2c2e57ac
...
...
@@ -67,16 +67,15 @@ func NewAPI(myURL *url.URL, version string, roundTripper *badgateway.RoundTrippe
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
type
RemoteObjectStore
struct
{
// GetURL is not used in gitlab-workhorse. We pass it back to gitlab-rails
// later for symmetry with the 'store upload in tempfile' approach.
type
RemoteObject
struct
{
// GetURL is an S3 GetObject URL
GetURL
string
// DeleteURL is a presigned S3 RemoveObject URL
DeleteURL
string
// StoreURL is the temporary presigned S3 PutObject URL to which upload the first found file
StoreURL
string
//
Object
ID is a unique identifier of object storage upload
Object
ID
string
// ID is a unique identifier of object storage upload
ID
string
// Timeout is a number that represents timeout in seconds for sending data to StoreURL
Timeout
int
}
...
...
@@ -105,9 +104,9 @@ type Response struct {
// TmpPath is the path where we should store temporary files
// This is set by authorization middleware
TempPath
string
//
ObjectStore
is provided by the GitLab Rails application
//
RemoteObject
is provided by the GitLab Rails application
// and defines a way to store object on remote storage
ObjectStore
RemoteObjectStore
RemoteObject
RemoteObject
// Archive is the path where the artifacts archive is stored
Archive
string
`json:"archive"`
// Entry is a filename inside the archive point to file that needs to be extracted
...
...
internal/artifacts/artifacts_store_test.go
View file @
2c2e57ac
...
...
@@ -74,8 +74,8 @@ func TestUploadHandlerSendingToExternalStorage(t *testing.T) {
responseProcessorCalled
:=
0
responseProcessor
:=
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
assert
.
Equal
(
t
,
"store-id"
,
r
.
FormValue
(
"file.
object
_id"
))
assert
.
NotEmpty
(
t
,
r
.
FormValue
(
"file.
stor
e_url"
))
assert
.
Equal
(
t
,
"store-id"
,
r
.
FormValue
(
"file.
remote
_id"
))
assert
.
NotEmpty
(
t
,
r
.
FormValue
(
"file.
remot
e_url"
))
w
.
WriteHeader
(
200
)
responseProcessorCalled
++
}
...
...
@@ -85,9 +85,9 @@ func TestUploadHandlerSendingToExternalStorage(t *testing.T) {
authResponse
:=
api
.
Response
{
TempPath
:
tempPath
,
ObjectStore
:
api
.
RemoteObjectStore
{
RemoteObject
:
api
.
RemoteObject
{
StoreURL
:
storeServer
.
URL
+
"/url/put"
,
ObjectID
:
"store-id"
,
ID
:
"store-id"
,
GetURL
:
storeServer
.
URL
+
"/store-id"
,
},
}
...
...
@@ -114,9 +114,9 @@ func TestUploadHandlerSendingToExternalStorageAndStorageServerUnreachable(t *tes
authResponse
:=
api
.
Response
{
TempPath
:
tempPath
,
ObjectStore
:
api
.
RemoteObjectStore
{
RemoteObject
:
api
.
RemoteObject
{
StoreURL
:
"http://localhost:12323/invalid/url"
,
ObjectID
:
"store-id"
,
ID
:
"store-id"
,
},
}
...
...
@@ -143,9 +143,9 @@ func TestUploadHandlerSendingToExternalStorageAndInvalidURLIsUsed(t *testing.T)
authResponse
:=
api
.
Response
{
TempPath
:
tempPath
,
ObjectStore
:
api
.
RemoteObjectStore
{
RemoteObject
:
api
.
RemoteObject
{
StoreURL
:
"htt:////invalid-url"
,
ObjectID
:
"store-id"
,
ID
:
"store-id"
,
},
}
...
...
@@ -184,9 +184,9 @@ func TestUploadHandlerSendingToExternalStorageAndItReturnsAnError(t *testing.T)
authResponse
:=
api
.
Response
{
TempPath
:
tempPath
,
ObjectStore
:
api
.
RemoteObjectStore
{
RemoteObject
:
api
.
RemoteObject
{
StoreURL
:
storeServer
.
URL
+
"/url/put"
,
ObjectID
:
"store-id"
,
ID
:
"store-id"
,
},
}
...
...
@@ -227,9 +227,9 @@ func TestUploadHandlerSendingToExternalStorageAndSupportRequestTimeout(t *testin
authResponse
:=
api
.
Response
{
TempPath
:
tempPath
,
ObjectStore
:
api
.
RemoteObjectStore
{
RemoteObject
:
api
.
RemoteObject
{
StoreURL
:
storeServer
.
URL
+
"/url/put"
,
ObjectID
:
"store-id"
,
ID
:
"store-id"
,
Timeout
:
1
,
},
}
...
...
internal/filestore/file_handler.go
View file @
2c2e57ac
...
...
@@ -65,10 +65,10 @@ func (fh *FileHandler) GitLabFinalizeFields(prefix string) map[string]string {
data
[
key
(
"path"
)]
=
fh
.
LocalPath
}
if
fh
.
RemoteURL
!=
""
{
data
[
key
(
"
stor
e_url"
)]
=
fh
.
RemoteURL
data
[
key
(
"
remot
e_url"
)]
=
fh
.
RemoteURL
}
if
fh
.
RemoteID
!=
""
{
data
[
key
(
"
object
_id"
)]
=
fh
.
RemoteID
data
[
key
(
"
remote
_id"
)]
=
fh
.
RemoteID
}
data
[
key
(
"size"
)]
=
strconv
.
FormatInt
(
fh
.
Size
,
10
)
for
hashName
,
hash
:=
range
fh
.
hashes
{
...
...
internal/filestore/file_handler_test.go
View file @
2c2e57ac
...
...
@@ -213,8 +213,8 @@ func TestSaveFile(t *testing.T) {
assert
.
Equal
(
fh
.
Name
,
fields
[
"file.name"
])
assert
.
Equal
(
fh
.
LocalPath
,
fields
[
"file.path"
])
assert
.
Equal
(
fh
.
RemoteURL
,
fields
[
"file.
stor
e_url"
])
assert
.
Equal
(
fh
.
RemoteID
,
fields
[
"file.
object
_id"
])
assert
.
Equal
(
fh
.
RemoteURL
,
fields
[
"file.
remot
e_url"
])
assert
.
Equal
(
fh
.
RemoteID
,
fields
[
"file.
remote
_id"
])
assert
.
Equal
(
strconv
.
FormatInt
(
test
.
ObjectSize
,
10
),
fields
[
"file.size"
])
assert
.
Equal
(
test
.
ObjectMD5
,
fields
[
"file.md5"
])
assert
.
Equal
(
test
.
ObjectSHA1
,
fields
[
"file.sha1"
])
...
...
internal/filestore/save_file_opts.go
View file @
2c2e57ac
...
...
@@ -51,17 +51,17 @@ func (s *SaveFileOpts) isGoogleCloudStorage() bool {
// GetOpts converts GitLab api.Response to a proper SaveFileOpts
func
GetOpts
(
apiResponse
*
api
.
Response
)
*
SaveFileOpts
{
timeout
:=
time
.
Duration
(
apiResponse
.
ObjectStore
.
Timeout
)
*
time
.
Second
timeout
:=
time
.
Duration
(
apiResponse
.
RemoteObject
.
Timeout
)
*
time
.
Second
if
timeout
==
0
{
timeout
=
objectstore
.
DefaultObjectStoreTimeout
}
return
&
SaveFileOpts
{
LocalTempPath
:
apiResponse
.
TempPath
,
RemoteID
:
apiResponse
.
ObjectStore
.
Object
ID
,
RemoteURL
:
apiResponse
.
ObjectStore
.
GetURL
,
PresignedPut
:
apiResponse
.
ObjectStore
.
StoreURL
,
PresignedDelete
:
apiResponse
.
ObjectStore
.
DeleteURL
,
RemoteID
:
apiResponse
.
RemoteObject
.
ID
,
RemoteURL
:
apiResponse
.
RemoteObject
.
GetURL
,
PresignedPut
:
apiResponse
.
RemoteObject
.
StoreURL
,
PresignedDelete
:
apiResponse
.
RemoteObject
.
DeleteURL
,
Timeout
:
timeout
,
}
}
internal/filestore/save_file_opts_test.go
View file @
2c2e57ac
...
...
@@ -62,9 +62,9 @@ func TestGetOpts(t *testing.T) {
assert
:=
assert
.
New
(
t
)
apiResponse
:=
&
api
.
Response
{
TempPath
:
"/tmp"
,
ObjectStore
:
api
.
RemoteObjectStore
{
RemoteObject
:
api
.
RemoteObject
{
Timeout
:
10
,
ObjectID
:
"id"
,
ID
:
"id"
,
GetURL
:
"http://get"
,
StoreURL
:
"http://store"
,
DeleteURL
:
"http://delete"
,
...
...
@@ -74,11 +74,11 @@ func TestGetOpts(t *testing.T) {
opts
:=
filestore
.
GetOpts
(
apiResponse
)
assert
.
Equal
(
apiResponse
.
TempPath
,
opts
.
LocalTempPath
)
assert
.
Equal
(
time
.
Duration
(
apiResponse
.
ObjectStore
.
Timeout
)
*
time
.
Second
,
opts
.
Timeout
)
assert
.
Equal
(
apiResponse
.
ObjectStore
.
Object
ID
,
opts
.
RemoteID
)
assert
.
Equal
(
apiResponse
.
ObjectStore
.
GetURL
,
opts
.
RemoteURL
)
assert
.
Equal
(
apiResponse
.
ObjectStore
.
StoreURL
,
opts
.
PresignedPut
)
assert
.
Equal
(
apiResponse
.
ObjectStore
.
DeleteURL
,
opts
.
PresignedDelete
)
assert
.
Equal
(
time
.
Duration
(
apiResponse
.
RemoteObject
.
Timeout
)
*
time
.
Second
,
opts
.
Timeout
)
assert
.
Equal
(
apiResponse
.
RemoteObject
.
ID
,
opts
.
RemoteID
)
assert
.
Equal
(
apiResponse
.
RemoteObject
.
GetURL
,
opts
.
RemoteURL
)
assert
.
Equal
(
apiResponse
.
RemoteObject
.
StoreURL
,
opts
.
PresignedPut
)
assert
.
Equal
(
apiResponse
.
RemoteObject
.
DeleteURL
,
opts
.
PresignedDelete
)
}
func
TestGetOptsDefaultTimeout
(
t
*
testing
.
T
)
{
...
...
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