From 5a18e33b4339303b133c0605356e9d74af12a4f0 Mon Sep 17 00:00:00 2001
From: Stefano Alberto Russo <stefano.russo@gmail.com>
Date: Thu, 2 Mar 2023 17:24:10 +0100
Subject: [PATCH] Fixed an issue in connecting over SSL from the agent to the
 webapp API.

---
 docker-compose-dev.yml                         | 5 +++--
 services/webapp/code/rosetta/core_app/utils.py | 6 +++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml
index 406c3c6..403f40f 100644
--- a/docker-compose-dev.yml
+++ b/docker-compose-dev.yml
@@ -69,8 +69,9 @@ services:
       - DJANGO_DEBUG=True
       - DJANGO_LOG_LEVEL=CRITICAL
       - ROSETTA_LOG_LEVEL=DEBUG
-      #- ROSETTA_WEBAPP_HOST=localhost # Internal, for the agent
-      #- ROSETTA_WEBAPP_PORT=8080      # Internal, for the agent
+      #- ROSETTA_WEBAPP_SSL=False      # Used for the agent.
+      #- ROSETTA_WEBAPP_HOST=          # Used for the agent, can be internal. Defaults to webapp IP.
+      #- ROSETTA_WEBAPP_PORT=8080      # Used for the agent, can be internal.
       #- ROSETTA_REGISTRY_HOST=proxy
       #- ROSETTA_REGISTRY_PORT=5000
       #- DJANGO_EMAIL_APIKEY=""
diff --git a/services/webapp/code/rosetta/core_app/utils.py b/services/webapp/code/rosetta/core_app/utils.py
index 51f40d6..bef643e 100644
--- a/services/webapp/code/rosetta/core_app/utils.py
+++ b/services/webapp/code/rosetta/core_app/utils.py
@@ -504,9 +504,13 @@ def get_my_ip():
     return my_ip
 
 def get_webapp_conn_string():
+    webapp_ssl  = booleanize(os.environ.get('ROSETTA_WEBAPP_SSL', False))
     webapp_host = os.environ.get('ROSETTA_WEBAPP_HOST', get_my_ip())
     webapp_port = os.environ.get('ROSETTA_WEBAPP_PORT', '8080')
-    webapp_conn_string = 'http://{}:{}'.format(webapp_host, webapp_port)
+    if webapp_ssl:
+        webapp_conn_string = 'https://{}:{}'.format(webapp_host, webapp_port)
+    else:
+        webapp_conn_string = 'http://{}:{}'.format(webapp_host, webapp_port)
     return webapp_conn_string
 
 def get_platform_registry():
-- 
GitLab