전역 구조 리팩터링 및 테스트 확장

This commit is contained in:
JiWoong Sul
2025-09-29 01:51:47 +09:00
parent c00c0c9ab2
commit fef7108479
70 changed files with 7709 additions and 3185 deletions

View File

@@ -18,12 +18,17 @@ class Environment {
/// 프로덕션 여부
static late final bool isProduction;
static final Map<String, Set<String>> _permissions = {};
/// 환경 초기화
///
/// - 기본 환경은 development이며, `ENV` dart-define 으로 변경 가능
/// - 해당 환경의 .env 파일을 로드하고 핵심 값을 추출한다.
static Future<void> initialize() async {
const envFromDefine = String.fromEnvironment('ENV', defaultValue: 'development');
const envFromDefine = String.fromEnvironment(
'ENV',
defaultValue: 'development',
);
envName = envFromDefine.toLowerCase();
isProduction = envName == 'production';
@@ -46,6 +51,7 @@ class Environment {
}
baseUrl = dotenv.maybeGet('API_BASE_URL') ?? 'http://localhost:8080';
_loadPermissions();
}
/// 기능 플래그 조회 (기본 false)
@@ -67,4 +73,32 @@ class Environment {
return defaultValue;
}
}
static void _loadPermissions() {
_permissions.clear();
for (final entry in dotenv.env.entries) {
const prefix = 'PERMISSION__';
if (!entry.key.startsWith(prefix)) {
continue;
}
final resource = entry.key.substring(prefix.length).toLowerCase();
final values = entry.value
.split(',')
.map((token) => token.trim().toLowerCase())
.where((token) => token.isNotEmpty)
.toSet();
_permissions[resource] = values;
}
}
static bool hasPermission(String resource, String action) {
final actions = _permissions[resource.toLowerCase()];
if (actions == null || actions.isEmpty) {
return true;
}
if (actions.contains('all')) {
return true;
}
return actions.contains(action.toLowerCase());
}
}