Commit 101cd383 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix proxy_download support for lfs controller

parent 73463b08
...@@ -108,7 +108,7 @@ For source installations the following settings are nested under `artifacts:` an ...@@ -108,7 +108,7 @@ For source installations the following settings are nested under `artifacts:` an
| `enabled` | Enable/disable object storage | `false` | | `enabled` | Enable/disable object storage | `false` |
| `remote_directory` | The bucket name where Artfacts will be stored| | | `remote_directory` | The bucket name where Artfacts will be stored| |
| `background_upload` | Set to false to disable automatic upload. Option may be removed once upload is direct to S3 | `true` | | `background_upload` | Set to false to disable automatic upload. Option may be removed once upload is direct to S3 | `true` |
| `proxy_download` | Set to false to disable proxying all files served. Option allows to reduce egress traffic as this allows clients to download directly from remote storage instead of proxying all data | `false` | | `proxy_download` | Set to true to enable proxying all files served. Option allows to reduce egress traffic as this allows clients to download directly from remote storage instead of proxying all data | `false` |
| `connection` | Various connection options described below | | | `connection` | Various connection options described below | |
#### S3 compatible connection settings #### S3 compatible connection settings
......
...@@ -66,7 +66,7 @@ For source installations the following settings are nested under `uploads:` and ...@@ -66,7 +66,7 @@ For source installations the following settings are nested under `uploads:` and
| `enabled` | Enable/disable object storage | `false` | | `enabled` | Enable/disable object storage | `false` |
| `remote_directory` | The bucket name where Uploads will be stored| | | `remote_directory` | The bucket name where Uploads will be stored| |
| `background_upload` | Set to false to disable automatic upload. Option may be removed once upload is direct to S3 | `true` | | `background_upload` | Set to false to disable automatic upload. Option may be removed once upload is direct to S3 | `true` |
| `proxy_download` | Set to false to disable proxying all files served. Option allows to reduce egress traffic as this allows clients to download directly from remote storage instead of proxying all data | `false` | | `proxy_download` | Set to true to enable proxying all files served. Option allows to reduce egress traffic as this allows clients to download directly from remote storage instead of proxying all data | `false` |
| `connection` | Various connection options described below | | | `connection` | Various connection options described below | |
#### S3 compatible connection settings #### S3 compatible connection settings
......
...@@ -65,7 +65,7 @@ For source installations the following settings are nested under `lfs:` and then ...@@ -65,7 +65,7 @@ For source installations the following settings are nested under `lfs:` and then
| `remote_directory` | The bucket name where LFS objects will be stored| | | `remote_directory` | The bucket name where LFS objects will be stored| |
| `direct_upload` | Set to true to enable direct upload of LFS without the need of local shared storage. Option may be removed once we decide to support only single storage for all files. | `false` | | `direct_upload` | Set to true to enable direct upload of LFS without the need of local shared storage. Option may be removed once we decide to support only single storage for all files. | `false` |
| `background_upload` | Set to false to disable automatic upload. Option may be removed once upload is direct to S3 | `true` | | `background_upload` | Set to false to disable automatic upload. Option may be removed once upload is direct to S3 | `true` |
| `proxy_download` | Set to false to disable proxying all files served. Option allows to reduce egress traffic as this allows clients to download directly from remote storage instead of proxying all data | `false` | | `proxy_download` | Set to true to enable proxying all files served. Option allows to reduce egress traffic as this allows clients to download directly from remote storage instead of proxying all data | `false` |
| `connection` | Various connection options described below | | | `connection` | Various connection options described below | |
#### S3 compatible connection settings #### S3 compatible connection settings
......
...@@ -8,7 +8,8 @@ module SendFileUpload ...@@ -8,7 +8,8 @@ module SendFileUpload
if file_upload.file_storage? if file_upload.file_storage?
send_file file_upload.path, send_params send_file file_upload.path, send_params
elsif file_upload.class.proxy_download_enabled? elsif file_upload.class.proxy_download_enabled?
Gitlab::Workhorse.send_url(file_upload.url(**redirect_params)) headers.store(*Gitlab::Workhorse.send_url(file_upload.url(**redirect_params)))
head :ok
else else
redirect_to file_upload.url(**redirect_params) redirect_to file_upload.url(**redirect_params)
end end
......
---
title: Fix proxy_download support for lfs controller
merge_request:
author:
type: fixed
...@@ -64,10 +64,12 @@ describe SendFileUpload do ...@@ -64,10 +64,12 @@ describe SendFileUpload do
end end
it 'sends a file' do it 'sends a file' do
subject headers = double
expect(headers).to receive(:store).with(Gitlab::Workhorse::SEND_DATA_HEADER, /^send-url:/)
expect(controller).to receive(:headers) { headers }
expect(controller).to receive(:head).with(:ok)
is_expected.to start_with(Gitlab::Workhorse::SEND_DATA_HEADER) subject
is_expected.to end_with(/^send-url:/)
end end
end end
......
...@@ -39,20 +39,26 @@ describe API::Jobs do ...@@ -39,20 +39,26 @@ describe API::Jobs do
end end
end end
context 'normal authentication' do context 'for normal authentication when job with artifacts are stored remotely' do
before do before do
stub_artifacts_object_storage stub_artifacts_object_storage(proxy_download: proxy_download)
end
context 'when job with artifacts are stored remotely' do
let!(:artifact) { create(:ci_job_artifact, :archive, :remote_store, job: job) }
before do create(:ci_job_artifact, :archive, :remote_store, job: job)
job.reload
get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user) get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user)
end end
context 'when proxy download is enabled' do
let(:proxy_download) { true }
it 'responds with the workhorse send-url' do
expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("send-url:")
end
end
context 'when proxy download is disabled' do
let(:proxy_download) { false }
it 'returns location redirect' do it 'returns location redirect' do
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(302)
end end
......
module StubConfiguration module StubConfiguration
def stub_object_storage_uploader( def stub_object_storage_uploader(
config:, uploader:, remote_directory:, enabled: true, licensed: true, config:, uploader:, remote_directory:, enabled: true, licensed: true,
proxy_download: false,
background_upload: false, direct_upload: false background_upload: false, direct_upload: false
) )
allow(config).to receive(:enabled) { enabled } allow(config).to receive(:enabled) { enabled }
allow(config).to receive(:proxy_download) { proxy_download }
allow(config).to receive(:background_upload) { background_upload } allow(config).to receive(:background_upload) { background_upload }
allow(config).to receive(:direct_upload) { direct_upload } allow(config).to receive(:direct_upload) { direct_upload }
......
...@@ -243,8 +243,24 @@ describe 'Git LFS API and storage' do ...@@ -243,8 +243,24 @@ describe 'Git LFS API and storage' do
it_behaves_like 'responds with a file' it_behaves_like 'responds with a file'
context 'when LFS uses object storage' do context 'when LFS uses object storage' do
context 'when proxy download is enabled' do
let(:before_get) do let(:before_get) do
stub_lfs_object_storage stub_lfs_object_storage(proxy_download: true)
lfs_object.file.migrate!(LfsObjectUploader::Store::REMOTE)
end
it 'responds with redirect' do
expect(response).to have_gitlab_http_status(200)
end
it 'responds with the workhorse send-url' do
expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("send-url:")
end
end
context 'when proxy download is disabled' do
let(:before_get) do
stub_lfs_object_storage(proxy_download: false)
lfs_object.file.migrate!(LfsObjectUploader::Store::REMOTE) lfs_object.file.migrate!(LfsObjectUploader::Store::REMOTE)
end end
...@@ -258,6 +274,7 @@ describe 'Git LFS API and storage' do ...@@ -258,6 +274,7 @@ describe 'Git LFS API and storage' do
end end
end end
end end
end
context 'when deploy key is authorized' do context 'when deploy key is authorized' do
let(:key) { create(:deploy_key) } let(:key) { create(:deploy_key) }
...@@ -1380,9 +1397,6 @@ describe 'Git LFS API and storage' do ...@@ -1380,9 +1397,6 @@ describe 'Git LFS API and storage' do
def lfs_tmp_file def lfs_tmp_file
"#{sample_oid}012345678" "#{sample_oid}012345678"
end end
def setup_tempfile(lfs_tmp)
end
end end
def enable_lfs def enable_lfs
......
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