-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (40 loc) · 2.4 KB
/
main.py
File metadata and controls
48 lines (40 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import importlib
import os
import sys
from pathlib import Path
from flask import Flask
from yaml import safe_load
sys.path.append("search-adaptor/src")
search_adaptor_module = importlib.import_module("app", "search-adaptor/src")
config = {}
app = Flask(__name__, instance_path=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'instance'),
instance_relative_config=True)
app.config.from_pyfile('app.cfg')
# load the index configurations and set the default
config['INDICES'] = safe_load((Path(__file__).absolute().parent / 'instance/search-config.yaml').read_text())
config['DEFAULT_INDEX_WITHOUT_PREFIX'] = config['INDICES']['default_index']
# Remove trailing slash / from URL base to avoid "//" caused by config with trailing slash
config['DEFAULT_ELASTICSEARCH_URL'] = config['INDICES']['indices'][config['DEFAULT_INDEX_WITHOUT_PREFIX']]['elasticsearch']['url'].strip('/')
config['DEFAULT_ENTITY_API_URL'] = config['INDICES']['indices'][config['DEFAULT_INDEX_WITHOUT_PREFIX']]['document_source_endpoint'].strip('/')
config['APP_CLIENT_ID'] = app.config['APP_CLIENT_ID']
config['APP_CLIENT_SECRET'] = app.config['APP_CLIENT_SECRET']
config['AWS_ACCESS_KEY_ID'] = app.config['AWS_ACCESS_KEY_ID']
config['AWS_SECRET_ACCESS_KEY'] = app.config['AWS_SECRET_ACCESS_KEY']
config['AWS_S3_BUCKET_NAME'] = app.config['AWS_S3_BUCKET_NAME']
config['AWS_S3_OBJECT_PREFIX'] = app.config['AWS_S3_OBJECT_PREFIX']
config['AWS_OBJECT_URL_EXPIRATION_IN_SECS'] = app.config['AWS_OBJECT_URL_EXPIRATION_IN_SECS']
config['LARGE_RESPONSE_THRESHOLD'] = app.config['LARGE_RESPONSE_THRESHOLD']
config['CONSORTIUM_ID'] = app.config['CONSORTIUM_ID']
config['PARAM_SEARCH_RECOGNIZED_ENTITIES_BY_INDEX'] = app.config['PARAM_SEARCH_RECOGNIZED_ENTITIES_BY_INDEX']
config['ONTOLOGY_API_BASE_URL'] = app.config['ONTOLOGY_API_BASE_URL'].strip('/')
config['DEBUG_MODE'] = app.config['DEBUG_MODE']
if not config['ONTOLOGY_API_BASE_URL']:
raise Exception(f"Unable retrieve ontology information using"
f" URL '{config['ONTOLOGY_API_BASE_URL']}'.")
translator_module = importlib.import_module("hubmap_translator")
# This `app` will be imported by wsgi.py when deployed with uWSGI server
app = search_adaptor_module.SearchAPI( config=config
, translator_module=translator_module).app
# For local standalone (non-docker) development/testing
if __name__ == "__main__":
app.run(host='0.0.0.0', port="5005")