Files
sam-manage/app/Models/DevTools/ApiEnvironment.php
김보곤 48aa4505f5 feat: [database] codebridge DB 분리 재적용 - 55개 MNG 전용 모델만 설정
- API 사용 테이블 22개(23개 모델) 제외하고 55개 모델만 $connection = 'codebridge' 적용
- config/database.php에 codebridge connection 재추가
- 제외 대상: Barobill 12개, ESign 4개, Audit 2개, DevTools 1개, System 2개, HR 1개
2026-03-09 20:02:38 +09:00

132 lines
3.1 KiB
PHP

<?php
namespace App\Models\DevTools;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Crypt;
/**
* API 환경 설정 모델
*
* @property int $id
* @property int $user_id
* @property string $name
* @property string $base_url
* @property string|null $api_key
* @property string|null $auth_token
* @property array|null $variables
* @property bool $is_default
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*/
class ApiEnvironment extends Model
{
protected $connection = 'codebridge';
protected $table = 'admin_api_environments';
protected $fillable = [
'user_id',
'name',
'base_url',
'api_key',
'auth_token',
'variables',
'is_default',
];
protected $casts = [
'variables' => 'array',
'is_default' => 'boolean',
];
/**
* 민감 정보 숨김
*/
protected $hidden = [
'api_key',
'auth_token',
];
/**
* 사용자 관계
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* API Key 암호화 저장
*/
public function setApiKeyAttribute(?string $value): void
{
if ($value && config('api-explorer.security.encrypt_tokens', true)) {
$this->attributes['api_key'] = Crypt::encryptString($value);
} else {
$this->attributes['api_key'] = $value;
}
}
/**
* API Key 복호화 조회
*/
public function getDecryptedApiKeyAttribute(): ?string
{
if (! $this->attributes['api_key']) {
return null;
}
if (config('api-explorer.security.encrypt_tokens', true)) {
try {
return Crypt::decryptString($this->attributes['api_key']);
} catch (\Exception $e) {
return $this->attributes['api_key'];
}
}
return $this->attributes['api_key'];
}
/**
* Auth Token 암호화 저장
*/
public function setAuthTokenAttribute(?string $value): void
{
if ($value && config('api-explorer.security.encrypt_tokens', true)) {
$this->attributes['auth_token'] = Crypt::encryptString($value);
} else {
$this->attributes['auth_token'] = $value;
}
}
/**
* Auth Token 복호화 조회
*/
public function getDecryptedAuthTokenAttribute(): ?string
{
if (! $this->attributes['auth_token']) {
return null;
}
if (config('api-explorer.security.encrypt_tokens', true)) {
try {
return Crypt::decryptString($this->attributes['auth_token']);
} catch (\Exception $e) {
return $this->attributes['auth_token'];
}
}
return $this->attributes['auth_token'];
}
/**
* 기본 환경 스코프
*/
public function scopeDefault($query)
{
return $query->where('is_default', true);
}
}