From 9c756ddd9a5636ff08af4fd578e00709b1baf1b6 Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Fri, 13 Mar 2020 09:24:44 -0500
Subject: [PATCH] Added a variable file to be used by flask and celery

- Added vars file to be used by run.py and tasks.py
- Fixed type Key to key
- Added username and password as variables
- Removed print statemt
- Fix variable mismatch
---
 run.py   | 11 ++++++-----
 tasks.py |  5 +++--
 vars.py  |  5 +++++
 3 files changed, 14 insertions(+), 7 deletions(-)
 create mode 100644 vars.py

diff --git a/run.py b/run.py
index 5b864f9..85381ff 100644
--- a/run.py
+++ b/run.py
@@ -4,6 +4,7 @@ import os
 import time
 import signal
 import tasks
+import vars
 
 from flask import session
 from flask_socketio import SocketIO, join_room
@@ -15,8 +16,8 @@ monkey.patch_all(subprocess=True)
 
 config_name = os.getenv('FLASK_CONFIG')
 app = create_app(config_name)
-app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#'
-socketio = SocketIO(app, message_queue='amqp://reggie:reggie@ohpc:5672/socketio')
+app.config['SECRET_KEY'] = vars.key
+socketio = SocketIO(app, message_queue= vars.message_queue)
 
 
 @socketio.on('join_room')
@@ -30,10 +31,10 @@ def on_room():
 @socketio.on('request account')
 def request_account(json, methods=['GET', 'POST']):
     print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json))
-    sid = str(session['uid'])
-    print("Room: {}".format(sid))
+    room = str(session['uid'])
+    print("Room: {}".format(room))
     try:
-        tasks.celery_create_account.delay(json['username'], json['fullname'], json['reason'], session=sid)
+        tasks.celery_create_account.delay(json['username'], json['fullname'], json['reason'], session=room)
     except Exception as e:
         print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e)
         socketio.emit("Account creation failed", room)
diff --git a/tasks.py b/tasks.py
index f596d1d..e380c9c 100644
--- a/tasks.py
+++ b/tasks.py
@@ -2,14 +2,15 @@ from celery import Celery
 import time
 from flask_socketio import SocketIO
 import subprocess
+import vars
 
 from gevent import monkey
 monkey.patch_all(subprocess=True)
 
-broker_url = 'amqp://reggie:reggie@ohpc:5672/'
+broker_url = vars.broker_url
 celery = Celery('flask_user_reg', broker=broker_url)
 
-socketio = SocketIO(message_queue='amqp://reggie:reggie@ohpc:5672/socketio')
+socketio = SocketIO(message_queue=vars.message_queue)
 
 def send_msg(event, room):
    print("Post '{}' to room '{}'".format(event,room))
diff --git a/vars.py b/vars.py
new file mode 100644
index 0000000..6d94b57
--- /dev/null
+++ b/vars.py
@@ -0,0 +1,5 @@
+id = 'reggie'
+password = 'reggie' 
+key = 'vnkdjnfjknfl1232'
+broker_url =  'amqp://' + id + ':' + password + '@ohpc:5672/'
+message_queue =  broker_url + 'socketio'
-- 
GitLab