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
``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
------

View file

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