From 79fed45c92ae595b3fde09aaea825204391381a7 Mon Sep 17 00:00:00 2001
From: Stefano Alberto Russo <stefano.russo@gmail.com>
Date: Fri, 1 May 2020 18:36:51 +0200
Subject: [PATCH] Parametrised the tunnel host.

---
 docker-compose.yml                             | 1 +
 services/webapp/code/rosetta/base_app/utils.py | 4 +++-
 services/webapp/code/rosetta/base_app/views.py | 4 +++-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index f69b79f..f41012e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -45,6 +45,7 @@ services:
       - SAFEMODE=False
       - DJANGO_LOG_LEVEL=CRITICAL
       - ROSETTA_LOG_LEVEL=DEBUG
+      #- ROSETTA_TUNNEL_HOST=
       #- ROSETTA_WEBAPP_HOST=
       #- ROSETTA_WEBAPP_PORT=8080
       #- LOCAL_DOCKER_REGISTRY_HOST=
diff --git a/services/webapp/code/rosetta/base_app/utils.py b/services/webapp/code/rosetta/base_app/utils.py
index fa369d6..5d675e3 100644
--- a/services/webapp/code/rosetta/base_app/utils.py
+++ b/services/webapp/code/rosetta/base_app/utils.py
@@ -452,7 +452,9 @@ def get_local_docker_registry_conn_string():
     local_docker_registry_conn_string = '{}:{}'.format(local_docker_registry_host, local_docker_registry_port)
     return local_docker_registry_conn_string
     
-
+def get_tunnel_host():
+    tunnel_host = os.environ.get('ROSETTA_TUNNEL_HOST', 'localhost')
+    return tunnel_host
 
 
 
diff --git a/services/webapp/code/rosetta/base_app/views.py b/services/webapp/code/rosetta/base_app/views.py
index dd6eeab..8b322b8 100644
--- a/services/webapp/code/rosetta/base_app/views.py
+++ b/services/webapp/code/rosetta/base_app/views.py
@@ -339,7 +339,9 @@ def tasks(request):
                     subprocess.Popen(background_tunnel_command, shell=True)
 
                 # Ok, now redirect to the task through the tunnel
-                return redirect('http://localhost:{}'.format(task.tunnel_port))
+                from utils import get_tunnel_host
+                tunnel_host = get_tunnel_host()
+                return redirect('http://{}:{}'.format(tunnel_host,task.tunnel_port))
 
         except Exception as e:
             data['error'] = 'Error in getting the task or performing the required action'
-- 
GitLab