Commit 103f9d43 authored by Ismail Moumni's avatar Ismail Moumni
Browse files

editing

parent 268f39cc
Pipeline #677 failed with stage
in 15 seconds
softwares/server/__pycache__/__init__.cpython-36.pyc
softwares/server/__pycache__/server.cpython-36.pyc
softwares/server/.vscode/settings.json
softwares/database/__init__.py
softwares/database/.vscode/settings.json
tests/test_server.py
......@@ -2,22 +2,24 @@ import mysql.connector
from get_docker_secret import get_docker_secret
import os
# Exception thrown when no password has been defined to connect to the database
class NoPasswordDefineError(Exception):
"""No secret containing a password has been found"""
pass
__rdos_password__ = None
__rdos_password__ = "rdos2013"
# Procedures that returns an externally defined password to conect to the database
# First tries to check the docker secrets, then an environment variable.
# Throws NoPasswordDefineError if no password is found
# Returns a password
# Returns a password
def get_password():
if __rdos_password__ == None:
if __rdos_password__ is None:
password = get_docker_secret('rdos_secret')
if password == None:
if password is None:
if 'rdos_secret' in os.environ:
password = os.environ['rdos_secret']
print("Password stored in a non secured way, please make your code safer")
......@@ -26,18 +28,19 @@ def get_password():
return password
return __rdos_password__
# Connect to the local MYSQL database on lipn-rdos
def database_connection():
mydb = mysql.connector.connect(
host="192.168.90.101",
user="rdos",
password = get_password(),
password=get_password(),
database="rdos"
)
return mydb
def update_database(url:str, job_id: str, before:str, after:str):
def update_database(url: str, job_id: str, before: str, after: str):
database = database_connection()
mycursor = database.cursor(buffered=False)
......@@ -59,9 +62,7 @@ def get_job(database):
sql_get_new_job = "SELECT jobs.id,parametersJSON,directory,email,tool,jobs.idGenerator,outputFormat,command from jobs inner join generators on jobs.idGenerator=generators.id where status='10'"
mycursor = database.cursor(buffered=True)
mycursor.execute(sql_get_new_job)
myresult = mycursor.fetchone()
mycursor.close()
return myresult
......@@ -70,13 +71,13 @@ def get_job(database):
# Returns 1 if no other deamon selected the job first, 0 otherwwise.
def apply_for_job(database, job_id: str):
mycursor = database.cursor(buffered=False)
update = "UPDATE jobs set status='100' where jobs.id='"+job_id+"' and status='10'"
update = "UPDATE jobs set status='100' where jobs.id='"+job_id+"' and status='10'"
mycursor.execute(update)
database.commit()
return mycursor.rowcount
# Returns a dictionnary containing each generator's parameters as a key. The value associated to each key is "is this parameter's value written in the comand line or in a separated file
# Returns a dictionnary containing each generator's parameters as a key. The value associated to each key is "is this parameter's value written in the command line or in a separated file
# in which case the value is the filename.
def getParameters(generators: dict):
database = database_connection()
......@@ -87,13 +88,15 @@ def getParameters(generators: dict):
parameters_default[generator] = {}
sql_get_new_job = "SELECT name,basefile,defaultValue from parameters inner join generators on parameters.idGenerator=generators.id where generators.tool = '"+generator+"'"
mycursor = database.cursor(buffered=False)
mycursor.execute(sql_get_new_job)
mycursor.execute(sql_get_new_job)
myresult = mycursor.fetchall()
mycursor.close()
for result in myresult:
parameters_basefile[generator][result[0]] = result[1]
parameters_default[generator][result[0]] = result[1]
database.disconnect()
return (parameters_basefile, parameters_default)
if __name__ == "__main__":
db = getParameters("Regal")
......@@ -24,12 +24,10 @@ class RdosServer:
serv.bind((address, PORT))
# Listening to 5 CLients
serv.listen(5)
print("ok")
# accepting the connection from client and getting client IP
conn, addr = serv.accept()
print("connexion accepted")
with conn:
print('Connexion acceptée depuis l IP : ', addr)
print('Connexion acceptee depuis l IP : ', addr)
# Receiving Data from Client
data = conn.recv(4096)
query = (json.loads(data.decode('utf-8')))
......@@ -39,6 +37,7 @@ class RdosServer:
dt_js = json.dumps(send_param_client(__RDOS_Dict__, Tool))
print(dt_js)
conn.send(bytes((dt_js), "utf-8"))
conn.close()
# Function query_valid matches the query send from client side
......@@ -47,7 +46,7 @@ class RdosServer:
# Function output boolean true if match else False
def query_valid(data: dict):
if 'parameters' in data:
if (data['parameters'] == 'request') & (len(data) < 2):
if (data['parameters'] == 'request') & (len(data) <= 2):
return True
return False
......@@ -73,15 +72,15 @@ def json_to_dict(js):
return data
def db_req(tool: str):
tool_dict = db.getParameters(tool)
return tool_dict
# def db_req(tool: str):
# tool_dict = db.getParameters(tool)
# return tool_dict
def verif_param(data: dict):
# Tuple
# s = db.getParameters(data['tool'])
s = ({"id": "", "name": ""}, {})
s = ({"id": "", "name": ""}, {"id": "15"})
if s is not None:
try:
gen = s[0]
......@@ -117,6 +116,7 @@ def match_generator_dict(biblio: dict, Genereator: list):
if __name__ == '__main__':
data = {
"sacha": "PokeBall",
"internet": "internet",
"glossary": {
"title": "example glossary",
......@@ -142,3 +142,4 @@ if __name__ == '__main__':
data1 = {"ll": "s", "ismail": "ss"}
print(match_query_dict(data, data))
print(verif_param({"name": ""}))
RdosServer.server_conn('127.0.0.1', 9393)
#!/usr/bin/env python3
import socket
import os
import sys
import unittest
sys.path.append(os.path.realpath('../softwares/'))
import server as ser
def Test_server():
ser.server_conn()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment