Skip to content

Commit c372332

Browse files
authored
Merge branch 'master' into shutdown
2 parents a51035c + 2d992b9 commit c372332

25 files changed

+427
-203
lines changed

.circleci/config.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
version: 2.1
2+
orbs:
3+
docker: circleci/docker@2.1.4
4+
5+
jobs:
6+
7+
build_and_test:
8+
working_directory: /home/circleci/mriqcwebapi
9+
10+
machine:
11+
image: ubuntu-2004:202104-01
12+
docker_layer_caching: true
13+
14+
environment:
15+
- SECRET_KEY: CI
16+
- MONGODB_HOST: mongodb
17+
- MONGODB_PORT: 27017
18+
- API_TOKEN: <secret_token>
19+
- API_URL: "http://localhost/docs/api"
20+
21+
steps:
22+
- docker/install-docker-credential-helper
23+
- run:
24+
name: Docker authentication
25+
command: |
26+
if [[ -n $DOCKER_PAT ]]; then
27+
echo "$DOCKER_PAT" | docker login -u $DOCKER_USER --password-stdin
28+
fi
29+
30+
- checkout
31+
- run:
32+
name: Install dependencies
33+
command: |
34+
python3 -m pip install --upgrade pip
35+
python3 -m pip install docker-compose
36+
python3 -m pip install requests
37+
- run:
38+
name: Set-up dockereve
39+
command: |
40+
mkdir -p dockereve-master/nginx/.ssl
41+
touch dockereve-master/nginx/.ssl/mriqcep.crt
42+
touch dockereve-master/nginx/.ssl/mriqcep.key
43+
docker pull mongo:latest
44+
docker pull swaggerapi/swagger-ui:latest
45+
docker pull nginx:latest
46+
docker-compose -f dockereve-master/docker-compose.yml build
47+
- run:
48+
name: Start server
49+
command: docker-compose -f dockereve-master/docker-compose.yml up -d
50+
- run:
51+
name: Test MRIQC WebAPI
52+
command: python3 test/testGetPost.py
53+
54+
workflows:
55+
version: 2
56+
webapi:
57+
jobs:
58+
- build_and_test:
59+
context:
60+
- nipreps-common
61+
filters:
62+
tags:
63+
only: /.*/

circle.yml

-25
This file was deleted.

dockereve-master/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ nginx:
1616
- swagger_ui:swagger_ui
1717

1818
swagger_ui:
19-
image: swaggerapi/swagger-ui:v3.0.12
19+
image: swaggerapi/swagger-ui:latest
2020
env_file: .env
2121

2222
eve:

dockereve-master/eve-app/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM python:3.4-onbuild
1+
FROM python:3.6-onbuild
22

33
WORKDIR /usr/src/app
44

55
ADD . /usr/src/app
66

77
RUN pip3 install -r requirements.txt
88
RUN pip3 install pytest
9-
RUN sed -i 's/\[scheme\]/\["https"\]/' /usr/local/lib/python3.4/site-packages/eve_swagger/objects.py
9+
RUN sed -i 's/\[scheme\]/\["https"\]/' /usr/local/lib/python3.6/site-packages/eve_swagger/objects.py
1010

1111
#EXPOSE 5000
1212
#CMD ["python3", "server.py"]

dockereve-master/eve-app/app.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,28 @@
66

77
from eve import Eve
88
from eve.auth import TokenAuth
9-
from eve_swagger import swagger
9+
from eve_swagger import get_swagger_blueprint
1010
from settings import settings
1111

1212
API_TOKEN = os.environ.get("API_TOKEN")
1313

14+
1415
class TokenAuth(TokenAuth):
1516
def check_auth(self, token, allowed_roles, resource, method):
1617
return token == API_TOKEN
1718

19+
1820
app = Eve(settings=settings, auth=TokenAuth)
21+
swagger = get_swagger_blueprint()
1922
app.register_blueprint(swagger, url_prefix='/docs/api')
2023
app.add_url_rule('/docs/api', 'eve_swagger.index')
2124

2225
# required. See http://swagger.io/specification/#infoObject for details.
2326
app.config['SWAGGER_INFO'] = {
2427
'title': 'MRIQC Web API',
2528
'version': 'v1',
26-
'description': """<p>####################################################<br />
29+
'description': """\
30+
<p>####################################################<br />
2731
Because of a lapse in government funding, the information on this website
2832
may not be up to date, transactions submitted via the website may not be
2933
processed, and the agency may not be able to respond to inquiries until
@@ -35,7 +39,7 @@ def check_auth(self, token, allowed_roles, resource, method):
3539
no-reference image quality metrics from structural and
3640
functional MRI data developed by the <a href="http://poldracklab.stanford.edu">
3741
Poldrack Lab</a> at <a href="http://www.stanford.edu">Stanford University</a>.
38-
This website provides an api to a crowdsourced repository of MRI quality
42+
This website provides an API to a crowdsourced repository of MRI quality
3943
metrics contributed by users of MRIQC and hosted by
4044
the <a href="http://cmn.nimh.nih.gov">Data Science and Sharing Team</a>
4145
at the <a href="http://nimh.nih.gov">National Institute of Mental Health</a>.</p>""",
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
gunicorn==19.3.0
2-
eve==0.7.4
3-
eve-swagger==0.0.7
1+
gunicorn
2+
eve
3+
eve-swagger>=0.1

dockereve-master/eve-app/settings.py

+76-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import re
32
from copy import deepcopy
43

54
bids_schema = {
@@ -43,7 +42,7 @@
4342
'InversionTime': {'type': 'float'},
4443
'MRAcquisitionType': {'type': 'string'},
4544
'MRTransmitCoilSequence': {'type': 'string'},
46-
'MagneticFieldStrength': {'type': 'integer'},
45+
'MagneticFieldStrength': {'type': 'float'},
4746
'Manufacturer': {'type': 'string'},
4847
'ManufacturersModelName': {'type': 'string'},
4948
'MatrixCoilMode': {'type': 'string'},
@@ -553,13 +552,14 @@
553552
'API_VERSION': 'v1',
554553
'ALLOWED_FILTERS': ['*'],
555554
'MONGO_HOST': os.environ.get('MONGODB_HOST', ''),
556-
'MONGO_PORT': os.environ.get('MONGODB_PORT', ''),
555+
'MONGO_PORT': int(os.environ.get('MONGODB_PORT', 27017)),
557556
'MONGO_DBNAME': 'mriqc_api',
558557
'PUBLIC_METHODS': ['GET'],
559558
'PUBLIC_ITEM_METHODS': ['GET'],
560559
'RESOURCE_METHODS': ['GET', 'POST'],
561560
'ITEM_METHODS': ['GET'],
562561
'X_DOMAINS': '*',
562+
'X_HEADERS': ['Authorization', 'Content-Type'],
563563
'DOMAIN': {
564564
'bold': {
565565
'item_title': 'bold',
@@ -574,6 +574,72 @@
574574
}
575575
}
576576

577+
rating_schema = {
578+
'rating': {
579+
'type': 'string',
580+
'required': True
581+
},
582+
'name': {
583+
'type': 'string',
584+
'required': False
585+
},
586+
'comment': {
587+
'type': 'string',
588+
'required': False
589+
},
590+
'md5sum': {
591+
'type': 'string',
592+
'required': True
593+
}
594+
}
595+
596+
nipype_schema = {
597+
'interface_class_name': {
598+
'type': 'string',
599+
'required': True
600+
},
601+
'version': {
602+
'type': 'string',
603+
'required': True
604+
},
605+
'mem_peak_gb': {
606+
'type': 'float',
607+
'required': True
608+
},
609+
'duration_sec': {
610+
'type': 'float',
611+
'required': True
612+
},
613+
'inputs': {
614+
'type': 'dict',
615+
'required': True
616+
}
617+
}
618+
619+
settings['DOMAIN']['nipype_telemetry'] = {
620+
'type': 'dict',
621+
'required': False,
622+
'schema': deepcopy(nipype_schema)
623+
}
624+
625+
settings['DOMAIN']['rating'] ={
626+
'type': 'dict',
627+
'required': False,
628+
'schema': deepcopy(rating_schema)
629+
}
630+
631+
settings['DOMAIN']['rating_counts'] = {
632+
'datasource': {
633+
'source': 'rating',
634+
'aggregation': {
635+
'pipeline': [
636+
{"$match": {"md5sum": "$value"}},
637+
{"$unwind": "$rating"},
638+
{"$group": {"_id": "$rating", "count": {"$sum": 1}}},
639+
],
640+
}
641+
}
642+
}
577643

578644
settings['DOMAIN']['bold']['schema'] = deepcopy(bold_iqms_schema)
579645
settings['DOMAIN']['bold']['schema'].update(
@@ -588,7 +654,12 @@
588654
'type': 'dict',
589655
'required': True,
590656
'schema': deepcopy(prov_schema)
591-
}
657+
},
658+
'rating': {
659+
'type': 'dict',
660+
'required': False,
661+
'schema': deepcopy(rating_schema)
662+
},
592663
}
593664
)
594665

@@ -613,9 +684,8 @@
613684
'type': 'dict',
614685
'required': True,
615686
'schema': deepcopy(prov_schema)
616-
}
687+
},
617688
}
618689
)
619690

620691
settings['DOMAIN']['T2w']['schema'] = deepcopy(settings['DOMAIN']['T1w']['schema'])
621-
+32-31
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
11
from eve.tests import TestMinimal
22
import os
3-
import re
43
from flask_pymongo import MongoClient
54

65
url = 'mriqc_api'
76
MONGO_HOST = os.environ.get("MONGODB_HOST", 'mongodb'),
87
MONGO_PORT = int(os.environ.get("MONGODB_PORT", 27017))
98
MONGO_DBNAME = 'test_DB'
9+
10+
1011
class settingsTestCase(TestMinimal):
11-
def setUp(self):
12-
return super().setUp(settings_file = './settings.py')
13-
def dropDB(self):
14-
self.connection = MongoClient(MONGO_HOST,MONGO_PORT)
15-
self.connection.drop_database(MONGO_DBNAME)
16-
self.connection.close()
17-
def setupDB(self):
18-
self.connection = MongoClient(MONGO_HOST,MONGO_PORT)
19-
self.connection.drop_database(MONGO_DBNAME)
20-
def testGet(self):
21-
return_json,return_code = self.get(url)
22-
self.assert200(return_code)
23-
def testPost(self):
24-
return_json, return_code = self.post(url, {"cjv": 0.1231231})
25-
self.assertFalse(self.domain)
26-
self.assertFalse(return_json)
27-
# self.assert200(return_code)
28-
29-
# class settingsTestCase(TestMinimal):
30-
# def dropDB(self):
31-
# self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
32-
# self.connection.drop_database(MONGO_DBNAME)
33-
# self.connection.close()
12+
def setUp(self):
13+
return super().setUp(settings_file='./settings.py')
3414

35-
# def setupDB(self):
36-
# self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
37-
# self.connection.drop_database(MONGO_DBNAME)
38-
# def testPost():
39-
# return_json, return_code = self.post(url,{"cjg":0.123123})
40-
# print(return_json)
41-
# print(return_code)
15+
def dropDB(self):
16+
self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
17+
self.connection.drop_database(MONGO_DBNAME)
18+
self.connection.close()
4219

20+
def setupDB(self):
21+
self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
22+
self.connection.drop_database(MONGO_DBNAME)
4323

24+
def testGet(self):
25+
return_json, return_code = self.get(url)
26+
self.assert200(return_code)
4427

28+
def testPost(self):
29+
return_json, return_code = self.post(url, {"cjv": 0.1231231})
30+
self.assertFalse(self.domain)
31+
self.assertFalse(return_json)
32+
# self.assert200(return_code)
33+
34+
# class settingsTestCase(TestMinimal):
35+
# def dropDB(self):
36+
# self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
37+
# self.connection.drop_database(MONGO_DBNAME)
38+
# self.connection.close()
4539

40+
# def setupDB(self):
41+
# self.connection = MongoClient(MONGO_HOST, MONGO_PORT)
42+
# self.connection.drop_database(MONGO_DBNAME)
43+
# def testPost():
44+
# return_json, return_code = self.post(url,{"cjg":0.123123})
45+
# print(return_json)
46+
# print(return_code)

0 commit comments

Comments
 (0)