Backend (Django 4.2 + DRF): - Admin auth with SimpleJWT - Volcengine API client with HMAC-SHA256 signing - IAM user management (create/sync/import/disable/enable) - Billing query with pagination - Feishu webhook notifications (async) - APScheduler for periodic spending checks - AES-256 encrypted credential storage - API key auth for external system integration Frontend (Vue 3 + Element Plus): - Login page - Dashboard with stats overview - IAM user list with per-user threshold config - Billing view with spending progress bars - Alert history with type filtering - Settings page for global config and Volcengine account management Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
148 lines
4.2 KiB
Python
148 lines
4.2 KiB
Python
import os
|
|
from pathlib import Path
|
|
from datetime import timedelta
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
# --- Core ---
|
|
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'dev-insecure-key-change-in-production')
|
|
DEBUG = os.environ.get('DJANGO_DEBUG', 'True').lower() in ('true', '1', 'yes')
|
|
ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', 'localhost,127.0.0.1,0.0.0.0').split(',')
|
|
|
|
# --- Apps ---
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
# Third party
|
|
'rest_framework',
|
|
'corsheaders',
|
|
# Local apps
|
|
'apps.accounts',
|
|
'apps.monitor',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'corsheaders.middleware.CorsMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'config.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.debug',
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'config.wsgi.application'
|
|
|
|
# --- Database ---
|
|
if os.environ.get('USE_MYSQL', 'false').lower() in ('true', '1', 'yes'):
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
'NAME': os.environ.get('DB_NAME', 'airgate'),
|
|
'USER': os.environ.get('DB_USER', 'airgate'),
|
|
'PASSWORD': os.environ.get('DB_PASSWORD', ''),
|
|
'HOST': os.environ.get('DB_HOST', 'localhost'),
|
|
'PORT': os.environ.get('DB_PORT', '3306'),
|
|
'OPTIONS': {
|
|
'charset': 'utf8mb4',
|
|
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
|
|
},
|
|
}
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': BASE_DIR / 'db.sqlite3',
|
|
}
|
|
}
|
|
|
|
# --- Auth ---
|
|
AUTH_USER_MODEL = 'accounts.AdminUser'
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
|
|
]
|
|
|
|
# --- JWT ---
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
|
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
|
],
|
|
'DEFAULT_PERMISSION_CLASSES': [
|
|
'rest_framework.permissions.IsAuthenticated',
|
|
],
|
|
'DEFAULT_THROTTLE_CLASSES': [
|
|
'rest_framework.throttling.AnonRateThrottle',
|
|
'rest_framework.throttling.UserRateThrottle',
|
|
],
|
|
'DEFAULT_THROTTLE_RATES': {
|
|
'anon': '30/minute',
|
|
'user': '120/minute',
|
|
},
|
|
}
|
|
|
|
SIMPLE_JWT = {
|
|
'ACCESS_TOKEN_LIFETIME': timedelta(hours=2),
|
|
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
|
|
'AUTH_HEADER_TYPES': ('Bearer',),
|
|
}
|
|
|
|
# --- CORS ---
|
|
CORS_ALLOWED_ORIGINS = os.environ.get(
|
|
'CORS_ALLOWED_ORIGINS',
|
|
'http://localhost:5173,http://localhost:3000,http://127.0.0.1:5173'
|
|
).split(',')
|
|
CORS_ALLOW_CREDENTIALS = True
|
|
|
|
# --- i18n ---
|
|
LANGUAGE_CODE = 'zh-hans'
|
|
TIME_ZONE = 'Asia/Shanghai'
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
# --- Static ---
|
|
STATIC_URL = 'static/'
|
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
# --- Volcengine ---
|
|
VOLC_ACCESS_KEY = os.environ.get('VOLC_ACCESS_KEY', '')
|
|
VOLC_SECRET_KEY = os.environ.get('VOLC_SECRET_KEY', '')
|
|
|
|
# --- Encryption ---
|
|
AIRGATE_ENCRYPTION_KEY = os.environ.get('AIRGATE_ENCRYPTION_KEY', '')
|
|
|
|
# --- Feishu ---
|
|
FEISHU_WEBHOOK_URL = os.environ.get('FEISHU_WEBHOOK_URL', '')
|
|
|
|
# --- API Key (for external systems like AirDrama) ---
|
|
AIRGATE_API_KEY = os.environ.get('AIRGATE_API_KEY', '')
|
|
|
|
# --- Monitor ---
|
|
MONITOR_INTERVAL = int(os.environ.get('MONITOR_INTERVAL', '3600'))
|