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
c31d68f0
Commit
c31d68f0
authored
11 years ago
by
Gunnar Schaefer
Browse files
Options
Downloads
Patches
Plain Diff
better upload md5 handling
parent
dd685d83
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nimsapi.py
+10
-6
10 additions, 6 deletions
nimsapi.py
with
10 additions
and
6 deletions
nimsapi.py
+
10
−
6
View file @
c31d68f0
...
...
@@ -29,18 +29,22 @@ class NIMSAPI(nimsapiutil.NIMSRequestHandler):
def
get
(
self
):
self
.
response
.
write
(
'
nimsapi
\n
'
)
def
upload
(
self
,
filename
):
hash_
=
hashlib
.
md5
()
def
upload
(
self
):
# TODO add security: either authenticated user or machine-to-machine CRAM
if
'
Content-MD5
'
not
in
self
.
request
.
headers
:
self
.
abort
(
400
,
'
Request must contain a valid
"
Content-MD5
"
header.
'
)
filename
=
self
.
request
.
get
(
'
filename
'
,
'
anonymous
'
)
stage_path
=
self
.
app
.
config
[
'
stage_path
'
]
with
nimsutil
.
TempDir
(
prefix
=
'
.tmp
'
,
dir
=
stage_path
)
as
tempdir_path
:
hash_
=
hashlib
.
md5
()
upload_filepath
=
os
.
path
.
join
(
tempdir_path
,
filename
)
log
.
info
(
os
.
path
.
basename
(
upload_filepath
))
with
open
(
upload_filepath
,
'
wb
'
)
as
upload_file
:
for
chunk
in
iter
(
lambda
:
self
.
request
.
body_file
.
read
(
2
**
20
),
''
):
hash_
.
update
(
chunk
)
upload_file
.
write
(
chunk
)
if
hash_
.
hexdigest
()
!=
self
.
request
.
get
(
'
md
5
'
)
:
self
.
abort
(
40
6
)
if
hash_
.
hexdigest
()
!=
self
.
request
.
headers
[
'
Content-MD
5
'
]
:
self
.
abort
(
40
0
,
'
Content-MD5 mismatch.
'
)
if
not
tarfile
.
is_tarfile
(
upload_filepath
)
and
not
zipfile
.
is_zipfile
(
upload_filepath
):
self
.
abort
(
415
)
os
.
rename
(
upload_filepath
,
os
.
path
.
join
(
stage_path
,
str
(
uuid
.
uuid1
())
+
'
_
'
+
filename
))
# add UUID to prevent clobbering files
...
...
@@ -94,7 +98,7 @@ class User(nimsapiutil.NIMSRequestHandler):
if
uid
==
self
.
userid
or
self
.
user_is_superuser
:
# users can only update their own info
updates
=
{
'
$set
'
:
{},
'
$unset
'
:
{}}
for
k
,
v
in
self
.
request
.
params
.
iteritems
():
if
k
!=
'
superuser
'
and
k
in
user_fields
:
if
k
!=
'
superuser
'
and
k
in
[]:
#
user_fields:
updates
[
'
$set
'
][
k
]
=
v
# FIXME: do appropriate type conversion
elif
k
==
'
superuser
'
and
uid
==
self
.
userid
and
self
.
user_is_superuser
is
not
None
:
# toggle superuser for requesting user
updates
[
'
$set
'
][
k
]
=
v
.
lower
()
in
(
'
1
'
,
'
true
'
)
...
...
@@ -162,7 +166,7 @@ class ArgumentParser(argparse.ArgumentParser):
routes
=
[
webapp2
.
Route
(
r
'
/nimsapi
'
,
NIMSAPI
),
webapp2
.
Route
(
r
'
/nimsapi/upload
/<:.+>
'
,
NIMSAPI
,
handler_method
=
'
upload
'
,
methods
=
[
'
PUT
'
]),
webapp2
.
Route
(
r
'
/nimsapi/upload
'
,
NIMSAPI
,
handler_method
=
'
upload
'
,
methods
=
[
'
PUT
'
]),
webapp2
.
Route
(
r
'
/nimsapi/download
'
,
NIMSAPI
,
handler_method
=
'
download
'
,
methods
=
[
'
GET
'
]),
webapp2
.
Route
(
r
'
/nimsapi/dump
'
,
NIMSAPI
,
handler_method
=
'
dump
'
,
methods
=
[
'
GET
'
]),
webapp2
.
Route
(
r
'
/nimsapi/users
'
,
Users
),
...
...
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