feat: 配置导出/导入支持 LDAP 和 OAuth Provider

- 新增配置格式 v2.1,支持导出/导入 LDAP 配置和 OAuth Providers
- 导出时解密敏感字段(bind_password, client_secret, provider_ops credentials)
- 导入时加密敏感字段后存储
- 前端支持预览和显示 LDAP/OAuth 导入结果
This commit is contained in:
fawney19
2026-01-28 12:56:37 +08:00
parent 4cd196f665
commit 95fc848e59
3 changed files with 365 additions and 8 deletions

View File

@@ -1,11 +1,46 @@
import apiClient from './client'
// LDAP 配置导出结构
export interface LDAPConfigExport {
server_url: string
bind_dn: string
bind_password?: string
base_dn: string
user_search_filter?: string
username_attr?: string
email_attr?: string
display_name_attr?: string
is_enabled?: boolean
is_exclusive?: boolean
use_starttls?: boolean
connect_timeout?: number
}
// OAuth Provider 导出结构
export interface OAuthProviderExport {
provider_type: string
display_name: string
client_id: string
client_secret?: string
authorization_url_override?: string | null
token_url_override?: string | null
userinfo_url_override?: string | null
scopes?: string[] | null
redirect_uri: string
frontend_callback_url: string
attribute_mapping?: any
extra_config?: any
is_enabled?: boolean
}
// 配置导出数据结构
export interface ConfigExportData {
version: string
exported_at: string
global_models: GlobalModelExport[]
providers: ProviderExport[]
ldap_config?: LDAPConfigExport | null
oauth_providers?: OAuthProviderExport[]
}
// 用户导出数据结构
@@ -254,6 +289,8 @@ export interface ConfigImportResponse {
endpoints: { created: number; updated: number; skipped: number }
keys: { created: number; updated: number; skipped: number }
models: { created: number; updated: number; skipped: number }
ldap?: { created: number; updated: number; skipped: number }
oauth?: { created: number; updated: number; skipped: number }
errors: string[]
}
}

View File

@@ -538,6 +538,10 @@
<li>
API Keys: {{ importPreview.providers?.reduce((sum: number, p: any) => sum + (p.api_keys?.length || 0), 0) }}
</li>
<li v-if="importPreview.ldap_config">LDAP 配置: 1 </li>
<li v-if="importPreview.oauth_providers?.length">
OAuth Providers: {{ importPreview.oauth_providers.length }}
</li>
</ul>
</div>
@@ -655,6 +659,26 @@
跳过: {{ importResult.stats.models.skipped }}
</p>
</div>
<div v-if="importResult.stats.ldap">
<p class="font-medium">
LDAP 配置
</p>
<p class="text-muted-foreground">
创建: {{ importResult.stats.ldap.created }},
更新: {{ importResult.stats.ldap.updated }},
跳过: {{ importResult.stats.ldap.skipped }}
</p>
</div>
<div v-if="importResult.stats.oauth">
<p class="font-medium">
OAuth Providers
</p>
<p class="text-muted-foreground">
创建: {{ importResult.stats.oauth.created }},
更新: {{ importResult.stats.oauth.updated }},
跳过: {{ importResult.stats.oauth.skipped }}
</p>
</div>
</div>
<div
@@ -1293,8 +1317,8 @@ function handleConfigFileSelect(event: Event) {
const content = e.target?.result as string
const data = JSON.parse(content) as ConfigExportData
// 验证版本
if (data.version !== '2.0') {
// 验证版本(支持 2.0 和 2.1
if (!['2.0', '2.1'].includes(data.version)) {
error(`不支持的配置版本: ${data.version}`)
return
}