Adds base href environment variable. Sets base path for API and all routes from BASE_HREF environment variable.

This commit is contained in:
Aaron Louie 2020-05-23 22:07:22 -04:00
parent 6c14248ef9
commit 68084a84cf
3 changed files with 9 additions and 5 deletions

View File

@ -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)

View File

@ -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']]

View File

@ -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 += "<h1>Headers</h1>"