Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
db3213fc
Commit
db3213fc
authored
Nov 09, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use normal file upload mechanism to upload artifacts
parent
7e4e3fb3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
23 deletions
+34
-23
lib/api/helpers.rb
lib/api/helpers.rb
+10
-6
lib/ci/api/builds.rb
lib/ci/api/builds.rb
+7
-9
spec/requests/ci/api/builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+17
-8
No files found.
lib/api/helpers.rb
View file @
db3213fc
...
@@ -294,19 +294,23 @@ module API
...
@@ -294,19 +294,23 @@ module API
# file helpers
# file helpers
def
uploaded_file!
(
uploads_path
)
def
uploaded_file!
(
field
,
uploads_path
)
required_attributes!
[
:file
]
if
params
[
field
]
bad_request!
(
"
#{
field
}
is not a file"
)
unless
params
[
field
].
respond_to?
(
:filename
)
return
params
[
field
]
end
# sanitize file paths
# sanitize file paths
# this requires for all paths to exist
# this requires all paths to exist
required_attributes!
%W(
#{
field
}
.path)
uploads_path
=
File
.
realpath
(
uploads_path
)
uploads_path
=
File
.
realpath
(
uploads_path
)
file_path
=
File
.
realpath
(
params
[
:file
])
file_path
=
File
.
realpath
(
params
[
"
#{
field
}
.path"
])
bad_request!
(
'Bad file path'
)
unless
file_path
.
start_with?
(
uploads_path
)
bad_request!
(
'Bad file path'
)
unless
file_path
.
start_with?
(
uploads_path
)
UploadedFile
.
new
(
UploadedFile
.
new
(
file_path
,
file_path
,
params
[
:filename
],
params
[
"
#{
field
}
.name"
],
params
[
:filetype
]
||
'application/octet-stream'
,
params
[
"
#{
field
}
.type"
]
||
'application/octet-stream'
,
)
)
end
end
...
...
lib/ci/api/builds.rb
View file @
db3213fc
...
@@ -53,7 +53,7 @@ module Ci
...
@@ -53,7 +53,7 @@ module Ci
# Parameters:
# Parameters:
# id (required) - The ID of a build
# id (required) - The ID of a build
# token (required) - The build authorization token
# token (required) - The build authorization token
# size (optional) - the size of uploaded file
#
file
size (optional) - the size of uploaded file
# Example Request:
# Example Request:
# POST /builds/:id/artifacts/authorize
# POST /builds/:id/artifacts/authorize
post
":id/artifacts/authorize"
do
post
":id/artifacts/authorize"
do
...
@@ -77,18 +77,16 @@ module Ci
...
@@ -77,18 +77,16 @@ module Ci
# Parameters:
# Parameters:
# id (required) - The ID of a build
# id (required) - The ID of a build
# token (required) - The build authorization token
# token (required) - The build authorization token
# file (required) - The uploaded 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
# Headers:
# Headers:
# Content-Type - File content type
# Content-Disposition - File media type and real name
# BUILD-TOKEN (required) - The build authorization token, the same as token
# BUILD-TOKEN (required) - The build authorization token, the same as token
# Body:
# Body:
# The file content
# The file content
#
#
# Parameters (set by GitLab Workhorse):
# file - path to locally stored body (generated by Workhorse)
# filename - real filename as send in Content-Disposition
# filetype - real content type as send in Content-Type
# filesize - real file size as send in Content-Length
# Example Request:
# Example Request:
# POST /builds/:id/artifacts
# POST /builds/:id/artifacts
post
":id/artifacts"
do
post
":id/artifacts"
do
...
@@ -98,7 +96,7 @@ module Ci
...
@@ -98,7 +96,7 @@ module Ci
authenticate_build_token!
(
build
)
authenticate_build_token!
(
build
)
forbidden!
(
'build is not running'
)
unless
build
.
running?
forbidden!
(
'build is not running'
)
unless
build
.
running?
file
=
uploaded_file!
(
ArtifactUploader
.
artifacts_upload_path
)
file
=
uploaded_file!
(
:file
,
ArtifactUploader
.
artifacts_upload_path
)
file_to_large!
unless
file
.
size
<
max_artifacts_size
file_to_large!
unless
file
.
size
<
max_artifacts_size
if
build
.
update_attributes
(
artifacts_file:
file
)
if
build
.
update_attributes
(
artifacts_file:
file
)
...
...
spec/requests/ci/api/builds_spec.rb
View file @
db3213fc
...
@@ -194,8 +194,14 @@ describe Ci::API::API do
...
@@ -194,8 +194,14 @@ describe Ci::API::API do
build
.
run!
build
.
run!
end
end
it
do
it
"uses regual file post"
do
upload_artifacts
(
file_upload
,
headers_with_token
)
upload_artifacts
(
file_upload
,
headers_with_token
,
false
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
"artifacts_file"
][
"filename"
]).
to
eq
(
file_upload
.
original_filename
)
end
it
"uses accelerated file post"
do
upload_artifacts
(
file_upload
,
headers_with_token
,
true
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
"artifacts_file"
][
"filename"
]).
to
eq
(
file_upload
.
original_filename
)
expect
(
json_response
[
"artifacts_file"
][
"filename"
]).
to
eq
(
file_upload
.
original_filename
)
end
end
...
@@ -263,12 +269,15 @@ describe Ci::API::API do
...
@@ -263,12 +269,15 @@ describe Ci::API::API do
end
end
end
end
def
upload_artifacts
(
file
,
headers
=
{})
def
upload_artifacts
(
file
,
headers
=
{},
accelerated
=
true
)
params
=
{
if
accelerated
file:
file
.
path
,
post
post_url
,
{
filename:
file
.
original_filename
,
'file.path'
=>
file
.
path
,
}
'file.name'
=>
file
.
original_filename
post
post_url
,
params
,
headers
},
headers
else
post
post_url
,
{
file:
file
},
headers
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment