sysom1/sysom_server/sysom_vmcore/conf/common.py

159 lines
4.5 KiB
Python

"""
Django settings for sysom_vmcore project.
Generated by 'django-admin startproject' using Django 3.2.8.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
from sysom_utils import ConfigParser, SysomFramework
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
##################################################################
# Load yaml config first
##################################################################
YAML_GLOBAL_CONFIG_PATH = f"{BASE_DIR.parent.parent}/conf/config.yml"
YAML_SERVICE_CONFIG_PATH = f"{BASE_DIR}/config.yml"
YAML_CONFIG = ConfigParser(YAML_GLOBAL_CONFIG_PATH, YAML_SERVICE_CONFIG_PATH)
SysomFramework.init(YAML_CONFIG)
##################################################################
# Cec settings
##################################################################
# channl_job SDK 需要的url
CHANNEL_JOB_URL = YAML_CONFIG.get_local_channel_job_url()
##########################################################################################
# Django Config
##########################################################################################
SECRET_KEY = YAML_CONFIG.get_server_config().jwt.get("SECRET_KEY", "")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'apps.vmcore',
'rest_framework',
'corsheaders',
'django.contrib.staticfiles',
'drf_yasg', # 在线API文档
'django_filters',
]
MIDDLEWARE = [
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
]
ROOT_URLCONF = 'sysom_vmcore.urls'
WSGI_APPLICATION = 'sysom_vmcore.wsgi.application'
ASGI_APPLICATION = 'sysom_diagnosis.asgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': YAML_CONFIG.get_server_config().db.mysql.database,
'USER': YAML_CONFIG.get_server_config().db.mysql.user,
'PASSWORD': YAML_CONFIG.get_server_config().db.mysql.password,
'HOST': YAML_CONFIG.get_server_config().db.mysql.host,
'PORT': YAML_CONFIG.get_server_config().db.mysql.port,
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = YAML_CONFIG.get_global_config().timezone
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
VMCORE_SERVICE_INTERFACE_PREFIX = 'api/v1/vmcore/'
WEB_DIR = YAML_CONFIG.get_web_config().path.root_path
DOWNLOAD_DIR = os.path.join(WEB_DIR, 'download')
#########################################################################################
# rest_framework settings
#########################################################################################
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
# 'rest_framework.permissions.IsAuthenticated'
),
'DEFAULT_AUTHENTICATION_CLASSES': [
# 'apps.accounts.authentication.Authentication'
],
'UNAUTHENTICATED_USER': None,
'DEFAULT_VERSIONING_CLASS': "rest_framework.versioning.URLPathVersioning",
'DEFAULT_VERSION': 'v1', # 默认版本
'ALLOWED_VERSIONS': ['v1', 'v2'], # 允许的版本
'VERSION_PARAM': 'version',
# 'DEFAULT_RENDERER_CLASSES': (
# 'lib.renderers.SysomJsonRender',
# ),
'DEFAULT_PAGINATION_CLASS': 'lib.paginations.Pagination',
'UNICODE_JSON': True,
'EXCEPTION_HANDLER': 'lib.exception.exception_handler'
}