diff --git a/docker/.env-sample b/docker/.env-sample index 5574e0d..fc2330c 100644 --- a/docker/.env-sample +++ b/docker/.env-sample @@ -13,4 +13,8 @@ MYSQL_ROOT_PASSWORD=root # define the name of the root account (when not using Docker) MYSQL_ROOT_LOGIN=root # define mysql tcp port (default is 3306) -MYSQL_TCP_PORT=3306 \ No newline at end of file +MYSQL_TCP_PORT=3306 +# define login for superadmin user +MYSQL_PYROS_LOGIN=pyros +# define password for superadmin user +MYSQL_PYROS_PWD=DjangoPyros \ No newline at end of file diff --git a/pyros.py b/pyros.py index 3e9fb99..75c620e 100755 --- a/pyros.py +++ b/pyros.py @@ -133,8 +133,8 @@ SQL_DATABASE = "pyros" SQL_DATABASE_TEST = "test_pyros" # Specific database that we need(ed?) for some simulations SQL_DATABASE_SIMU = "pyros_test" -SQL_USER = "pyros" -SQL_PSWD = "DjangoPyros" +SQL_USER = "" +SQL_PSWD = "" MYSQL_EXE_PATH = "" ENV_PATH = "docker/.env" @@ -298,14 +298,14 @@ def set_environment_variables_if_not_configured(env_path: str,env_sample_path: s env_path (str): path to .env file env_sample_path (str): path to .env-sample file """ - is_environment_variables_not_defined = os.environ.get("MYSQL_ROOT_PASSWORD") == None or os.environ.get("MYSQL_ROOT_LOGIN") == None + is_environment_variables_not_defined = os.environ.get("MYSQL_ROOT_PASSWORD") == None or os.environ.get("MYSQL_ROOT_LOGIN") == None or os.environ.get("MYSQL_PYROS_LOGIN") == None or os.environ.get("MYSQL_PYROS_PWD") == None if(is_environment_variables_not_defined): print("Some environment variables are not configured...") try: with open(env_path,"r") as env_file: print("Reading env file") for line in env_file: - if(line.startswith("#") and not env_sample_line.strip()): + if(line.startswith("#") and not line.strip()): continue else: key,value = line.split("=") @@ -439,6 +439,8 @@ def install(packages_only, database_only): install_or_update(UPDATE=False, packages_only=packages_only, database_only=database_only) def install_or_update(UPDATE:bool=False, packages_only:bool=False, database_only:bool=False): + SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() + SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() ACTION = "UPDATING" if UPDATE else "INSTALLING" if WITH_DOCKER: database_only = True @@ -1012,6 +1014,8 @@ def install_packages(): def install_database(venv): + SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() + SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() print(Colors.LOG_BLUE + END_OF_LINE+"-----------------------------Launching mysql to create database and create and grant user pyros-----------------------------" + Colors.END) # -------------------------------------------- diff --git a/src/core/pyros_django/pyros/settings.py b/src/core/pyros_django/pyros/settings.py index dfaf087..abdb178 100644 --- a/src/core/pyros_django/pyros/settings.py +++ b/src/core/pyros_django/pyros/settings.py @@ -113,6 +113,8 @@ ENV_PATH="../../../../docker/.env" ENV_SAMPLE_PATH="../../../../docker/.env-sample" # default value of mysql port MYSQL_PORT = "3306" +SQL_USER = "" +SQL_PSWD = "" ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'pyros.irap.omp.eu'] # defining variables when using Docker if WITH_DOCKER: @@ -120,6 +122,8 @@ if WITH_DOCKER: else: try: MYSQL_PORT = os.environ['MYSQL_TCP_PORT'] + SQL_USER = os.environ.get("MYSQL_PYROS_LOGIN").strip() + SQL_PSWD = os.environ.get("MYSQL_PYROS_PWD").strip() except: set_environment_variables_if_not_configured(ENV_PATH,ENV_SAMPLE_PATH) -- libgit2 0.21.2