Commit 97d7f0f9 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fix timezone issues with bravado/jsonschema.

parent e330f097
Pipeline #44751 passed with stages
in 26 minutes and 31 seconds
...@@ -17,12 +17,14 @@ All APIs are served by one Flask app (:py:mod:`nomad.api.app`) under different p ...@@ -17,12 +17,14 @@ All APIs are served by one Flask app (:py:mod:`nomad.api.app`) under different p
""" """
from flask import Flask, jsonify from flask import Flask, jsonify
from flask_restplus import Api from flask_restplus import Api, fields
from flask_cors import CORS from flask_cors import CORS
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException
from werkzeug.wsgi import DispatcherMiddleware from werkzeug.wsgi import DispatcherMiddleware
import os.path import os.path
import inspect import inspect
from datetime import datetime
import pytz
from nomad import config, utils from nomad import config, utils
...@@ -120,3 +122,12 @@ def with_logger(func): ...@@ -120,3 +122,12 @@ def with_logger(func):
wrapper.__signature__ = wrapper_signature wrapper.__signature__ = wrapper_signature
return wrapper return wrapper
class RFC3339DateTime(fields.DateTime):
def format(self, value):
if isinstance(value, datetime):
return super().format(value.replace(tzinfo=pytz.utc))
else:
str(value)
...@@ -41,7 +41,7 @@ from datetime import datetime ...@@ -41,7 +41,7 @@ from datetime import datetime
from nomad import config, processing, files, utils, coe_repo from nomad import config, processing, files, utils, coe_repo
from nomad.coe_repo import User, LoginException from nomad.coe_repo import User, LoginException
from .app import app, api from .app import app, api, RFC3339DateTime
app.config['SECRET_KEY'] = config.services.api_secret app.config['SECRET_KEY'] = config.services.api_secret
auth = HTTPBasicAuth() auth = HTTPBasicAuth()
...@@ -145,7 +145,7 @@ user_model = api.model('User', { ...@@ -145,7 +145,7 @@ user_model = api.model('User', {
'token': fields.String( 'token': fields.String(
description='The access token that authenticates the user with the API. ' description='The access token that authenticates the user with the API. '
'User the HTTP header "X-Token" to provide it in API requests.'), 'User the HTTP header "X-Token" to provide it in API requests.'),
'created': fields.DateTime(dt_format='iso8601', description='The create date for the user.') 'created': RFC3339DateTime(description='The create date for the user.')
}) })
...@@ -229,7 +229,7 @@ class UserResource(Resource): ...@@ -229,7 +229,7 @@ class UserResource(Resource):
token_model = api.model('Token', { token_model = api.model('Token', {
'user': fields.Nested(user_model), 'user': fields.Nested(user_model),
'token': fields.String(description='The short term token to sign URLs'), 'token': fields.String(description='The short term token to sign URLs'),
'experies_at': fields.DateTime(desription='The time when the token expires') 'expiries_at': RFC3339DateTime(desription='The time when the token expires')
}) })
......
...@@ -29,7 +29,7 @@ from nomad.processing import Upload, FAILURE ...@@ -29,7 +29,7 @@ from nomad.processing import Upload, FAILURE
from nomad.processing import ProcessAlreadyRunning from nomad.processing import ProcessAlreadyRunning
from nomad.files import ArchiveBasedStagingUploadFiles from nomad.files import ArchiveBasedStagingUploadFiles
from .app import api, with_logger from .app import api, with_logger, RFC3339DateTime
from .auth import login_really_required from .auth import login_really_required
from .common import pagination_request_parser, pagination_model from .common import pagination_request_parser, pagination_model
...@@ -46,8 +46,8 @@ proc_model = api.model('Processing', { ...@@ -46,8 +46,8 @@ proc_model = api.model('Processing', {
'tasks_status': fields.String, 'tasks_status': fields.String,
'errors': fields.List(fields.String), 'errors': fields.List(fields.String),
'warnings': fields.List(fields.String), 'warnings': fields.List(fields.String),
'create_time': fields.DateTime(dt_format='iso8601'), 'create_time': RFC3339DateTime,
'complete_time': fields.DateTime(dt_format='iso8601'), 'complete_time': RFC3339DateTime,
'current_process': fields.String, 'current_process': fields.String,
'process_running': fields.Boolean, 'process_running': fields.Boolean,
}) })
...@@ -64,7 +64,7 @@ metadata_model = api.model('MetaData', { ...@@ -64,7 +64,7 @@ metadata_model = api.model('MetaData', {
'references': fields.List(fields.String, descriptions='References allow to link calculations to external source, e.g. URLs.'), 'references': fields.List(fields.String, descriptions='References allow to link calculations to external source, e.g. URLs.'),
'coauthors': fields.List(fields.Integer, description='A list of co-authors given by user_id.'), 'coauthors': fields.List(fields.Integer, description='A list of co-authors given by user_id.'),
'shared_with': fields.List(fields.Integer, description='A list of users to share calculations with given by user_id.'), 'shared_with': fields.List(fields.Integer, description='A list of users to share calculations with given by user_id.'),
'_upload_time': fields.DateTime(dt_format='iso8601', description='Overrride the upload time.'), '_upload_time': RFC3339DateTime(description='Overrride the upload time.'),
'_uploader': fields.Integer(description='Override the uploader with the given user id.'), '_uploader': fields.Integer(description='Override the uploader with the given user id.'),
'datasets': fields.List(fields.Nested(model=dataset_model), description='A list of datasets.') 'datasets': fields.List(fields.Nested(model=dataset_model), description='A list of datasets.')
}) })
...@@ -86,7 +86,7 @@ upload_model = api.inherit('UploadProcessing', proc_model, { ...@@ -86,7 +86,7 @@ upload_model = api.inherit('UploadProcessing', proc_model, {
description='The unique id for the upload.'), description='The unique id for the upload.'),
'metadata': fields.Nested(model=upload_metadata_model, description='Additional upload and calculation meta data.'), 'metadata': fields.Nested(model=upload_metadata_model, description='Additional upload and calculation meta data.'),
'local_path': fields.String, 'local_path': fields.String,
'upload_time': fields.DateTime(dt_format='iso8601'), 'upload_time': RFC3339DateTime(),
}) })
calc_model = api.inherit('UploadCalculationProcessing', proc_model, { calc_model = api.inherit('UploadCalculationProcessing', proc_model, {
......
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