From 1de1105b377c06ef180179e8f760cbe47d8cfa1a Mon Sep 17 00:00:00 2001
From: Stefano Alberto Russo <stefano.russo@gmail.com>
Date: Mon, 11 Jan 2021 23:12:43 +0100
Subject: [PATCH] Added the "protocol" property for the containers, defaulted
 to "http".

---
 .../migrations/0002_container_protocol.py      | 18 ++++++++++++++++++
 .../webapp/code/rosetta/core_app/models.py     |  1 +
 .../core_app/templates/add_container.html      | 10 ++++++++++
 .../templates/components/container.html        |  5 +++++
 services/webapp/code/rosetta/core_app/views.py |  8 +++++---
 5 files changed, 39 insertions(+), 3 deletions(-)
 create mode 100644 services/webapp/code/rosetta/core_app/migrations/0002_container_protocol.py

diff --git a/services/webapp/code/rosetta/core_app/migrations/0002_container_protocol.py b/services/webapp/code/rosetta/core_app/migrations/0002_container_protocol.py
new file mode 100644
index 0000000..2b74fb8
--- /dev/null
+++ b/services/webapp/code/rosetta/core_app/migrations/0002_container_protocol.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2.1 on 2021-01-11 20:44
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core_app', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='container',
+            name='protocol',
+            field=models.CharField(blank=True, default='http', max_length=36, null=True, verbose_name='Container protocol'),
+        ),
+    ]
diff --git a/services/webapp/code/rosetta/core_app/models.py b/services/webapp/code/rosetta/core_app/models.py
index 13fc4fd..cb19c07 100644
--- a/services/webapp/code/rosetta/core_app/models.py
+++ b/services/webapp/code/rosetta/core_app/models.py
@@ -82,6 +82,7 @@ class Container(models.Model):
     type     = models.CharField('Container type', max_length=36, blank=False, null=False)
     registry = models.CharField('Container registry', max_length=255, blank=False, null=False)
     ports    = models.CharField('Container ports', max_length=36, blank=True, null=True)
+    protocol = models.CharField('Container protocol', max_length=36, blank=True, null=True, default='http')
 
     # Capabilities
     supports_dynamic_ports = models.BooleanField(default=False)
diff --git a/services/webapp/code/rosetta/core_app/templates/add_container.html b/services/webapp/code/rosetta/core_app/templates/add_container.html
index 0c85201..0e342f0 100644
--- a/services/webapp/code/rosetta/core_app/templates/add_container.html
+++ b/services/webapp/code/rosetta/core_app/templates/add_container.html
@@ -54,6 +54,16 @@
             </td>
            </tr>
 
+           <tr>
+            <td><b>Protocol</b></td>
+            <td>
+             <select name="container_protocol" id="cars">
+              <option value="http" selected>http</option>
+              <option value="https">https</option>
+             </select>
+            </td>
+           </tr>
+   
            <tr>
             <td colspan=2><b>Default port(s)</b>
              &nbsp; &nbsp;<input type="text" name="container_ports" value="" placeholder="" size="5" />
diff --git a/services/webapp/code/rosetta/core_app/templates/components/container.html b/services/webapp/code/rosetta/core_app/templates/components/container.html
index 1fc5ddd..60da1b0 100644
--- a/services/webapp/code/rosetta/core_app/templates/components/container.html
+++ b/services/webapp/code/rosetta/core_app/templates/components/container.html
@@ -44,6 +44,11 @@
         <td>{{ container.registry }}</td>
        </tr>
 
+       <tr>
+        <td><b>Protocol</b></td>
+        <td>{{ container.protocol }}</td>
+       </tr>
+
        <tr>
         <td colspan=2><b>Default port(s)</b>
         &nbsp; &nbsp;{{ container.ports }}</td>
diff --git a/services/webapp/code/rosetta/core_app/views.py b/services/webapp/code/rosetta/core_app/views.py
index d069f6b..313754c 100644
--- a/services/webapp/code/rosetta/core_app/views.py
+++ b/services/webapp/code/rosetta/core_app/views.py
@@ -363,7 +363,7 @@ def tasks(request):
 
                 # Then, redirect to the task through the tunnel
                 tunnel_host = get_tunnel_host()
-                return redirect('http://{}:{}'.format(tunnel_host,task.tunnel_port))
+                return redirect('{}://{}:{}'.format(task.container.protocol, tunnel_host, task.tunnel_port))
 
         except Exception as e:
             data['error'] = 'Error in getting the task or performing the required action'
@@ -700,6 +700,9 @@ def add_container(request):
         # Container name
         container_name = request.POST.get('container_name', None)
 
+        # Container protocol 
+        container_protocol = request.POST.get('container_protocol')
+
         # Container service ports. TODO: support multiple ports? 
         container_ports = request.POST.get('container_ports', None)
         
@@ -709,8 +712,6 @@ def add_container(request):
                     int(container_service_port)
             except:
                 raise ErrorMessage('Invalid container port(s) in "{}"'.format(container_ports))
-
-
         # Capabilities
         container_supports_dynamic_ports = request.POST.get('container_supports_dynamic_ports', None)
         if container_supports_dynamic_ports and container_supports_dynamic_ports == 'True':
@@ -739,6 +740,7 @@ def add_container(request):
                                  name     = container_name,
                                  type     = container_type,
                                  registry = container_registry,
+                                 protocol = container_protocol,
                                  ports    = container_ports,
                                  supports_dynamic_ports = container_supports_dynamic_ports,
                                  supports_user_auth     = container_supports_user_auth,
-- 
GitLab