공개 제보 — 파일 스토리지에서 S3 를 선택해 저장해도 실제 파일 저장이 동작하지 않던 결함의 전면 수정. - S3 어댑터(league/flysystem-aws-s3-v3)·predis 를 코어 기본 의존성으로 포함 — 어댑터 부재 즉사, phpredis 확장 없는 서버의 redis 선택 전면 다운 차단 (부트 시 확장 부재 감지 → predis 자동 폴백) - storage_driver=s3 저장 시 코어 첨부 업로드 디스크를 s3 로 전환 (ATTACHMENT_DISK env 명시가 항상 우선, 기존 행은 저장 당시 disk 로 서빙) - 첨부·템플릿 레이아웃 첨부 서빙을 행 disk 를 따르는 스토리지 스트림으로 교체 — 로컬 절대 경로 전제 fileResponse 는 S3 행에서 filemtime stat 500 (streamedFileResponse: 행 메타 기반 ETag/304/Cache-Control) - S3 호환 스토리지(R2/MinIO/NCP) 연결 지원: 엔드포인트 URL·path-style 설정 신설, 리전 목록 선택 → 자유 입력 전환, 연결 테스트를 실제 저장 경로와 동일 설정(endpoint/path-style)으로 정렬 - 사용 불능 드라이버(어댑터·PHP 확장 부재)의 저장/테스트 요청을 사유와 함께 422 로 차단하는 서버 게이트 신설 (DriverRegistryService 능력 판정) - 웹소켓 연결 테스트에 서버(백엔드 발송용) endpoint 검사 추가 — 클라이언트만 검사해 테스트 성공 + 실제 발송 실패가 가능하던 비대칭 해소 - env 빈 값(`KEY=`) 함정 정규화: AWS_URL/AWS_ENDPOINT/ATTACHMENT_DISK 빈 문자열을 미설정으로 취급 (config 정규화 + 예시 파일 주석 처리) - 플러그인 드라이버 폴백의 log 카테고리 죽은 키(logging.default) 정정 및 websocket 유령 설정 키 제거 - 실 AWS S3 종단 검증 완료 (설정 저장 → 업로드 S3 실저장 → 서빙 200/304)
183 lines
8.4 KiB
PHP
183 lines
8.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Settings;
|
|
|
|
use App\Extension\HookManager;
|
|
use App\Services\DriverRegistryService;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
/**
|
|
* 드라이버 연결 테스트 요청 검증
|
|
*
|
|
* S3, Redis, Memcached, Websocket 드라이버 연결 테스트에 필요한
|
|
* 설정값을 검증합니다.
|
|
*/
|
|
class TestDriverConnectionRequest extends FormRequest
|
|
{
|
|
/**
|
|
* 지원되는 스토리지 드라이버 목록
|
|
*/
|
|
private const SUPPORTED_STORAGE_DRIVERS = ['local', 's3'];
|
|
|
|
/**
|
|
* S3 리전 형식 (AWS 리전 코드 + S3 호환 스토리지 임의값 허용 — R2 의 `auto` 등)
|
|
*/
|
|
private const S3_REGION_FORMAT = 'regex:/^[a-z0-9-]+$/';
|
|
|
|
/**
|
|
* 지원되는 캐시 드라이버 목록
|
|
*/
|
|
private const SUPPORTED_CACHE_DRIVERS = ['file', 'redis', 'memcached'];
|
|
|
|
/**
|
|
* 지원되는 세션 드라이버 목록
|
|
*/
|
|
private const SUPPORTED_SESSION_DRIVERS = ['file', 'database', 'redis'];
|
|
|
|
/**
|
|
* 지원되는 큐 드라이버 목록
|
|
*/
|
|
private const SUPPORTED_QUEUE_DRIVERS = ['sync', 'database', 'redis'];
|
|
|
|
/**
|
|
* 지원되는 웹소켓 프로토콜 목록
|
|
*/
|
|
private const SUPPORTED_WEBSOCKET_SCHEMES = ['http', 'https'];
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
// 드라이버 선택
|
|
'storage_driver' => ['nullable', Rule::in(self::SUPPORTED_STORAGE_DRIVERS), $this->getDriverUsabilityRule('storage')],
|
|
'cache_driver' => ['nullable', Rule::in(self::SUPPORTED_CACHE_DRIVERS), $this->getDriverUsabilityRule('cache')],
|
|
'session_driver' => ['nullable', Rule::in(self::SUPPORTED_SESSION_DRIVERS), $this->getDriverUsabilityRule('session')],
|
|
'queue_driver' => ['nullable', Rule::in(self::SUPPORTED_QUEUE_DRIVERS), $this->getDriverUsabilityRule('queue')],
|
|
'websocket_enabled' => ['nullable', 'boolean'],
|
|
|
|
// S3 설정
|
|
's3_bucket' => ['nullable', 'string', 'max:255'],
|
|
's3_region' => ['nullable', 'string', 'max:64', self::S3_REGION_FORMAT],
|
|
's3_access_key' => ['nullable', 'string', 'max:255'],
|
|
's3_secret_key' => ['nullable', 'string', 'max:255'],
|
|
's3_url' => ['nullable', 'url', 'max:500'],
|
|
's3_endpoint' => ['nullable', 'url', 'max:500'],
|
|
's3_use_path_style' => ['nullable', 'boolean'],
|
|
|
|
// Redis 설정
|
|
'redis_host' => ['nullable', 'string', 'max:255'],
|
|
'redis_port' => ['nullable', 'integer', 'min:1', 'max:65535'],
|
|
'redis_password' => ['nullable', 'string', 'max:255'],
|
|
'redis_database' => ['nullable', 'integer', 'min:0', 'max:15'],
|
|
|
|
// Memcached 설정
|
|
'memcached_host' => ['nullable', 'string', 'max:255'],
|
|
'memcached_port' => ['nullable', 'integer', 'min:1', 'max:65535'],
|
|
|
|
// Websocket 설정 — client(브라우저 접속) / server(백엔드 broadcast HTTP API) endpoint 분리
|
|
'websocket_app_key' => ['nullable', 'string', 'max:255'],
|
|
'websocket_host' => ['nullable', 'string', 'max:255'],
|
|
'websocket_port' => ['nullable', 'integer', 'min:1', 'max:65535'],
|
|
'websocket_scheme' => ['nullable', Rule::in(self::SUPPORTED_WEBSOCKET_SCHEMES)],
|
|
'websocket_server_host' => ['nullable', 'string', 'max:255'],
|
|
'websocket_server_port' => ['nullable', 'integer', 'min:1', 'max:65535'],
|
|
'websocket_server_scheme' => ['nullable', Rule::in(self::SUPPORTED_WEBSOCKET_SCHEMES)],
|
|
];
|
|
|
|
// 모듈/플러그인이 validation rules를 동적으로 추가할 수 있도록 훅 제공
|
|
return HookManager::applyFilters('core.settings.test_driver_connection_validation_rules', $rules, $this);
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'storage_driver.in' => __('validation.settings.storage_driver_invalid'),
|
|
's3_bucket.max' => __('validation.settings.s3_bucket_max'),
|
|
's3_region.regex' => __('validation.settings.s3_region_invalid'),
|
|
's3_region.max' => __('validation.settings.s3_region_max'),
|
|
's3_access_key.max' => __('validation.settings.s3_access_key_max'),
|
|
's3_secret_key.max' => __('validation.settings.s3_secret_key_max'),
|
|
's3_url.url' => __('validation.settings.s3_url_invalid'),
|
|
's3_url.max' => __('validation.settings.s3_url_max'),
|
|
's3_endpoint.url' => __('validation.settings.s3_endpoint_invalid'),
|
|
's3_endpoint.max' => __('validation.settings.s3_endpoint_max'),
|
|
's3_use_path_style.boolean' => __('validation.settings.s3_use_path_style_boolean'),
|
|
'cache_driver.in' => __('validation.settings.cache_driver_invalid'),
|
|
'redis_host.max' => __('validation.settings.redis_host_max'),
|
|
'redis_port.integer' => __('validation.settings.redis_port_integer'),
|
|
'redis_port.min' => __('validation.settings.redis_port_min'),
|
|
'redis_port.max' => __('validation.settings.redis_port_max'),
|
|
'redis_password.max' => __('validation.settings.redis_password_max'),
|
|
'redis_database.integer' => __('validation.settings.redis_database_integer'),
|
|
'redis_database.min' => __('validation.settings.redis_database_min'),
|
|
'redis_database.max' => __('validation.settings.redis_database_max'),
|
|
'memcached_host.max' => __('validation.settings.memcached_host_max'),
|
|
'memcached_port.integer' => __('validation.settings.memcached_port_integer'),
|
|
'memcached_port.min' => __('validation.settings.memcached_port_min'),
|
|
'memcached_port.max' => __('validation.settings.memcached_port_max'),
|
|
'session_driver.in' => __('validation.settings.session_driver_invalid'),
|
|
'queue_driver.in' => __('validation.settings.queue_driver_invalid'),
|
|
'websocket_enabled.boolean' => __('validation.settings.websocket_enabled_boolean'),
|
|
'websocket_app_key.max' => __('validation.settings.websocket_app_key_max'),
|
|
'websocket_host.max' => __('validation.settings.websocket_host_max'),
|
|
'websocket_port.integer' => __('validation.settings.websocket_port_integer'),
|
|
'websocket_port.min' => __('validation.settings.websocket_port_min'),
|
|
'websocket_port.max' => __('validation.settings.websocket_port_max'),
|
|
'websocket_scheme.in' => __('validation.settings.websocket_scheme_invalid'),
|
|
'websocket_server_host.max' => __('validation.settings.websocket_server_host_max'),
|
|
'websocket_server_port.integer' => __('validation.settings.websocket_server_port_integer'),
|
|
'websocket_server_port.min' => __('validation.settings.websocket_server_port_min'),
|
|
'websocket_server_port.max' => __('validation.settings.websocket_server_port_max'),
|
|
'websocket_server_scheme.in' => __('validation.settings.websocket_server_scheme_invalid'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 드라이버 가용성 검증 rule 을 반환합니다.
|
|
*
|
|
* 저장 게이트(SaveSettingsRequest)와 동일 판정 — 사용 불능 드라이버는 테스트 요청
|
|
* 단계에서도 422 로 차단해 어느 경로로도 통과하지 못하게 합니다.
|
|
*
|
|
* @param string $category 드라이버 카테고리 (storage, cache, session, queue)
|
|
* @return \Closure 검증 클로저
|
|
*/
|
|
private function getDriverUsabilityRule(string $category): \Closure
|
|
{
|
|
return function ($attribute, $value, $fail) use ($category) {
|
|
if (empty($value)) {
|
|
return;
|
|
}
|
|
|
|
$registry = app(DriverRegistryService::class);
|
|
|
|
if (! $registry->isDriverUsable($category, $value)) {
|
|
$fail(__('validation.settings.driver_unusable', [
|
|
'driver' => $value,
|
|
'reason' => $registry->usabilityFailureReason($category, $value),
|
|
]));
|
|
}
|
|
};
|
|
}
|
|
}
|