mirror of
https://git.isptech.ru/ISPsystem/isp-maintenance.git
synced 2025-09-13 18:43:09 +02:00
Add: settings values, json parser from file (function), demo example
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
from settings.environment import BASE_DIR
|
||||
|
||||
from settings.platform import (
|
||||
PLATFORM_TYPE,
|
||||
PLATFORM_URL,
|
||||
PLATFORM_CONFIG
|
||||
)
|
||||
|
||||
from settings.db import(
|
||||
DB_ENGINE,
|
||||
DB_HOST,
|
||||
DB_PORT,
|
||||
DB_USER,
|
||||
DB_PASSWORD
|
||||
)
|
||||
|
20
isp_maintenance/settings/db.py
Normal file
20
isp_maintenance/settings/db.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from settings.environment import env
|
||||
from settings.platform import PLATFORM_CONFIG
|
||||
|
||||
|
||||
#! Required because some instance use psql db:
|
||||
DB_ENGINE = env.str(
|
||||
'DB_ENGINE',
|
||||
PLATFORM_CONFIG.get('DatabaseType', 'mysql')
|
||||
)
|
||||
|
||||
# Connection parameters:
|
||||
DB_HOST = env.str('DB_HOST', 'mysql')
|
||||
DB_PORT = env.int('DB_PORT', 3306)
|
||||
DB_USER = env.str('DB_USER', 'root')
|
||||
|
||||
#! Do not pass password on production. Use value from config.json
|
||||
DB_PASSWORD = env.str(
|
||||
'DB_PASSWORD',
|
||||
PLATFORM_CONFIG.get('MysqlRootPassword', '')
|
||||
)
|
14
isp_maintenance/settings/environment.py
Normal file
14
isp_maintenance/settings/environment.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import pathlib
|
||||
from environs import Env
|
||||
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = pathlib.Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Init environment:
|
||||
env = Env()
|
||||
|
||||
# read .env file, if it exists
|
||||
# reed more about .env file here: https://github.com/sloria/environs
|
||||
env.read_env()
|
12
isp_maintenance/settings/platform.py
Normal file
12
isp_maintenance/settings/platform.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from settings.environment import env, BASE_DIR
|
||||
from utils.helpers import parse_json_file
|
||||
|
||||
|
||||
PLATFORM_TYPE = env.str('PLATFORM_TYPE', 'vm')
|
||||
|
||||
PLATFORM_CONFIG = parse_json_file(f'{BASE_DIR}/config.json')
|
||||
|
||||
PLATFORM_URL = env.url(
|
||||
'PLATFORM_URL',
|
||||
f"https://{PLATFORM_CONFIG.get('DomainName' ,'replace.me')}"
|
||||
)
|
Reference in New Issue
Block a user