diff --git a/circle.yml b/circle.yml index 86bafee..a3d2afa 100644 --- a/circle.yml +++ b/circle.yml @@ -6,6 +6,10 @@ dependencies: machine: environment: SECRET_KEY: CI + MONGODB_HOST: mongodb + MONGODB_PORT: 27017 + API_TOKEN: afaketoken + API_URL: "http://localhost/docs/api" services: - docker diff --git a/dockereve-master/.env b/dockereve-master/.env new file mode 100644 index 0000000..2bd1ee8 --- /dev/null +++ b/dockereve-master/.env @@ -0,0 +1,5 @@ +MONGODB_HOST=mongodb +MONGODB_PORT=27017 + +API_TOKEN=afaketoken +API_URL=http://localhost/docs/api diff --git a/dockereve-master/README.md b/dockereve-master/README.md index f111c68..479f408 100644 --- a/dockereve-master/README.md +++ b/dockereve-master/README.md @@ -11,4 +11,13 @@ $ docker-compose up $ curl -i -H "Content-Type: application/json" http://192.168.99.100:80/T1w ``` -Swagger API documentation available at `http://localhost/docs`. \ No newline at end of file +Swagger API documentation available at `http://localhost/docs`. + +## Environment variables in Docker +To properly run the file dockereve-master/.env needs to be created and populated with the following values: +``` +MONGODB_HOST=full url to mongodb host +MONGODB_PORT=port that mongo is running on +API_TOKEN=random string that is used for auth +API_URL=full url to swagger docs in the api +``` diff --git a/dockereve-master/docker-compose.yml b/dockereve-master/docker-compose.yml index 8e62552..f07d0c2 100644 --- a/dockereve-master/docker-compose.yml +++ b/dockereve-master/docker-compose.yml @@ -13,11 +13,11 @@ nginx: swagger_ui: image: swaggerapi/swagger-ui:v3.0.12 - environment: - - API_URL=http://${HOSTNAME}/docs/api + env_file: .env eve: restart: always + env_file: .env build: eve-app expose: - 5000 diff --git a/dockereve-master/eve-app/app.py b/dockereve-master/eve-app/app.py index c425396..e482917 100644 --- a/dockereve-master/eve-app/app.py +++ b/dockereve-master/eve-app/app.py @@ -2,16 +2,18 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: +import os + from eve import Eve from eve.auth import TokenAuth from eve_swagger import swagger -from settings import my_settings as ms +from settings import settings class TokenAuth(TokenAuth): def check_auth(self, token, allowed_roles, resource, method): - return token == '' + return token == os.environ.get("API_TOKEN", '') -app = Eve(settings=ms, auth=TokenAuth) +app = Eve(settings=settings, auth=TokenAuth) app.register_blueprint(swagger, url_prefix='/docs/api') app.add_url_rule('/docs/api', 'eve_swagger.index') diff --git a/dockereve-master/eve-app/settings.py b/dockereve-master/eve-app/settings.py index 46fa621..5bbc0fb 100644 --- a/dockereve-master/eve-app/settings.py +++ b/dockereve-master/eve-app/settings.py @@ -2,8 +2,6 @@ import re from copy import deepcopy -get_mongo_host = re.match('tcp://(.*):(.*)', os.environ['MONGODB_PORT']) - bids_schema = { # BIDS identification bits 'modality': { @@ -550,10 +548,10 @@ } -my_settings = { - 'MONGO_HOST': get_mongo_host.group(1), - 'MONGO_PORT': get_mongo_host.group(2), - 'MONGO_DBNAME': 'scenarios', +settings = { + 'MONGO_HOST': os.environ.get('MONGODB_HOST', ''), + 'MONGO_PORT': os.environ.get('MONGODB_PORT', ''), + 'MONGO_DBNAME': 'mriqc_api', 'PUBLIC_METHODS': ['GET'], 'PUBLIC_ITEM_METHODS': ['GET'], 'RESOURCE_METHODS': ['GET', 'POST'], @@ -574,8 +572,8 @@ } -my_settings['DOMAIN']['bold']['schema'] = deepcopy(bold_iqms_schema) -my_settings['DOMAIN']['bold']['schema'].update( +settings['DOMAIN']['bold']['schema'] = deepcopy(bold_iqms_schema) +settings['DOMAIN']['bold']['schema'].update( { 'bids_meta': { 'type': 'dict', @@ -590,7 +588,7 @@ } ) -my_settings['DOMAIN']['bold']['schema']['bids_meta']['schema'].update({ +settings['DOMAIN']['bold']['schema']['bids_meta']['schema'].update({ 'TaskName': { 'type': 'string', 'required': True @@ -598,8 +596,8 @@ }) -my_settings['DOMAIN']['T1w']['schema'] = deepcopy(struct_iqms_schema) -my_settings['DOMAIN']['T1w']['schema'].update( +settings['DOMAIN']['T1w']['schema'] = deepcopy(struct_iqms_schema) +settings['DOMAIN']['T1w']['schema'].update( { 'bids_meta': { 'type': 'dict', @@ -614,5 +612,5 @@ } ) -my_settings['DOMAIN']['T2w']['schema'] = deepcopy(my_settings['DOMAIN']['T1w']['schema']) +settings['DOMAIN']['T2w']['schema'] = deepcopy(settings['DOMAIN']['T1w']['schema']) diff --git a/dockereve-master/eve-app/test_settings.py b/dockereve-master/eve-app/test_settings.py index cb57f32..d3842b6 100644 --- a/dockereve-master/eve-app/test_settings.py +++ b/dockereve-master/eve-app/test_settings.py @@ -3,11 +3,9 @@ import re from flask_pymongo import MongoClient - -get_mongo_host = re.match('tcp://(.*):(.*)', os.environ['MONGODB_PORT']) -url = 'scenarios' -MONGO_HOST = get_mongo_host.group(1), -MONGO_PORT = int(get_mongo_host.group(2)) +url = 'mriqc_api' +MONGO_HOST = os.environ.get("MONGODB_HOST", 'mongodb'), +MONGO_PORT = int(os.environ.get("MONGODB_PORT", 27017)) MONGO_DBNAME = 'test_DB' class settingsTestCase(TestMinimal): def setUp(self): diff --git a/dockereve-master/nginx/sites-enabled/eve_project b/dockereve-master/nginx/sites-enabled/eve_project index f595fde..4260e20 100644 --- a/dockereve-master/nginx/sites-enabled/eve_project +++ b/dockereve-master/nginx/sites-enabled/eve_project @@ -1,7 +1,7 @@ server { listen 80; - server_name example.org; + server_name _; charset utf-8; location = /docs/api { diff --git a/test/testGetPost.py b/test/testGetPost.py index e602dfa..1bb6447 100644 --- a/test/testGetPost.py +++ b/test/testGetPost.py @@ -31,10 +31,10 @@ def getRequest(post_resp, url): ###### MAIN ###### header = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'} authenticated_header = header.copy() -authenticated_header['Authorization'] = '' +authenticated_header['Authorization'] = os.environ.get('API_TOKEN', '') numOfTestData = 84 -urlBold = "http://localhost:80/bold" -urlT1w = "http://localhost:80/T1w" +urlBold = "http://0.0.0.0:80/bold" +urlT1w = "http://0.0.0.0:80/T1w" codeForInvalid = 422