Update build artifacts API
We do not want to allow runners to upload a metadata file. This needs to be generated by Workhorse only.
This commit is contained in:
parent
6d7a77074f
commit
0b946029a1
3 changed files with 44 additions and 24 deletions
|
@ -79,14 +79,13 @@ module Ci
|
|||
# id (required) - The ID of a build
|
||||
# token (required) - The build authorization token
|
||||
# file (required) - Artifacts file
|
||||
# metadata (optional) - Artifacts metadata file
|
||||
# Parameters (accelerated by GitLab Workhorse):
|
||||
# file.path - path to locally stored body (generated by Workhorse)
|
||||
# file.name - real filename as send in Content-Disposition
|
||||
# file.type - real content type as send in Content-Type
|
||||
# metadata.path - path to locally stored body (generated by Workhorse)
|
||||
# metadata.name - real filename as send in Content-Disposition
|
||||
# metadata.type - real content type as send in Content-Type
|
||||
# metadata.name - filename (generated by Workhorse)
|
||||
# metadata.type - content type (returned by Workhorse)
|
||||
# Headers:
|
||||
# BUILD-TOKEN (required) - The build authorization token, the same as token
|
||||
# Body:
|
||||
|
@ -101,19 +100,19 @@ module Ci
|
|||
not_found! unless build
|
||||
authenticate_build_token!(build)
|
||||
forbidden!('build is not running') unless build.running?
|
||||
forbidden!('metadata reserved for workhorse') if params[:metadata]
|
||||
|
||||
artifacts_upload_path = ArtifactUploader.artifacts_upload_path
|
||||
artifacts = uploaded_file!(:file, artifacts_upload_path)
|
||||
file_to_large! unless artifacts.size < max_artifacts_size
|
||||
artifacts_attributes = { artifacts_file: artifacts }
|
||||
build.artifacts_file = artifacts
|
||||
|
||||
if params[:metadata] || params['metadata.path'.to_sym]
|
||||
metadata = uploaded_file!(:metadata, artifacts_upload_path)
|
||||
artifacts_attributes.store(:artifacts_metadata, metadata)
|
||||
if params[:'metadata.path'] && params[:'metadata.name']
|
||||
build.artifacts_metadata = uploaded_file!(:metadata, artifacts_upload_path)
|
||||
end
|
||||
|
||||
if build.update_attributes(artifacts_attributes)
|
||||
present build, with: Entities::Build
|
||||
if build.save
|
||||
present(build, with: Entities::Build)
|
||||
else
|
||||
render_validation_error!(build)
|
||||
end
|
||||
|
|
|
@ -31,7 +31,6 @@ module Ci
|
|||
|
||||
expose :variables
|
||||
expose :artifacts_file, using: ArtifactFile
|
||||
expose :artifacts_metadata, using: ArtifactFile
|
||||
end
|
||||
|
||||
class Runner < Grape::Entity
|
||||
|
|
|
@ -210,27 +210,49 @@ describe Ci::API::API do
|
|||
end
|
||||
end
|
||||
|
||||
context "should post artifacts metadata" do
|
||||
context 'should post artifacts file and metadata file' do
|
||||
let!(:artifacts) { file_upload }
|
||||
let!(:metadata) { file_upload2 }
|
||||
|
||||
let(:stored_artifacts_file) { build.reload.artifacts_file.file }
|
||||
let(:stored_metadata_file) { build.reload.artifacts_metadata.file }
|
||||
|
||||
before do
|
||||
build.run!
|
||||
|
||||
post_data = {
|
||||
'file.path' => artifacts.path,
|
||||
'file.name' => artifacts.original_filename,
|
||||
'metadata.path' => metadata.path,
|
||||
'metadata.name' => metadata.original_filename
|
||||
}
|
||||
|
||||
post post_url, post_data, headers_with_token
|
||||
post(post_url, post_data, headers_with_token)
|
||||
end
|
||||
|
||||
it 'stores artifacts and artifacts metadata' do
|
||||
expect(response.status).to eq(201)
|
||||
expect(json_response['artifacts_file']['filename']).to eq(artifacts.original_filename)
|
||||
expect(json_response['artifacts_metadata']['filename']).to eq(metadata.original_filename)
|
||||
context 'post data accelerated by workhorse is correct' do
|
||||
let(:post_data) do
|
||||
{ 'file.path' => artifacts.path,
|
||||
'file.name' => artifacts.original_filename,
|
||||
'metadata.path' => metadata.path,
|
||||
'metadata.name' => metadata.original_filename }
|
||||
end
|
||||
|
||||
it 'responds with valid status' do
|
||||
expect(response.status).to eq(201)
|
||||
end
|
||||
|
||||
it 'stores artifacts and artifacts metadata' do
|
||||
expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename)
|
||||
expect(stored_metadata_file.original_filename).to eq(metadata.original_filename)
|
||||
end
|
||||
end
|
||||
|
||||
context 'runner sends metadata file' do
|
||||
let(:post_data) do
|
||||
{ 'file' => artifacts, 'metadata' => metadata }
|
||||
end
|
||||
|
||||
it 'is expected to respond with forbbiden' do
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it 'does not store artifacts or metadata' do
|
||||
expect(stored_artifacts_file).to be_nil
|
||||
expect(stored_metadata_file).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue