Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
b6e48be5
Commit
b6e48be5
authored
7 years ago
by
Harsha Kethineni
Browse files
Options
Downloads
Patches
Plain Diff
Checks file form in process_upload
parent
61cde698
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/files.py
+0
-10
0 additions, 10 deletions
api/files.py
api/placer.py
+9
-29
9 additions, 29 deletions
api/placer.py
api/upload.py
+3
-3
3 additions, 3 deletions
api/upload.py
api/web/base.py
+1
-1
1 addition, 1 deletion
api/web/base.py
with
13 additions
and
43 deletions
api/files.py
+
0
−
10
View file @
b6e48be5
...
...
@@ -48,16 +48,6 @@ def hash_file_formatted(path, hash_alg=None, buffer_size=65536):
return
util
.
format_hash
(
hash_alg
,
hasher
.
hexdigest
())
<<<<<<<
HEAD
=======
class
FileStoreException
(
Exception
):
pass
class
FileFormException
(
Exception
):
pass
>>>>>>>
Empty
uploads
400
instead
of
500
class
HashingFile
(
file
):
def
__init__
(
self
,
file_path
,
hash_alg
):
super
(
HashingFile
,
self
).
__init__
(
file_path
,
"
wb
"
)
...
...
This diff is collapsed.
Click to expand it.
api/placer.py
+
9
−
29
View file @
b6e48be5
...
...
@@ -18,14 +18,14 @@ from .jobs import rules
from
.jobs.jobs
import
Job
from
.types
import
Origin
from
.web
import
encoder
from
.web.errors
import
FileFormException
class
Placer
(
object
):
"""
Interface for a placer, which knows how to process files and place them where they belong - on disk and database.
"""
def
__init__
(
self
,
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
,
file_fields
):
def
__init__
(
self
,
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
):
self
.
container_type
=
container_type
self
.
container
=
container
self
.
id_
=
id_
...
...
@@ -43,7 +43,6 @@ class Placer(object):
# A list of files that have been saved via save_file() usually returned by finalize()
self
.
saved
=
[]
self
.
file_fields
=
file_fields
def
check
(
self
):
...
...
@@ -76,15 +75,7 @@ class Placer(object):
Helper function that throws unless metadata was provided.
"""
if
self
.
metadata
==
None
:
raise
files
.
FileFormException
(
'
Metadata required
'
)
def
requireFiles
(
self
):
"""
Helper function that throws unless metadata was provided.
"""
if
not
self
.
file_fields
or
len
(
self
.
file_fields
)
<
1
:
raise
files
.
FileFormException
(
'
No files selected to upload
'
)
raise
FileFormException
(
'
Metadata required
'
)
def
save_file
(
self
,
field
=
None
,
file_attrs
=
None
):
"""
...
...
@@ -123,16 +114,6 @@ class TargetedPlacer(Placer):
An exception is thrown in upload.process_upload() if you try. This could be fixed by making a better schema.
"""
# TODO: Change schemas to enabled targeted uploads of more than one file.
# Ref docs from placer.TargetedPlacer for details.
def
requireFiles
(
self
):
"""
Helper function that throws unless metadata was provided.
"""
if
not
self
.
file_fields
or
len
(
self
.
file_fields
)
!=
1
:
raise
files
.
FileFormException
(
"
Targeted uploads can only send one file
"
)
def
check
(
self
):
self
.
requireTarget
()
validators
.
validate_data
(
self
.
metadata
,
'
file.json
'
,
'
input
'
,
'
POST
'
,
optional
=
True
)
...
...
@@ -157,14 +138,13 @@ class UIDPlacer(Placer):
create_hierarchy
=
staticmethod
(
hierarchy
.
upsert_top_down_hierarchy
)
match_type
=
'
uid
'
def
__init__
(
self
,
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
,
file_fields
):
super
(
UIDPlacer
,
self
).
__init__
(
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
,
file_fields
)
def
__init__
(
self
,
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
):
super
(
UIDPlacer
,
self
).
__init__
(
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
)
self
.
metadata_for_file
=
{}
self
.
session_id
=
None
def
check
(
self
):
self
.
requireMetadata
()
self
.
requireFiles
()
payload_schema_uri
=
validators
.
schema_uri
(
'
input
'
,
self
.
metadata_schema
)
metadata_validator
=
validators
.
from_schema_path
(
payload_schema_uri
)
...
...
@@ -335,8 +315,8 @@ class TokenPlacer(Placer):
Intended for use with a token that tracks where the files will be stored.
"""
def
__init__
(
self
,
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
,
file_fields
):
super
(
TokenPlacer
,
self
).
__init__
(
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
,
file_fields
)
def
__init__
(
self
,
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
):
super
(
TokenPlacer
,
self
).
__init__
(
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
)
self
.
paths
=
[]
self
.
folder
=
None
...
...
@@ -374,8 +354,8 @@ class PackfilePlacer(Placer):
A placer that can accept N files, save them into a zip archive, and place the result on an acquisition.
"""
def
__init__
(
self
,
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
,
file_fields
):
super
(
PackfilePlacer
,
self
).
__init__
(
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
,
file_fields
)
def
__init__
(
self
,
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
):
super
(
PackfilePlacer
,
self
).
__init__
(
container_type
,
container
,
id_
,
metadata
,
timestamp
,
origin
,
context
)
# This endpoint is an SSE endpoint
self
.
sse
=
True
...
...
This diff is collapsed.
Click to expand it.
api/upload.py
+
3
−
3
View file @
b6e48be5
...
...
@@ -5,7 +5,7 @@ import os.path
import
shutil
from
.web
import
base
from
.web.errors
import
FileStoreException
from
.web.errors
import
FileStoreException
,
FileFormException
from
.
import
config
from
.
import
files
from
.
import
placer
as
pl
...
...
@@ -93,9 +93,9 @@ def process_upload(request, strategy, container_type=None, id_=None, origin=None
# TODO: Change schemas to enabled targeted uploads of more than one file.
# Ref docs from placer.TargetedPlacer for details.
if
strategy
==
Strategy
.
targeted
and
len
(
file_fields
)
>
1
:
raise
Exception
(
"
Targeted uploads can only send one file
"
)
raise
FileForm
Exception
(
"
Targeted uploads can only send one file
"
)
elif
strategy
in
[
Strategy
.
reaper
,
Strategy
.
uidupload
,
Strategy
.
labelupload
,
Strategy
.
uidmatch
]
and
len
(
file_fields
)
<
1
:
raise
Exception
(
"
No files selected for uploading
"
)
raise
FileForm
Exception
(
"
No files selected for uploading
"
)
placer
.
check
()
...
...
This diff is collapsed.
Click to expand it.
api/web/base.py
+
1
−
1
View file @
b6e48be5
...
...
@@ -358,7 +358,7 @@ class RequestHandler(webapp2.RequestHandler):
code
=
400
elif
isinstance
(
exception
,
errors
.
FileFormException
):
code
=
400
elif
isinstance
(
exception
,
file
s
.
FileFormException
):
elif
isinstance
(
exception
,
error
s
.
FileFormException
):
code
=
400
elif
isinstance
(
exception
,
ElasticsearchException
):
code
=
503
...
...
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