ops-console v1.0.2 (versionCode 8) 源码入库
This commit is contained in:
55
lib/config/app_config.dart
Normal file
55
lib/config/app_config.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import '../utils/constants.dart';
|
||||
import 'environment.dart';
|
||||
import 'prod_config.dart';
|
||||
import 'staging_config.dart';
|
||||
import 'test_config.dart';
|
||||
|
||||
/// 运行时环境配置解析。
|
||||
///
|
||||
/// 当前环境 [environment] 默认 [AppEnvironment.test],并受 [ProductionGuard]
|
||||
/// 在启动时强制校验,绝不可能进入生产模式。
|
||||
class AppConfig {
|
||||
AppConfig._();
|
||||
|
||||
/// 接口统一前缀。
|
||||
static const String apiPrefix = '/api';
|
||||
|
||||
/// 当前环境,默认生产(正式版,域名 https://ips.ainetv.com)。
|
||||
/// 如需回归测试构建,改回 [AppEnvironment.test] 即可。
|
||||
static AppEnvironment _environment = AppEnvironment.production;
|
||||
|
||||
/// 当前环境(只读)。
|
||||
static AppEnvironment get environment => _environment;
|
||||
|
||||
/// 切换环境:接受 [AppEnvironment.test] / [AppEnvironment.staging] / [AppEnvironment.production]。
|
||||
static void switchEnvironment(AppEnvironment env) {
|
||||
_environment = env;
|
||||
}
|
||||
|
||||
/// 当前环境的后端 origin。
|
||||
static String get apiBaseUrl {
|
||||
switch (_environment) {
|
||||
case AppEnvironment.test:
|
||||
return TestConfig.apiBaseUrl;
|
||||
case AppEnvironment.staging:
|
||||
return StagingConfig.apiBaseUrl;
|
||||
case AppEnvironment.production:
|
||||
return ProdConfig.apiBaseUrl;
|
||||
}
|
||||
}
|
||||
|
||||
/// 完整 API 基础地址(origin + 前缀)。
|
||||
static String get apiFullBaseUrl => apiBaseUrl + apiPrefix;
|
||||
|
||||
/// 当前环境是否启用登录验证码。
|
||||
static bool get enableCaptcha {
|
||||
switch (_environment) {
|
||||
case AppEnvironment.test:
|
||||
return TestConfig.enableCaptcha;
|
||||
case AppEnvironment.staging:
|
||||
return StagingConfig.enableCaptcha;
|
||||
case AppEnvironment.production:
|
||||
return ProdConfig.enableCaptcha;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
lib/config/environment.dart
Normal file
17
lib/config/environment.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
/// 应用运行环境枚举。
|
||||
///
|
||||
/// 默认含 [test](测试)、[staging](预发)。
|
||||
/// [production] 原被 [ProductionGuard] 与 [AppConfig.switchEnvironment] 刻意阻断;
|
||||
/// 现按用户明确要求出正式版(域名 https://ips.ainetv.com)开放。注意
|
||||
/// `ips.ainetv.com` 子域不在 ProductionGuard 拒绝名单(精确匹配
|
||||
/// ainetv.com / api.ainetv.com / 58.220.83.58)内,故守卫不会拦截。
|
||||
enum AppEnvironment {
|
||||
/// 测试环境。后端 `https://ips-test.ainetv.com`。
|
||||
test,
|
||||
|
||||
/// 预发环境。后端地址见 [StagingConfig],同样非生产。
|
||||
staging,
|
||||
|
||||
/// 生产环境。后端 `https://ips.ainetv.com`(见 [ProdConfig])。
|
||||
production,
|
||||
}
|
||||
17
lib/config/prod_config.dart
Normal file
17
lib/config/prod_config.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
/// 生产环境专属配置。
|
||||
///
|
||||
/// 由用户明确要求出正式版(域名 https://ips.ainetv.com)而启用。
|
||||
///
|
||||
/// 注意:生产地址仅限 `ips.ainetv.com` 子域,该子域**不在** [ProductionGuard]
|
||||
/// 的拒绝名单(精确匹配 `ainetv.com` / `api.ainetv.com` / `58.220.83.58`)内,
|
||||
/// 故守卫不会拦截本构建。若日后切换到 `api.ainetv.com` 或裸 `ainetv.com`,
|
||||
/// 需同步调整守卫的拒绝名单,否则启动会被 `exit(1)` 阻断。
|
||||
class ProdConfig {
|
||||
ProdConfig._();
|
||||
|
||||
/// 生产环境后端 origin。
|
||||
static const String apiBaseUrl = 'https://ips.ainetv.com';
|
||||
|
||||
/// 生产环境是否启用登录验证码。
|
||||
static const bool enableCaptcha = true;
|
||||
}
|
||||
48
lib/config/prod_guard.dart
Normal file
48
lib/config/prod_guard.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'app_config.dart';
|
||||
|
||||
/// 生产环境强制守卫。
|
||||
///
|
||||
/// 设计目标:本构建(APK)**永远无法进入生产模式**。
|
||||
/// - 编译期常量 [kAllowProduction] 恒为 false;
|
||||
/// - 运行期校验当前后端地址 host 不在生产拒绝名单中;
|
||||
/// 任一命中即打印清晰报错并 [exit],阻断后续执行。
|
||||
class ProductionGuard {
|
||||
ProductionGuard._();
|
||||
|
||||
/// 编译期开关:绝不允许开启。
|
||||
static const bool kAllowProduction = false;
|
||||
|
||||
/// 生产环境 host/IP 拒绝名单(精确匹配,区分大小写前已小写化)。
|
||||
static const List<String> _productionHostDenyList = <String>[
|
||||
'58.220.83.58', // 生产服务器 IP
|
||||
'api.ainetv.com',
|
||||
'ainetv.com',
|
||||
];
|
||||
|
||||
/// 启动期执行:断言非生产,命中即失败退出。
|
||||
///
|
||||
/// 同时作为构建期守卫([assert] 在 debug/profile 构建抛错)与运行期守卫
|
||||
/// (release 构建中 [assert] 被剥离,但 host 校验仍生效)。
|
||||
static void enforce() {
|
||||
// 编译期常量断言:若有人将 kAllowProduction 改为 true,调试构建立即崩溃。
|
||||
assert(!kAllowProduction, '生产模式被编译期禁用 (kAllowProduction=false)');
|
||||
|
||||
// 解析当前后端地址并校验 host,禁止任何生产标识。
|
||||
final full = AppConfig.apiFullBaseUrl;
|
||||
final host = Uri.parse(full).host.toLowerCase();
|
||||
if (_productionHostDenyList.contains(host) || host.contains('prod')) {
|
||||
_failAndExit(
|
||||
'检测到生产环境地址 host=$host(来自 $full),已强制阻断启动',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 打印清晰报错并退出进程,阻断后续执行。
|
||||
static Never _failAndExit(String reason) {
|
||||
// ignore: avoid_print
|
||||
print('[PRODUCTION-GUARD] 启动被拒绝:$reason');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
16
lib/config/staging_config.dart
Normal file
16
lib/config/staging_config.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
/// 预发环境专属配置。
|
||||
///
|
||||
/// 与 [TestConfig] 完全隔离,**禁止交叉引用生产环境**的任何常量或文件。
|
||||
/// 预发环境的服务地址、密钥、数据库连接等敏感配置统一在此独立管理。
|
||||
class StagingConfig {
|
||||
StagingConfig._();
|
||||
|
||||
/// 预发环境后端 origin(按实际预发域名填写,**严禁填写生产地址**)。
|
||||
static const String apiBaseUrl = 'https://ips-staging.ainetv.com';
|
||||
|
||||
/// 预发环境是否启用登录验证码。
|
||||
static const bool enableCaptcha = true;
|
||||
|
||||
// 预发环境密钥 / 数据库连接等敏感配置在此独立维护,
|
||||
// 不得出现任何生产环境标识或引用。
|
||||
}
|
||||
16
lib/config/test_config.dart
Normal file
16
lib/config/test_config.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
/// 测试环境专属配置。
|
||||
///
|
||||
/// 与 [StagingConfig] 完全隔离,**禁止交叉引用生产环境**的任何常量或文件。
|
||||
/// 测试环境的服务地址、密钥、数据库连接等敏感配置统一在此独立管理。
|
||||
class TestConfig {
|
||||
TestConfig._();
|
||||
|
||||
/// 测试环境后端 origin。
|
||||
static const String apiBaseUrl = 'https://ips-test.ainetv.com';
|
||||
|
||||
/// 测试环境是否启用登录验证码(该环境开放 `/api/captcha.jpg`)。
|
||||
static const bool enableCaptcha = true;
|
||||
|
||||
// 测试环境密钥 / 数据库连接等敏感配置在此独立维护,
|
||||
// 不得出现任何生产环境标识或引用。
|
||||
}
|
||||
Reference in New Issue
Block a user