Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-workhorse
Commits
085e5087
Commit
085e5087
authored
Jan 19, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor fixed and improvements for build artifacts implementation
parent
5ae1356e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
16 deletions
+19
-16
internal/artifacts/artifact_download.go
internal/artifacts/artifact_download.go
+2
-1
internal/artifacts/artifact_download_test.go
internal/artifacts/artifact_download_test.go
+9
-2
internal/artifacts/artifacts_upload.go
internal/artifacts/artifacts_upload.go
+3
-2
internal/artifacts/artifacts_upload_test.go
internal/artifacts/artifacts_upload_test.go
+1
-1
internal/upload/uploads.go
internal/upload/uploads.go
+4
-10
No files found.
internal/artifacts/artifact_download.go
View file @
085e5087
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"archive/zip"
"archive/zip"
"encoding/base64"
"encoding/base64"
"errors"
"errors"
"fmt"
"io"
"io"
"mime"
"mime"
"net/http"
"net/http"
...
@@ -89,7 +90,7 @@ func DownloadArtifact(myAPI *api.API) http.Handler {
...
@@ -89,7 +90,7 @@ func DownloadArtifact(myAPI *api.API) http.Handler {
http
.
NotFound
(
w
,
r
)
http
.
NotFound
(
w
,
r
)
return
return
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
helper
.
Fail500
(
w
,
err
)
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"DownloadArtifact: %v"
,
err
)
)
}
}
},
""
)
},
""
)
}
}
internal/artifacts/artifact_download_test.go
View file @
085e5087
...
@@ -29,7 +29,7 @@ func testArtifactDownloadServer(t *testing.T, archive string, entry string) *htt
...
@@ -29,7 +29,7 @@ func testArtifactDownloadServer(t *testing.T, archive string, entry string) *htt
Entry
:
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
entry
)),
Entry
:
base64
.
StdEncoding
.
EncodeToString
([]
byte
(
entry
)),
})
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
"Expected to marshal"
)
t
.
Fatal
(
err
)
}
}
w
.
Write
(
data
)
w
.
Write
(
data
)
})
})
...
@@ -69,7 +69,14 @@ func TestDownloadingFromValidArchive(t *testing.T) {
...
@@ -69,7 +69,14 @@ func TestDownloadingFromValidArchive(t *testing.T) {
response
:=
testDownloadArtifact
(
t
,
ts
)
response
:=
testDownloadArtifact
(
t
,
ts
)
testhelper
.
AssertResponseCode
(
t
,
response
,
200
)
testhelper
.
AssertResponseCode
(
t
,
response
,
200
)
testhelper
.
AssertResponseHeader
(
t
,
response
,
"Content-Type"
,
"text/plain; charset=utf-8"
)
testhelper
.
AssertResponseHeader
(
t
,
response
,
"Content-Type"
,
"text/plain; charset=utf-8"
)
testhelper
.
AssertResponseHeader
(
t
,
response
,
"Content-Disposition"
,
"attachment; filename=
\"
test.txt
\"
"
)
testhelper
.
AssertResponseBody
(
t
,
response
,
"testtest"
)
testhelper
.
AssertResponseBody
(
t
,
response
,
"testtest"
)
}
}
...
...
internal/artifacts/artifacts_upload.go
View file @
085e5087
...
@@ -12,18 +12,19 @@ import (
...
@@ -12,18 +12,19 @@ import (
"os"
"os"
)
)
// The artifactsFormFilter allows to pass only the `file` as file in body
type
artifactsUploadProcessor
struct
{
type
artifactsUploadProcessor
struct
{
TempPath
string
TempPath
string
metadataFile
string
metadataFile
string
}
}
func
(
a
*
artifactsUploadProcessor
)
ProcessFile
(
formName
,
fileName
string
,
writer
*
multipart
.
Writer
)
error
{
func
(
a
*
artifactsUploadProcessor
)
ProcessFile
(
formName
,
fileName
string
,
writer
*
multipart
.
Writer
)
error
{
// ProcessFile for artifacts requires file form-data field name to eq `file`
if
formName
!=
"file"
{
if
formName
!=
"file"
{
return
fmt
.
Errorf
(
"Invalid form field: %q"
,
formName
)
return
fmt
.
Errorf
(
"Invalid form field: %q"
,
formName
)
}
}
if
a
.
metadataFile
!=
""
{
if
a
.
metadataFile
!=
""
{
return
fmt
.
Errorf
(
"
Multiple files
"
)
return
fmt
.
Errorf
(
"
Artifacts request contains more than one file!
"
)
}
}
// Create temporary file for metadata and store it's path
// Create temporary file for metadata and store it's path
...
...
internal/artifacts/artifacts_upload_test.go
View file @
085e5087
...
@@ -71,7 +71,7 @@ func testArtifactsUploadServer(t *testing.T, tempPath string) *httptest.Server {
...
@@ -71,7 +71,7 @@ func testArtifactsUploadServer(t *testing.T, tempPath string) *httptest.Server {
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
return
return
}
}
if
!
bytes
.
Contains
(
metadata
,
[]
byte
(
metadataHeader
))
{
if
!
bytes
.
HasPrefix
(
metadata
[
4
:
]
,
[]
byte
(
metadataHeader
))
{
w
.
WriteHeader
(
400
)
w
.
WriteHeader
(
400
)
return
return
}
}
...
...
internal/upload/uploads.go
View file @
085e5087
...
@@ -75,12 +75,9 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
...
@@ -75,12 +75,9 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
file
.
Close
()
file
.
Close
()
if
filter
!=
nil
{
if
err
:=
filter
.
ProcessFile
(
name
,
file
.
Name
(),
writer
);
err
!=
nil
{
err
=
filter
.
ProcessFile
(
name
,
file
.
Name
(),
writer
)
if
err
!=
nil
{
return
cleanup
,
err
return
cleanup
,
err
}
}
}
}
else
{
}
else
{
np
,
err
:=
writer
.
CreatePart
(
p
.
Header
)
np
,
err
:=
writer
.
CreatePart
(
p
.
Header
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -92,14 +89,11 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
...
@@ -92,14 +89,11 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
return
cleanup
,
err
return
cleanup
,
err
}
}
if
filter
!=
nil
{
if
err
:=
filter
.
ProcessField
(
name
,
writer
);
err
!=
nil
{
err
=
filter
.
ProcessField
(
name
,
writer
)
if
err
!=
nil
{
return
cleanup
,
err
return
cleanup
,
err
}
}
}
}
}
}
}
return
cleanup
,
nil
return
cleanup
,
nil
}
}
...
...
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