From c9a78a9a7ac8920f311b8c0b26a0e9f464ca20b6 Mon Sep 17 00:00:00 2001 From: Francesco Bartoli Date: Thu, 6 Sep 2018 09:45:54 +0200 Subject: [PATCH] Fix #3893 * Remove duplicates from allowed_hosts * Fix #3893 --- tasks.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tasks.py b/tasks.py index 1a9a401b866..84831350c89 100755 --- a/tasks.py +++ b/tasks.py @@ -35,22 +35,34 @@ def update(ctx): "geodburl": geodb_url, "override_fn": override_env } - if not os.environ.get('GEOSERVER_PUBLIC_LOCATION'): + if os.environ.get( + 'GEONODE_LB_HOST_IP' + ) and os.environ.get( + 'GEONODE_LB_PORT' + ): ctx.run("echo export GEOSERVER_PUBLIC_LOCATION=\ http://{public_fqdn}/geoserver/ >> {override_fn}".format(**envs), pty=True) - if not os.environ.get('SITEURL'): ctx.run("echo export SITEURL=\ http://{public_fqdn}/ >> {override_fn}".format(**envs), pty=True) try: - current_allowed = ast.literal_eval(os.getenv('ALLOWED_HOSTS') or \ - "['{public_fqdn}', '{public_host}', 'localhost', 'django', 'geonode',]".format(**envs)) + current_allowed = ast.literal_eval( + os.getenv('ALLOWED_HOSTS') or "[\ +'{public_fqdn}', '{public_host}', 'localhost', 'django', 'geonode',\ +]".format(**envs)) except ValueError: current_allowed = [] - current_allowed.extend(['{}'.format(pub_ip), '{}:{}'.format(pub_ip, pub_port)]) - allowed_hosts = ['"{}"'.format(c) for c in current_allowed] + ['"geonode"', '"django"'] + current_allowed.extend( + ['{}'.format(pub_ip), '{}:{}'.format(pub_ip, pub_port)] + ) + allowed_hosts = ['"{}"'.format(c) for c in current_allowed] + for host in ['django', 'geonode']: + if host not in allowed_hosts: + allowed_hosts.extend(['{}'.format(host)]) - ctx.run('echo export ALLOWED_HOSTS="\\"{}\\"" >> {}'.format(allowed_hosts, override_env), pty=True) + ctx.run('echo export ALLOWED_HOSTS="\\"{}\\"" >> {}'.format( + allowed_hosts, override_env + ), pty=True) if not os.environ.get('DATABASE_URL'): ctx.run("echo export DATABASE_URL=\