Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
9040a9db
Commit
9040a9db
authored
Dec 22, 2018
by
Markus Scheidgen
Browse files
Added endpoint for providing url and commands for upload. Removed per upload commands/urls.
parent
57392d52
Changes
3
Hide whitespace changes
Inline
Side-by-side
nomad/api/upload.py
View file @
9040a9db
...
...
@@ -21,6 +21,7 @@ from flask import g, request
from
flask_restplus
import
Resource
,
fields
,
abort
from
datetime
import
datetime
from
nomad
import
config
from
nomad.processing
import
Upload
from
nomad.processing
import
NotAllowedDuringProcessing
from
nomad.utils
import
get_logger
...
...
@@ -60,8 +61,6 @@ upload_model = api.inherit('UploadProcessing', proc_model, {
'used within nomad to identify uploads.'
),
'additional_metadata'
:
fields
.
Arbitrary
,
'upload_url'
:
fields
.
String
,
'upload_command'
:
fields
.
String
,
'local_path'
:
fields
.
String
,
'upload_time'
:
fields
.
DateTime
(
dt_format
=
'iso8601'
),
})
...
...
@@ -298,3 +297,26 @@ class UploadResource(Resource):
return
upload
,
200
abort
(
400
,
message
=
'Unsuported operation %s.'
%
operation
)
upload_command_model
=
api
.
model
(
'UploadCommand'
,
{
'upload_url'
:
fields
.
Url
,
'upload_command'
:
fields
.
String
})
@
ns
.
route
(
'/command'
)
class
UploadCommandResource
(
Resource
):
@
api
.
marshal_with
(
upload_command_model
,
code
=
200
,
description
=
'Upload command send'
)
@
login_really_required
def
get
(
self
):
""" Get url and example command for shell based uploads. """
upload_url
=
'http://%s:%s%s/uploads/'
%
(
config
.
services
.
api_host
,
config
.
services
.
api_port
,
config
.
services
.
api_base_path
)
upload_command
=
'curl -H "X-Token: "%s" "%s" --upload-file <local_file>'
%
(
g
.
user
.
get_auth_token
().
decode
(
'utf-8'
),
upload_url
)
return
dict
(
upload_url
=
upload_url
,
upload_command
=
upload_command
),
200
nomad/processing/data.py
View file @
9040a9db
...
...
@@ -28,12 +28,11 @@ from typing import List, Any, ContextManager, Tuple, Generator
from
elasticsearch.exceptions
import
NotFoundError
from
mongoengine
import
StringField
,
BooleanField
,
DateTimeField
,
DictField
,
IntField
import
logging
import
base64
import
time
from
structlog
import
wrap_logger
from
contextlib
import
contextmanager
from
nomad
import
config
,
utils
,
coe_repo
from
nomad
import
utils
,
coe_repo
from
nomad.files
import
UploadFile
,
ArchiveFile
,
ArchiveLogFile
,
File
from
nomad.repo
import
RepoCalc
from
nomad.processing.base
import
Proc
,
Chord
,
process
,
task
,
PENDING
,
SUCCESS
,
FAILURE
,
RUNNING
...
...
@@ -325,8 +324,6 @@ class Upload(Chord):
upload_hash
=
StringField
(
default
=
None
)
user_id
=
StringField
(
required
=
True
)
upload_url
=
StringField
(
default
=
None
)
upload_command
=
StringField
(
default
=
None
)
coe_repo_upload_id
=
IntField
(
default
=
None
)
...
...
@@ -386,13 +383,6 @@ class Upload(Chord):
with
lnr
(
logger
,
'deleting upload'
):
super
().
delete
()
@
classmethod
def
_external_objects_url
(
cls
,
url
):
""" Replaces the given internal object storage url with an URL that allows
external access.
"""
return
'http://%s:%s%s%s'
%
(
config
.
services
.
api_host
,
config
.
services
.
api_port
,
config
.
services
.
api_base_path
,
url
)
@
classmethod
def
create
(
cls
,
**
kwargs
)
->
'Upload'
:
"""
...
...
@@ -410,12 +400,6 @@ class Upload(Chord):
kwargs
.
update
(
user_id
=
str
(
user
.
user_id
))
self
=
super
().
create
(
**
kwargs
)
basic_auth_token
=
base64
.
b64encode
(
b
'%s:'
%
user
.
get_auth_token
()).
decode
(
'utf-8'
)
self
.
upload_url
=
cls
.
_external_objects_url
(
'/uploads/%s/file'
%
self
.
upload_id
)
self
.
upload_command
=
'curl -H "Authorization: Basic %s" "%s" --upload-file local_file'
%
(
basic_auth_token
,
self
.
upload_url
)
self
.
_continue_with
(
'uploading'
)
return
self
...
...
tests/test_api.py
View file @
9040a9db
...
...
@@ -115,8 +115,6 @@ class TestUploads:
if
id
is
not
None
:
assert
id
==
data
[
'upload_id'
]
assert
'create_time'
in
data
assert
'upload_url'
in
data
assert
'upload_command'
in
data
for
key
,
value
in
kwargs
.
items
():
assert
data
.
get
(
key
,
None
)
==
value
...
...
@@ -170,6 +168,13 @@ class TestUploads:
self
.
assert_uploads
(
rv
.
data
,
count
=
0
)
assert_coe_upload
(
upload
[
'upload_hash'
],
proc_infra
[
'repository_db'
],
empty
=
empty_upload
)
def
test_get_command
(
self
,
client
,
test_user_auth
,
no_warn
):
rv
=
client
.
get
(
'/uploads/command'
,
headers
=
test_user_auth
)
assert
rv
.
status_code
==
200
data
=
json
.
loads
(
rv
.
data
)
assert
'upload_command'
in
data
assert
'upload_url'
in
data
def
test_get_empty
(
self
,
client
,
test_user_auth
,
no_warn
):
rv
=
client
.
get
(
'/uploads/'
,
headers
=
test_user_auth
)
...
...
Write
Preview
Supports
Markdown
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