Commit d78f0997 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'object_store_rename' into 'master'

More consistent API naming. ObjectStore -> RemoteObject

See merge request gitlab-org/gitlab-workhorse!240
parents 948e94fb 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
// ObjectID is a unique identifier of object storage upload
ObjectID 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
......
......@@ -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.store_url"))
assert.Equal(t, "store-id", r.FormValue("file.remote_id"))
assert.NotEmpty(t, r.FormValue("file.remote_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,
},
}
......
......@@ -65,10 +65,10 @@ func (fh *FileHandler) GitLabFinalizeFields(prefix string) map[string]string {
data[key("path")] = fh.LocalPath
}
if fh.RemoteURL != "" {
data[key("store_url")] = fh.RemoteURL
data[key("remote_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 {
......
......@@ -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.store_url"])
assert.Equal(fh.RemoteID, fields["file.object_id"])
assert.Equal(fh.RemoteURL, fields["file.remote_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"])
......
......@@ -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.ObjectID,
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,
}
}
......@@ -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.ObjectID, 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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment