summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-05-09 17:27:38 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2018-06-04 13:04:29 +0200
commitb8370c9f55843351b49073dafe84a2e9858c8c8a (patch)
treea211a5003143c2d2dc9b10e86ce67f58c27a41c9 /app
parent0b4f9ff4068af6776b495d9332aeecf58e48786f (diff)
downloadgitlab-ce-b8370c9f55843351b49073dafe84a2e9858c8c8a.tar.gz
Support presigned multipart uploads
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/lfs_storage_controller.rb2
-rw-r--r--app/uploaders/object_storage.rb21
2 files changed, 7 insertions, 16 deletions
diff --git a/app/controllers/projects/lfs_storage_controller.rb b/app/controllers/projects/lfs_storage_controller.rb
index 43d8867a536..45c98d60822 100644
--- a/app/controllers/projects/lfs_storage_controller.rb
+++ b/app/controllers/projects/lfs_storage_controller.rb
@@ -18,7 +18,7 @@ class Projects::LfsStorageController < Projects::GitHttpClientController
def upload_authorize
set_workhorse_internal_api_content_type
- authorized = LfsObjectUploader.workhorse_authorize
+ authorized = LfsObjectUploader.workhorse_authorize(has_length: true)
authorized.merge!(LfsOid: oid, LfsSize: size)
render json: authorized
diff --git a/app/uploaders/object_storage.rb b/app/uploaders/object_storage.rb
index 5bdca26a584..3bb2e1ea63a 100644
--- a/app/uploaders/object_storage.rb
+++ b/app/uploaders/object_storage.rb
@@ -10,8 +10,6 @@ module ObjectStorage
UnknownStoreError = Class.new(StandardError)
ObjectStorageUnavailable = Class.new(StandardError)
- DIRECT_UPLOAD_TIMEOUT = 4.hours
- DIRECT_UPLOAD_EXPIRE_OFFSET = 15.minutes
TMP_UPLOAD_PATH = 'tmp/uploads'.freeze
module Store
@@ -157,9 +155,9 @@ module ObjectStorage
model_class.uploader_options.dig(mount_point, :mount_on) || mount_point
end
- def workhorse_authorize
+ def workhorse_authorize(has_length:, maximum_size: nil)
{
- RemoteObject: workhorse_remote_upload_options,
+ RemoteObject: workhorse_remote_upload_options(has_length: has_length, maximum_size: maximum_size),
TempPath: workhorse_local_upload_path
}.compact
end
@@ -168,23 +166,16 @@ module ObjectStorage
File.join(self.root, TMP_UPLOAD_PATH)
end
- def workhorse_remote_upload_options
+ def workhorse_remote_upload_options(has_length:, maximum_size: nil)
return unless self.object_store_enabled?
return unless self.direct_upload_enabled?
id = [CarrierWave.generate_cache_id, SecureRandom.hex].join('-')
upload_path = File.join(TMP_UPLOAD_PATH, id)
- connection = ::Fog::Storage.new(self.object_store_credentials)
- expire_at = Time.now + DIRECT_UPLOAD_TIMEOUT + DIRECT_UPLOAD_EXPIRE_OFFSET
- options = { 'Content-Type' => 'application/octet-stream' }
+ direct_upload = ObjectStorage::DirectUpload.new(self.object_store_credentials, remote_store_path, upload_path,
+ has_length: has_length, maximum_size: maximum_size)
- {
- ID: id,
- Timeout: DIRECT_UPLOAD_TIMEOUT,
- GetURL: connection.get_object_url(remote_store_path, upload_path, expire_at),
- DeleteURL: connection.delete_object_url(remote_store_path, upload_path, expire_at),
- StoreURL: connection.put_object_url(remote_store_path, upload_path, expire_at, options)
- }
+ direct_upload.to_hash.merge(ID: id)
end
end