From 355a7422644bc31d431e134210ef7842846091fe Mon Sep 17 00:00:00 2001
From: Stefano Alberto Russo <stefano.russo@gmail.com>
Date: Fri, 28 Aug 2020 13:53:57 +0200
Subject: [PATCH] Minor refactor, cleanup.

---
 README.md                                     | 23 +++++++++++++++----
 docker-compose-dev.yml                        |  4 +++-
 rosetta/logs                                  | 20 ++++++++++++++++
 run_webapp_unit_tests.sh => rosetta/test      |  0
 .../rosetta/core_app/templates/header.html    |  4 ----
 .../webapp/code/rosetta/core_app/views.py     |  5 +---
 services/webapp/code/rosetta/settings.py      |  9 ++++----
 view_webapp_server_log.sh                     |  2 --
 view_webapp_startup_log.sh                    |  2 --
 9 files changed, 47 insertions(+), 22 deletions(-)
 create mode 100755 rosetta/logs
 rename run_webapp_unit_tests.sh => rosetta/test (100%)
 delete mode 100755 view_webapp_server_log.sh
 delete mode 100755 view_webapp_startup_log.sh

diff --git a/README.md b/README.md
index 799bd5d..1cc7a49 100755
--- a/README.md
+++ b/README.md
@@ -6,6 +6,8 @@ _A container-centric Science Platform_
 
 Rosetta makes it easy to run interactive workloads on batch and remote computing systems using Docker and Singularity containers.
 
+Rosetta licensed under the Apache License 2.0, unless otherwise specificed.
+
 
 ## Quickstart
 
@@ -58,14 +60,14 @@ Example Webapp configuraion
 
 ### Extras
 
-Check status (not yet fully supported)
+List all running services
 
-    # rosetta/status
+    # rosetta/ps
 
+Check status (not yet fully supported)
 
-Run Web App unit tests (with Rosetta running)
+    # rosetta/status
 
-    ./run_webapp_unit_tests.sh
 
 
 ### Building errors
@@ -98,6 +100,19 @@ Note that when you edit the Django ORM model, you need to rerun the migrate the
     $ python3 manage.py makemigrations
     $ python3 manage.py migrate
     
+### Logs and testing
+
+Run Web App unit tests (with Rosetta running)
+
+    $ rosetta/logs webapp
+    
+    $ rosetta/logs webapp startup
+    
+    $ rosetta/logs webapp server
+    
+    $rosetta/tets
+
+    
 ## Known issues
 
     SINGULARITY_TMPDIR=/...
diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml
index ea23bbe..6461a7b 100644
--- a/docker-compose-dev.yml
+++ b/docker-compose-dev.yml
@@ -46,6 +46,7 @@ services:
     hostname: webapp
     environment:
       - SAFEMODE=False
+      - DJANGO_DEBUG=True
       - DJANGO_LOG_LEVEL=CRITICAL
       - ROSETTA_LOG_LEVEL=DEBUG
       #- ROSETTA_TUNNEL_HOST=
@@ -56,6 +57,7 @@ services:
       #- DJANGO_EMAIL_APIKEY=""
       #- DJANGO_EMAIL_FROM="Rosetta Platform <notifications@rosetta.platform>"
       #- DJANGO_PUBLIC_HTTP_HOST=http://localhost:8080
+      #- DJANGO_SECRET_KEY=""
     ports:
       - "8080:8080"
       - "7000-7020:7000-7020"
@@ -63,7 +65,7 @@ services:
       - ./data_rosetta/webapp/data:/data
       - ./data_rosetta/webapp/log:/var/log/webapp
       - /var/run/docker.sock:/var/run/docker.sock
-      #- ./services/webapp/code:/opt/webapp_code
+      - ./services/webapp/code:/opt/code
 
   proxy:
     image: "rosetta/proxy"
diff --git a/rosetta/logs b/rosetta/logs
new file mode 100755
index 0000000..41a9ad1
--- /dev/null
+++ b/rosetta/logs
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Check if we are in the right place
+if [ ! -d ./services ]; then
+    echo "You must run this command from the project's root folder."
+    exit 1
+fi
+
+if [[ $# -eq 0 ]] ; then
+    echo "Please tell me which service to get logs from."
+    exit 1
+fi
+
+if [[ "x$2" != "x" ]] ; then
+    tail -f -n 1000 data_rosetta/$1/log/$2.log
+else
+    docker-compose logs -f $1    
+fi
+
+
diff --git a/run_webapp_unit_tests.sh b/rosetta/test
similarity index 100%
rename from run_webapp_unit_tests.sh
rename to rosetta/test
diff --git a/services/webapp/code/rosetta/core_app/templates/header.html b/services/webapp/code/rosetta/core_app/templates/header.html
index 29d46e1..6d82d49 100644
--- a/services/webapp/code/rosetta/core_app/templates/header.html
+++ b/services/webapp/code/rosetta/core_app/templates/header.html
@@ -13,11 +13,7 @@
     <meta http-equiv="refresh" content="{{refresh}}" >
     {% endif %}
 
-    {% if data.title %}
-    <title>{{data.title}}</title>
-    {% else %}
     <title>Rosetta</title>
-    {% endif %}
 
     <!-- Bootstrap Core CSS -->
     <link href="/static/css/bootstrap-3.3.5.min.css" rel="stylesheet">
diff --git a/services/webapp/code/rosetta/core_app/views.py b/services/webapp/code/rosetta/core_app/views.py
index 86b1f04..d069f6b 100644
--- a/services/webapp/code/rosetta/core_app/views.py
+++ b/services/webapp/code/rosetta/core_app/views.py
@@ -30,7 +30,6 @@ _task_cache = {}
 def login_view(request):
 
     data = {}
-    data['title'] = "{} - Login".format(settings.DJANGO_PROJECT_NAME)
 
     # If authenticated user reloads the main URL
     if request.method == 'GET' and request.user.is_authenticated:
@@ -80,7 +79,7 @@ def login_view(request):
                     loginToken.token = token
                     loginToken.save()
                 try:
-                    send_email(to=user.email, subject='{} login link'.format(settings.DJANGO_PROJECT_NAME), text='Hello,\n\nhere is your login link: {}/login/?token={}\n\nOnce logged in, you can go to "My Account" and change password (or just keep using the login link feature).\n\nThe {} Team.'.format(settings.DJANGO_PUBLIC_HTTP_HOST, token, settings.DJANGO_PROJECT_NAME))
+                    send_email(to=user.email, subject='Rosetta login link', text='Hello,\n\nhere is your login link: {}/login/?token={}\n\nOnce logged in, you can go to "My Account" and change password (or just keep using the login link feature).\n\nThe Rosetta Team.'.format(settings.DJANGO_PUBLIC_HTTP_HOST, token))
                 except Exception as e:
                     logger.error(format_exception(e))
                     raise ErrorMessage('Something went wrong. Please retry later.')
@@ -141,7 +140,6 @@ def logout_view(request):
 def register_view(request):
 
     data = {}
-    data['title'] = "{} - Register".format(settings.DJANGO_PROJECT_NAME)
 
     # If authenticated user reloads the main URL
     if request.method == 'GET' and request.user.is_authenticated:
@@ -230,7 +228,6 @@ def account(request):
     except Profile.DoesNotExist:
         profile = Profile.objects.create(user=request.user)
     data['profile'] = profile
-    data['title'] = "{} - Account".format(settings.DJANGO_PROJECT_NAME)
 
     # Set values from POST and GET
     edit = request.POST.get('edit', None)
diff --git a/services/webapp/code/rosetta/settings.py b/services/webapp/code/rosetta/settings.py
index 6dc85d4..df5a3f7 100644
--- a/services/webapp/code/rosetta/settings.py
+++ b/services/webapp/code/rosetta/settings.py
@@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
 
 import os
 from django.core.exceptions import ImproperlyConfigured
-
+from .core_app.utils import booleanize
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -22,16 +22,16 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
 
 # SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = '-3byo^nd6-x82fuj*#68mj=5#qp*gagg58sc($u$r-=g8ujxu4'
+SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', '-3byo^nd6-x82fuj*#68mj=5#qp*gagg58sc($u$r-=g8ujxu4')
 
 # SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = True
+DEBUG = booleanize(os.environ.get('DJANGO_DEBUG', False))
 
+# SECURITY WARNING: check if you want this in production
 ALLOWED_HOSTS = ['*']
 
 
 # Application definition
-
 INSTALLED_APPS = [
     'rosetta.core_app',
     'django.contrib.admin',
@@ -157,7 +157,6 @@ TMP_PATH   = '/tmp/'
 #  Email settings
 #===============================
 
-DJANGO_PROJECT_NAME = os.environ.get('DJANGO_PROJECT_NAME', 'Rosetta')
 DJANGO_PUBLIC_HTTP_HOST = os.environ.get('DJANGO_PUBLIC_HTTP_HOST', 'http://localhost:8080')
 
 DJANGO_EMAIL_SERVICE = os.environ.get('DJANGO_EMAIL_SERVICE', 'Sendgrid')
diff --git a/view_webapp_server_log.sh b/view_webapp_server_log.sh
deleted file mode 100755
index 0572279..0000000
--- a/view_webapp_server_log.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-tail -f -n 1000 data_rosetta/webapp/log/server.log
diff --git a/view_webapp_startup_log.sh b/view_webapp_startup_log.sh
deleted file mode 100755
index 5e57e64..0000000
--- a/view_webapp_startup_log.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-tail -f -n 1000 data_rosetta/webapp/log/startup.log
-- 
GitLab