Allowing full host override (#143)

This commit is contained in:
Omer Hamerman 2021-07-29 18:39:47 +01:00 committed by GitHub
parent 89a90f4924
commit 40df900dc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -98,6 +98,8 @@ need to change this.
``REDIS_PREFIX``: (optional, defaults to ``"snappass"``) prefix used on redis keys to prevent collisions with other potential clients ``REDIS_PREFIX``: (optional, defaults to ``"snappass"``) prefix used on redis keys to prevent collisions with other potential clients
``HOST_OVERRIDE``: (optional) Used to override the base URL if the app is unaware. Useful when running behind reverse proxies like an identity-aware SSO. Example: ``sub.domain.com``
Docker Docker
------ ------

View file

@ -13,6 +13,7 @@ from distutils.util import strtobool
NO_SSL = bool(strtobool(os.environ.get('NO_SSL', 'False'))) NO_SSL = bool(strtobool(os.environ.get('NO_SSL', 'False')))
URL_PREFIX = os.environ.get('URL_PREFIX', None) URL_PREFIX = os.environ.get('URL_PREFIX', None)
HOST_OVERRIDE = os.environ.get('HOST_OVERRIDE', None)
TOKEN_SEPARATOR = '~' TOKEN_SEPARATOR = '~'
@ -164,7 +165,13 @@ def handle_password():
token = set_password(password, ttl) token = set_password(password, ttl)
if NO_SSL: if NO_SSL:
if HOST_OVERRIDE:
base_url = f'http://{HOST_OVERRIDE}/'
else:
base_url = request.url_root base_url = request.url_root
else:
if HOST_OVERRIDE:
base_url = f'https://{HOST_OVERRIDE}/'
else: else:
base_url = request.url_root.replace("http://", "https://") base_url = request.url_root.replace("http://", "https://")
if URL_PREFIX: if URL_PREFIX: