feat(api-explorer): Phase 1 기본 구조 및 OpenAPI 파싱 구현
- Config: api-explorer.php (환경, 보안, 캐시 설정) - Migration: api_bookmarks, api_templates, api_histories, api_environments - Model: ApiBookmark, ApiTemplate, ApiHistory, ApiEnvironment - Service: OpenApiParserService, ApiRequestService, ApiExplorerService - Controller: ApiExplorerController (CRUD, 실행, 히스토리) - View: 3-Panel 레이아웃 (sidebar, request, response, history) - Route: 23개 엔드포인트 등록 Swagger UI 대체 개발 도구, HTMX 기반 SPA 경험
This commit is contained in:
128
app/Models/DevTools/ApiEnvironment.php
Normal file
128
app/Models/DevTools/ApiEnvironment.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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 $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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user