Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
763ecd4c
Commit
763ecd4c
authored
5 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
import: don't create file if source uri is not supported at
parent
c99f9bcc
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/v1/files.go
+2
-4
2 additions, 4 deletions
api/v1/files.go
importer/importer.go
+10
-1
10 additions, 1 deletion
importer/importer.go
importer/job.go
+2
-3
2 additions, 3 deletions
importer/job.go
importer/job_source.go
+2
-0
2 additions, 0 deletions
importer/job_source.go
with
16 additions
and
8 deletions
api/v1/files.go
+
2
−
4
View file @
763ecd4c
...
...
@@ -28,7 +28,6 @@ import (
"context"
"encoding/json"
"net/http"
"net/url"
"time"
"github.com/gin-gonic/gin"
...
...
@@ -68,7 +67,7 @@ func (api *API) CreateFileForShow(c *gin.Context) {
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"source-uri is mandatory"
})
return
}
srcURI
,
err
:=
url
.
Parse
(
request
.
SourceURI
)
srcURI
,
err
:=
api
.
importer
.
ParseAndVerifySourceURI
(
request
.
SourceURI
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusBadRequest
,
ErrorResponse
{
Error
:
"source-uri is invalid: "
+
err
.
Error
()})
return
...
...
@@ -93,10 +92,9 @@ func (api *API) CreateFileForShow(c *gin.Context) {
// file or at least return the id of the created file so the UI can deal with it.
refID
:=
""
// TODO: get this from query paremeter
job
,
err
:=
api
.
importer
.
CreateJob
(
showID
,
file
.
ID
,
*
srcURI
,
sess
.
Username
,
refID
)
job
,
err
:=
api
.
importer
.
CreateJob
(
showID
,
file
.
ID
,
srcURI
,
sess
.
Username
,
refID
)
if
err
!=
nil
{
// possible errors:
// - importer.ErrSourceNotSupported -> delete file
// - any error returned by store.GetFile():
// possible reasons for this:
// * connection problem to the store database
...
...
This diff is collapsed.
Click to expand it.
importer/importer.go
+
10
−
1
View file @
763ecd4c
...
...
@@ -52,7 +52,12 @@ func (im *Importer) ListJobs(show string) (Jobs, error) {
return
im
.
jobs
.
ListJobs
(
show
),
nil
// for now error is always nil but this might change later
}
func
(
im
*
Importer
)
CreateJob
(
show
string
,
id
uint64
,
src
url
.
URL
,
user
,
refID
string
)
(
*
Job
,
error
)
{
func
(
im
*
Importer
)
ParseAndVerifySourceURI
(
uri
string
)
(
*
SourceURL
,
error
)
{
src
,
err
:=
url
.
Parse
(
uri
)
if
err
!=
nil
{
return
nil
,
err
}
switch
src
.
Scheme
{
case
SourceSchemeUpload
:
case
SourceSchemeFake
:
...
...
@@ -62,6 +67,10 @@ func (im *Importer) CreateJob(show string, id uint64, src url.URL, user, refID s
return
nil
,
ErrSourceNotSupported
}
return
(
*
SourceURL
)(
src
),
nil
}
func
(
im
*
Importer
)
CreateJob
(
show
string
,
id
uint64
,
src
*
SourceURL
,
user
,
refID
string
)
(
*
Job
,
error
)
{
file
,
err
:=
im
.
store
.
GetFile
(
show
,
id
)
if
err
!=
nil
{
return
nil
,
err
...
...
This diff is collapsed.
Click to expand it.
importer/job.go
+
2
−
3
View file @
763ecd4c
...
...
@@ -28,7 +28,6 @@ import (
"context"
"io"
"io/ioutil"
"net/url"
"os"
"sync/atomic"
"time"
...
...
@@ -220,8 +219,8 @@ func (job *Job) cleanup() {
}
}
func
newJob
(
im
*
Importer
,
show
string
,
id
uint64
,
src
url
.
URL
,
user
,
refID
string
)
*
Job
{
job
:=
&
Job
{
im
:
im
,
Show
:
show
,
ID
:
id
,
Source
:
SourceURL
(
src
)
,
User
:
user
,
RefID
:
refID
}
func
newJob
(
im
*
Importer
,
show
string
,
id
uint64
,
src
*
Source
URL
,
user
,
refID
string
)
*
Job
{
job
:=
&
Job
{
im
:
im
,
Show
:
show
,
ID
:
id
,
Source
:
*
src
,
User
:
user
,
RefID
:
refID
}
job
.
State
=
JobNew
job
.
CreatedAt
.
set
(
time
.
Now
())
job
.
subC
.
sourceAttached
=
make
(
chan
struct
{})
...
...
This diff is collapsed.
Click to expand it.
importer/job_source.go
+
2
−
0
View file @
763ecd4c
...
...
@@ -57,6 +57,8 @@ func (job *Job) initializeSource() (err error) {
case
SourceSchemeFake
:
job
.
source
=
newJobSourceFake
(
job
.
Source
)
default
:
// Naughty you! You should have used importer.ParseAndVerifySourceURI which would have
// told you right away that this uri scheme is not supported
return
ErrSourceNotSupported
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment