Commit 2b9e609f authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'eb-return-filesize-authorize' into 'master'

Include max artifact size in authorize response

See merge request gitlab-org/gitlab!37632
parents a150f511 5ce80ffc
...@@ -178,10 +178,14 @@ module ObjectStorage ...@@ -178,10 +178,14 @@ module ObjectStorage
end end
def workhorse_authorize(has_length:, maximum_size: nil) def workhorse_authorize(has_length:, maximum_size: nil)
if self.object_store_enabled? && self.direct_upload_enabled? {}.tap do |hash|
{ RemoteObject: workhorse_remote_upload_options(has_length: has_length, maximum_size: maximum_size) } if self.object_store_enabled? && self.direct_upload_enabled?
else hash[:RemoteObject] = workhorse_remote_upload_options(has_length: has_length, maximum_size: maximum_size)
{ TempPath: workhorse_local_upload_path } else
hash[:TempPath] = workhorse_local_upload_path
end
hash[:MaximumSize] = maximum_size if maximum_size.present?
end end
end end
......
---
title: Include max artifact size in authorize response
merge_request: 37632
author:
type: added
...@@ -143,6 +143,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -143,6 +143,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE)
expect(json_response['TempPath']).to eq(JobArtifactUploader.workhorse_local_upload_path) expect(json_response['TempPath']).to eq(JobArtifactUploader.workhorse_local_upload_path)
expect(json_response['RemoteObject']).to be_nil expect(json_response['RemoteObject']).to be_nil
expect(json_response['MaximumSize']).not_to be_nil
end end
end end
...@@ -167,6 +168,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -167,6 +168,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
expect(json_response['RemoteObject']).to have_key('StoreURL') expect(json_response['RemoteObject']).to have_key('StoreURL')
expect(json_response['RemoteObject']).to have_key('DeleteURL') expect(json_response['RemoteObject']).to have_key('DeleteURL')
expect(json_response['RemoteObject']).to have_key('MultipartUpload') expect(json_response['RemoteObject']).to have_key('MultipartUpload')
expect(json_response['MaximumSize']).not_to be_nil
end end
end end
...@@ -188,6 +190,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -188,6 +190,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE)
expect(json_response['TempPath']).not_to be_nil expect(json_response['TempPath']).not_to be_nil
expect(json_response['MaximumSize']).not_to be_nil
end end
it 'fails to post too large artifact' do it 'fails to post too large artifact' do
......
...@@ -414,28 +414,38 @@ RSpec.describe ObjectStorage do ...@@ -414,28 +414,38 @@ RSpec.describe ObjectStorage do
subject { uploader_class.workhorse_authorize(has_length: has_length, maximum_size: maximum_size) } subject { uploader_class.workhorse_authorize(has_length: has_length, maximum_size: maximum_size) }
shared_examples 'uses local storage' do shared_examples 'returns the maximum size given' do
it "returns temporary path" do it "returns temporary path" do
is_expected.to have_key(:TempPath) expect(subject[:MaximumSize]).to eq(maximum_size)
end
end
shared_examples 'uses local storage' do
it_behaves_like 'returns the maximum size given' do
it "returns temporary path" do
is_expected.to have_key(:TempPath)
expect(subject[:TempPath]).to start_with(uploader_class.root) expect(subject[:TempPath]).to start_with(uploader_class.root)
expect(subject[:TempPath]).to include(described_class::TMP_UPLOAD_PATH) expect(subject[:TempPath]).to include(described_class::TMP_UPLOAD_PATH)
end
end end
end end
shared_examples 'uses remote storage' do shared_examples 'uses remote storage' do
it "returns remote store" do it_behaves_like 'returns the maximum size given' do
is_expected.to have_key(:RemoteObject) it "returns remote store" do
is_expected.to have_key(:RemoteObject)
expect(subject[:RemoteObject]).to have_key(:ID)
expect(subject[:RemoteObject]).to include(Timeout: a_kind_of(Integer)) expect(subject[:RemoteObject]).to have_key(:ID)
expect(subject[:RemoteObject][:Timeout]).to be(ObjectStorage::DirectUpload::TIMEOUT) expect(subject[:RemoteObject]).to include(Timeout: a_kind_of(Integer))
expect(subject[:RemoteObject]).to have_key(:GetURL) expect(subject[:RemoteObject][:Timeout]).to be(ObjectStorage::DirectUpload::TIMEOUT)
expect(subject[:RemoteObject]).to have_key(:DeleteURL) expect(subject[:RemoteObject]).to have_key(:GetURL)
expect(subject[:RemoteObject]).to have_key(:StoreURL) expect(subject[:RemoteObject]).to have_key(:DeleteURL)
expect(subject[:RemoteObject][:GetURL]).to include(described_class::TMP_UPLOAD_PATH) expect(subject[:RemoteObject]).to have_key(:StoreURL)
expect(subject[:RemoteObject][:DeleteURL]).to include(described_class::TMP_UPLOAD_PATH) expect(subject[:RemoteObject][:GetURL]).to include(described_class::TMP_UPLOAD_PATH)
expect(subject[:RemoteObject][:StoreURL]).to include(described_class::TMP_UPLOAD_PATH) expect(subject[:RemoteObject][:DeleteURL]).to include(described_class::TMP_UPLOAD_PATH)
expect(subject[:RemoteObject][:StoreURL]).to include(described_class::TMP_UPLOAD_PATH)
end
end end
end end
......
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