feat:GCS 환경변수(.env) 기반 설정 지원
- config/gcs.php 추가: 환경변수 기반 설정 - GoogleCloudStorageService 우선순위 변경: 1. DB 설정 (UI 오버라이드용) 2. 환경변수 (.env) - 기본 3. 레거시 파일 (fallback) - .env.example에 GCS 설정 추가 - 서버 배포 시 .env만 설정하면 DB 설정 불필요 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -81,3 +81,8 @@ FCM_LOG_CHANNEL=stack
|
||||
BAROBILL_CERT_KEY=
|
||||
BAROBILL_CORP_NUM=
|
||||
BAROBILL_TEST_MODE=true
|
||||
|
||||
# Google Cloud Storage (음성 녹음 백업)
|
||||
GCS_BUCKET_NAME=
|
||||
GCS_SERVICE_ACCOUNT_PATH=/var/www/sales/apikey/google_service_account.json
|
||||
GCS_USE_DB_CONFIG=true
|
||||
|
||||
@@ -8,13 +8,18 @@
|
||||
/**
|
||||
* Google Cloud Storage 업로드 서비스
|
||||
*
|
||||
* DB 설정(ai_configs 테이블)을 우선 사용하고, 없으면 레거시 파일 설정을 사용합니다.
|
||||
* 우선순위:
|
||||
* 1. DB 설정 (ui에서 오버라이드)
|
||||
* 2. 환경변수 (.env)
|
||||
* 3. 레거시 파일 (/sales/apikey/)
|
||||
*
|
||||
* JWT 인증 방식 사용.
|
||||
*/
|
||||
class GoogleCloudStorageService
|
||||
{
|
||||
private ?string $bucketName = null;
|
||||
private ?array $serviceAccount = null;
|
||||
private string $configSource = 'none';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -26,11 +31,13 @@ public function __construct()
|
||||
*
|
||||
* 우선순위:
|
||||
* 1. DB 설정 (ai_configs 테이블의 활성화된 gcs provider)
|
||||
* 2. 레거시 파일 설정 (/sales/apikey/)
|
||||
* 2. 환경변수 (.env의 GCS_BUCKET_NAME, GCS_SERVICE_ACCOUNT_PATH)
|
||||
* 3. 레거시 파일 설정 (/sales/apikey/)
|
||||
*/
|
||||
private function loadConfig(): void
|
||||
{
|
||||
// 1. DB 설정 확인
|
||||
// 1. DB 설정 확인 (GCS_USE_DB_CONFIG=true일 때만)
|
||||
if (config('gcs.use_db_config', true)) {
|
||||
$dbConfig = AiConfig::getActiveGcs();
|
||||
|
||||
if ($dbConfig) {
|
||||
@@ -43,13 +50,30 @@ private function loadConfig(): void
|
||||
$this->serviceAccount = json_decode(file_get_contents($dbConfig->getServiceAccountPath()), true);
|
||||
}
|
||||
|
||||
if ($this->serviceAccount) {
|
||||
if ($this->bucketName && $this->serviceAccount) {
|
||||
$this->configSource = 'db';
|
||||
Log::debug('GCS 설정 로드: DB (활성화된 설정: ' . $dbConfig->name . ')');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 레거시 파일 설정 (fallback)
|
||||
// 2. 환경변수 (.env) 설정
|
||||
$envBucket = config('gcs.bucket_name');
|
||||
$envServiceAccountPath = config('gcs.service_account_path');
|
||||
|
||||
if ($envBucket && $envServiceAccountPath && file_exists($envServiceAccountPath)) {
|
||||
$this->bucketName = $envBucket;
|
||||
$this->serviceAccount = json_decode(file_get_contents($envServiceAccountPath), true);
|
||||
|
||||
if ($this->serviceAccount) {
|
||||
$this->configSource = 'env';
|
||||
Log::debug('GCS 설정 로드: 환경변수 (.env)');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 레거시 파일 설정 (fallback)
|
||||
$gcsConfigPath = base_path('../sales/apikey/gcs_config.txt');
|
||||
if (file_exists($gcsConfigPath)) {
|
||||
$config = parse_ini_file($gcsConfigPath);
|
||||
@@ -62,10 +86,19 @@ private function loadConfig(): void
|
||||
}
|
||||
|
||||
if ($this->bucketName && $this->serviceAccount) {
|
||||
$this->configSource = 'legacy';
|
||||
Log::debug('GCS 설정 로드: 레거시 파일');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 설정 소스 반환
|
||||
*/
|
||||
public function getConfigSource(): string
|
||||
{
|
||||
return $this->configSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* GCS가 사용 가능한지 확인
|
||||
*/
|
||||
|
||||
21
config/gcs.php
Normal file
21
config/gcs.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Google Cloud Storage 설정
|
||||
*
|
||||
* 우선순위:
|
||||
* 1. DB 설정 (ai_configs 테이블) - UI에서 오버라이드 가능
|
||||
* 2. 환경변수 (.env)
|
||||
* 3. 레거시 파일 (/sales/apikey/)
|
||||
*/
|
||||
|
||||
return [
|
||||
// 버킷 이름
|
||||
'bucket_name' => env('GCS_BUCKET_NAME'),
|
||||
|
||||
// 서비스 계정 파일 경로
|
||||
'service_account_path' => env('GCS_SERVICE_ACCOUNT_PATH', '/var/www/sales/apikey/google_service_account.json'),
|
||||
|
||||
// DB 설정 사용 여부 (false면 .env만 사용)
|
||||
'use_db_config' => env('GCS_USE_DB_CONFIG', true),
|
||||
];
|
||||
Reference in New Issue
Block a user