refactor: [ai-config] 모든 API 키를 DB(ai_configs)에서 .env로 전환

- AiConfig::getActiveGemini() → config('services.gemini') 기반
- AiConfig::getActiveGcs() → config('services.google') 기반
- AiConfig::getActiveClaude() → config('services.claude') 기반
- AiConfig::getActiveNotion() → config('services.notion') 기반
- GoogleCloudStorageService: DB 우선 로직 제거, .env만 사용
- 8개 서비스 파일은 수정 없이 동작 (AiConfig 인터페이스 유지)
This commit is contained in:
김보곤
2026-02-23 09:55:07 +09:00
parent 1b73fd1cf2
commit 52b26c7216
3 changed files with 134 additions and 107 deletions

View File

@@ -82,43 +82,84 @@ class AiConfig extends Model
public const API_SERVICE_PROVIDERS = ['notion'];
/**
* 활성화된 Gemini 설정 조회
* 활성화된 Gemini 설정 조회 (.env 기반)
*/
public static function getActiveGemini(): ?self
{
return self::where('provider', 'gemini')
->where('is_active', true)
->first();
$apiKey = config('services.gemini.api_key');
if (! $apiKey) {
return null;
}
$instance = new self;
$instance->provider = 'gemini';
$instance->api_key = $apiKey;
$instance->model = config('services.gemini.model', 'gemini-2.0-flash');
$instance->base_url = config('services.gemini.base_url', 'https://generativelanguage.googleapis.com/v1beta');
$instance->is_active = true;
$instance->options = [
'auth_type' => 'api_key',
'project_id' => config('services.gemini.project_id', 'codebridge-chatbot'),
'region' => config('services.vertex_ai.location', 'us-central1'),
];
return $instance;
}
/**
* 활성화된 Claude 설정 조회
* 활성화된 Claude 설정 조회 (.env 기반)
*/
public static function getActiveClaude(): ?self
{
return self::where('provider', 'claude')
->where('is_active', true)
->first();
$apiKey = config('services.claude.api_key');
if (! $apiKey) {
return null;
}
$instance = new self;
$instance->provider = 'claude';
$instance->api_key = $apiKey;
$instance->model = 'claude-sonnet-4-20250514';
$instance->base_url = 'https://api.anthropic.com/v1';
$instance->is_active = true;
$instance->options = [];
return $instance;
}
/**
* 활성화된 Notion 설정 조회
* 활성화된 Notion 설정 조회 (.env 기반)
*/
public static function getActiveNotion(): ?self
{
return self::where('provider', 'notion')
->where('is_active', true)
->first();
$apiKey = config('services.notion.api_key');
if (! $apiKey) {
return null;
}
$instance = new self;
$instance->provider = 'notion';
$instance->api_key = $apiKey;
$instance->model = config('services.notion.version', '2025-09-03');
$instance->base_url = config('services.notion.base_url', 'https://api.notion.com/v1');
$instance->is_active = true;
$instance->options = [];
return $instance;
}
/**
* Provider별 활성 설정 조회
* Provider별 활성 설정 조회 (.env 기반)
*/
public static function getActive(string $provider): ?self
{
return self::where('provider', $provider)
->where('is_active', true)
->first();
return match ($provider) {
'gemini' => self::getActiveGemini(),
'claude' => self::getActiveClaude(),
'notion' => self::getActiveNotion(),
'gcs' => self::getActiveGcs(),
default => null,
};
}
/**
@@ -145,13 +186,28 @@ public function getProviderLabelAttribute(): string
}
/**
* 활성화된 GCS 설정 조회
* 활성화된 GCS 설정 조회 (.env 기반)
*/
public static function getActiveGcs(): ?self
{
return self::where('provider', 'gcs')
->where('is_active', true)
->first();
$credentialsPath = config('services.google.credentials_path');
$bucket = config('services.google.storage_bucket');
if (! $bucket) {
return null;
}
$instance = new self;
$instance->provider = 'gcs';
$instance->api_key = 'gcs_service_account';
$instance->model = '-';
$instance->base_url = 'https://storage.googleapis.com';
$instance->is_active = true;
$instance->options = [
'bucket_name' => $bucket,
'service_account_path' => $credentialsPath,
];
return $instance;
}
/**