From 68084a84cf0648aa48dc40f2c6d66ca97101402e Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Sat, 23 May 2020 22:07:22 -0400 Subject: [PATCH] Adds base href environment variable. Sets base path for API and all routes from BASE_HREF environment variable. --- config/default.py | 8 ++++++-- crc/__init__.py | 2 +- crc/api/user.py | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config/default.py b/config/default.py index f31f2889..cb6cb832 100644 --- a/config/default.py +++ b/config/default.py @@ -13,6 +13,9 @@ DEVELOPMENT = environ.get('DEVELOPMENT', default="true") == "true" TESTING = environ.get('TESTING', default="false") == "true" PRODUCTION = (environ.get('PRODUCTION', default="false") == "true") or (not DEVELOPMENT and not TESTING) +# Add trailing slash to base path +BASE_HREF = re.sub(r'//', '/', '/%s/' % environ.get('BASE_HREF', default="/").strip('/')) + DB_HOST = environ.get('DB_HOST', default="localhost") DB_PORT = environ.get('DB_PORT', default="5432") DB_NAME = environ.get('DB_NAME', default="crc_dev") @@ -29,13 +32,13 @@ SWAGGER_AUTH_KEY = environ.get('SWAGGER_AUTH_KEY', default="SWAGGER") # %s/%i placeholders expected for uva_id and study_id in various calls. PB_ENABLED = environ.get('PB_ENABLED', default=True) -PB_BASE_URL = environ.get('PB_BASE_URL', default="http://localhost:5001/pb/") +PB_BASE_URL = environ.get('PB_BASE_URL', default="http://localhost:5001/pb/").strip('/') + '/' # Trailing slash required PB_USER_STUDIES_URL = environ.get('PB_USER_STUDIES_URL', default=PB_BASE_URL + "user_studies?uva_id=%s") PB_INVESTIGATORS_URL = environ.get('PB_INVESTIGATORS_URL', default=PB_BASE_URL + "investigators?studyid=%i") PB_REQUIRED_DOCS_URL = environ.get('PB_REQUIRED_DOCS_URL', default=PB_BASE_URL + "required_docs?studyid=%i") PB_STUDY_DETAILS_URL = environ.get('PB_STUDY_DETAILS_URL', default=PB_BASE_URL + "study?studyid=%i") -LDAP_URL = environ.get('LDAP_URL', default="ldap.virginia.edu") +LDAP_URL = environ.get('LDAP_URL', default="ldap.virginia.edu").strip('/') # No trailing slash or http:// LDAP_TIMEOUT_SEC = environ.get('LDAP_TIMEOUT_SEC', default=3) print('=== USING DEFAULT CONFIG: ===') print('DB_HOST = ', DB_HOST) @@ -45,4 +48,5 @@ print('TESTING = ', TESTING) print('PRODUCTION = ', PRODUCTION) print('PB_BASE_URL = ', PB_BASE_URL) print('LDAP_URL = ', LDAP_URL) +print('BASE_HREF = ', BASE_HREF) diff --git a/crc/__init__.py b/crc/__init__.py index 9f1c4ee3..c0569e68 100644 --- a/crc/__init__.py +++ b/crc/__init__.py @@ -34,7 +34,7 @@ ma = Marshmallow(app) from crc import models from crc import api -connexion_app.add_api('api.yml') +connexion_app.add_api('api.yml', base_path=app.config['BASE_HREF'] + 'v1.0') # Convert list of allowed origins to list of regexes origins_re = [r"^https?:\/\/%s(.*)" % o.replace('.', '\.') for o in app.config['CORS_ALLOW_ORIGINS']] diff --git a/crc/api/user.py b/crc/api/user.py index 3e423fc6..cb3bd91d 100644 --- a/crc/api/user.py +++ b/crc/api/user.py @@ -32,7 +32,7 @@ def verify_token(token): def get_current_user(): return UserModelSchema().dump(g.user) -@app.route('/v1.0/login') +@app.route(app.config['BASE_HREF'] + 'v1.0/login') def sso_login(): # This what I see coming back: # X-Remote-Cn: Daniel Harold Funk (dhf8r) @@ -67,7 +67,7 @@ def sso_login(): return _handle_login(info, redirect) -@app.route('/sso') +@app.route(app.config['BASE_HREF'] + 'sso') def sso(): response = "" response += "

Headers

"