Commit 9040a9db authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added endpoint for providing url and commands for upload. Removed per upload commands/urls.

parent 57392d52
......@@ -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
class UploadCommandResource(Resource):
@api.marshal_with(upload_command_model, code=200, description='Upload command send')
def get(self):
""" Get url and example command for shell based uploads. """
upload_url = 'http://%s:%s%s/uploads/' % (,,
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
......@@ -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'):
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' % (,,, url)
def create(cls, **kwargs) -> 'Upload':
......@@ -410,12 +400,6 @@ class Upload(Chord):
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)
return self
......@@ -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(, 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(
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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment