fix: 修复/api/v1/tenants/kv/storage-engine-config接口不返回华为云obs配置导致创建知识库弹窗存储引擎华为云OBS未正确显示不可用标识
fix: 修复租户default_provider为空时降级至local,而local未被允许时导致创建知识库报错: Storage provider is not allowed by STORAGE_ALLOW_LIST
This commit is contained in:
committed by
lyingbug
parent
e3b7ad98c2
commit
b3bb60f03c
@@ -34,6 +34,7 @@ type ParserEngine struct {
|
|||||||
// StorageEngineStatusItem describes one storage engine's availability
|
// StorageEngineStatusItem describes one storage engine's availability
|
||||||
type StorageEngineStatusItem struct {
|
type StorageEngineStatusItem struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Allowed bool `json:"allowed"`
|
||||||
Available bool `json:"available"`
|
Available bool `json:"available"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
@@ -41,6 +42,7 @@ type StorageEngineStatusItem struct {
|
|||||||
// StorageEngineStatusResponse is the response for storage engine status
|
// StorageEngineStatusResponse is the response for storage engine status
|
||||||
type StorageEngineStatusResponse struct {
|
type StorageEngineStatusResponse struct {
|
||||||
Engines []StorageEngineStatusItem `json:"engines"`
|
Engines []StorageEngineStatusItem `json:"engines"`
|
||||||
|
AllowedProviders []string `json:"allowed_providers"`
|
||||||
MinioEnvAvailable bool `json:"minio_env_available"`
|
MinioEnvAvailable bool `json:"minio_env_available"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1019,14 +1019,35 @@ const handleAddWikiModel = () => {
|
|||||||
|
|
||||||
const handleStorageProviderUpdate = (value: string) => {
|
const handleStorageProviderUpdate = (value: string) => {
|
||||||
if (formData.value) {
|
if (formData.value) {
|
||||||
formData.value.storageProvider = value || tenantDefaultStorageProvider.value || 'local'
|
formData.value.storageProvider = props.mode === 'create'
|
||||||
|
? pickUsableStorageProvider(value || tenantDefaultStorageProvider.value)
|
||||||
|
: (value || tenantDefaultStorageProvider.value || 'local')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pickUsableStorageProvider(candidate?: string): string {
|
||||||
|
const provider = candidate?.trim() || ''
|
||||||
|
const engines = editorResources.storageStatus || []
|
||||||
|
const allowedProviders = editorResources.storageAllowedProviders || []
|
||||||
|
const isUsable = (name: string) => {
|
||||||
|
if (!name) return false
|
||||||
|
const status = engines.find((item) => item.name === name)
|
||||||
|
if (status) return status.allowed !== false && status.available !== false
|
||||||
|
if (engines.length > 0) return false
|
||||||
|
if (allowedProviders.length > 0) return allowedProviders.includes(name)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isUsable(provider)) return provider
|
||||||
|
const fallback = engines.find((item) => item.allowed !== false && item.available !== false)?.name
|
||||||
|
if (fallback) return fallback
|
||||||
|
return allowedProviders[0] || provider || 'local'
|
||||||
|
}
|
||||||
|
|
||||||
async function loadTenantDefaultStorageProvider(force = false) {
|
async function loadTenantDefaultStorageProvider(force = false) {
|
||||||
try {
|
try {
|
||||||
await editorResources.ensureStorageEngine(force)
|
await editorResources.ensureStorageEngine(force)
|
||||||
tenantDefaultStorageProvider.value = editorResources.storageConfig?.default_provider || 'local'
|
tenantDefaultStorageProvider.value = pickUsableStorageProvider(editorResources.storageConfig?.default_provider)
|
||||||
} catch {
|
} catch {
|
||||||
tenantDefaultStorageProvider.value = 'local'
|
tenantDefaultStorageProvider.value = 'local'
|
||||||
}
|
}
|
||||||
@@ -1035,6 +1056,9 @@ async function loadTenantDefaultStorageProvider(force = false) {
|
|||||||
/** Resolved storage provider for create payload (never silently default to local before tenant config loads). */
|
/** Resolved storage provider for create payload (never silently default to local before tenant config loads). */
|
||||||
function resolvedStorageProvider(): string {
|
function resolvedStorageProvider(): string {
|
||||||
const explicit = formData.value?.storageProvider?.trim()
|
const explicit = formData.value?.storageProvider?.trim()
|
||||||
|
if (props.mode === 'create') {
|
||||||
|
return pickUsableStorageProvider(explicit || tenantDefaultStorageProvider.value)
|
||||||
|
}
|
||||||
if (explicit) return explicit
|
if (explicit) return explicit
|
||||||
return tenantDefaultStorageProvider.value || 'local'
|
return tenantDefaultStorageProvider.value || 'local'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,76 +79,78 @@ const allowedProviders = ref<string[]>([])
|
|||||||
const hasAnyConfig = ref(false)
|
const hasAnyConfig = ref(false)
|
||||||
|
|
||||||
const engineOptions = computed(() => {
|
const engineOptions = computed(() => {
|
||||||
const statusMap: Record<string, boolean> = {}
|
const statusByName = new Map(engineStatus.value.map((engine) => [engine.name, engine]))
|
||||||
const allowedMap: Record<string, boolean> = {}
|
const allowedSet = new Set(allowedProviders.value)
|
||||||
for (const e of engineStatus.value) {
|
const hasStatus = engineStatus.value.length > 0
|
||||||
statusMap[e.name] = e.available
|
const hasAllowedList = allowedProviders.value.length > 0
|
||||||
allowedMap[e.name] = e.allowed !== false
|
const resolveState = (name: string, fallbackAvailable = false) => {
|
||||||
|
const status = statusByName.get(name)
|
||||||
|
const allowed = status?.allowed ?? (hasAllowedList ? allowedSet.has(name) : !hasStatus)
|
||||||
|
const available = status?.available ?? fallbackAvailable
|
||||||
|
return {
|
||||||
|
allowed,
|
||||||
|
available,
|
||||||
|
disabled: !allowed || !available,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const local = resolveState('local', true)
|
||||||
|
const minio = resolveState('minio')
|
||||||
|
const cos = resolveState('cos')
|
||||||
|
const tos = resolveState('tos')
|
||||||
|
const s3 = resolveState('s3')
|
||||||
|
const oss = resolveState('oss')
|
||||||
|
const ks3 = resolveState('ks3')
|
||||||
|
const obs = resolveState('obs')
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
value: 'local',
|
value: 'local',
|
||||||
label: t('kbSettings.storage.engineLocal'),
|
label: t('kbSettings.storage.engineLocal'),
|
||||||
desc: t('kbSettings.storage.engineLocalDesc'),
|
desc: t('kbSettings.storage.engineLocalDesc'),
|
||||||
allowed: allowedMap.local !== false,
|
...local,
|
||||||
available: statusMap.local !== false,
|
|
||||||
disabled: allowedMap.local === false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'minio',
|
value: 'minio',
|
||||||
label: 'MinIO',
|
label: 'MinIO',
|
||||||
desc: t('kbSettings.storage.engineMinioDesc'),
|
desc: t('kbSettings.storage.engineMinioDesc'),
|
||||||
allowed: allowedMap.minio !== false,
|
...minio,
|
||||||
available: statusMap.minio,
|
|
||||||
disabled: allowedMap.minio === false || statusMap.minio === false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'cos',
|
value: 'cos',
|
||||||
label: t('kbSettings.storage.engineCos'),
|
label: t('kbSettings.storage.engineCos'),
|
||||||
desc: t('kbSettings.storage.engineCosDesc'),
|
desc: t('kbSettings.storage.engineCosDesc'),
|
||||||
allowed: allowedMap.cos !== false,
|
...cos,
|
||||||
available: statusMap.cos,
|
|
||||||
disabled: allowedMap.cos === false || statusMap.cos === false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'tos',
|
value: 'tos',
|
||||||
label: t('kbSettings.storage.engineTos'),
|
label: t('kbSettings.storage.engineTos'),
|
||||||
desc: t('kbSettings.storage.engineTosDesc'),
|
desc: t('kbSettings.storage.engineTosDesc'),
|
||||||
allowed: allowedMap.tos !== false,
|
...tos,
|
||||||
available: statusMap.tos,
|
|
||||||
disabled: allowedMap.tos === false || statusMap.tos === false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 's3',
|
value: 's3',
|
||||||
label: t('kbSettings.storage.engineS3'),
|
label: t('kbSettings.storage.engineS3'),
|
||||||
desc: t('kbSettings.storage.engineS3Desc'),
|
desc: t('kbSettings.storage.engineS3Desc'),
|
||||||
allowed: allowedMap.s3 !== false,
|
...s3,
|
||||||
available: statusMap.s3,
|
|
||||||
disabled: allowedMap.s3 === false || statusMap.s3 === false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'oss',
|
value: 'oss',
|
||||||
label: t('kbSettings.storage.engineOss'),
|
label: t('kbSettings.storage.engineOss'),
|
||||||
desc: t('kbSettings.storage.engineOssDesc'),
|
desc: t('kbSettings.storage.engineOssDesc'),
|
||||||
allowed: allowedMap.oss !== false,
|
...oss,
|
||||||
available: statusMap.oss,
|
|
||||||
disabled: allowedMap.oss === false || statusMap.oss === false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'ks3',
|
value: 'ks3',
|
||||||
label: t('kbSettings.storage.engineKs3'),
|
label: t('kbSettings.storage.engineKs3'),
|
||||||
desc: t('kbSettings.storage.engineKs3Desc'),
|
desc: t('kbSettings.storage.engineKs3Desc'),
|
||||||
allowed: allowedMap.ks3 !== false,
|
...ks3,
|
||||||
available: statusMap.ks3,
|
|
||||||
disabled: allowedMap.ks3 === false || statusMap.ks3 === false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'obs',
|
value: 'obs',
|
||||||
label: t('kbSettings.storage.engineObs'),
|
label: t('kbSettings.storage.engineObs'),
|
||||||
desc: t('kbSettings.storage.engineObsDesc'),
|
desc: t('kbSettings.storage.engineObsDesc'),
|
||||||
allowed: allowedMap.obs !== false,
|
...obs,
|
||||||
available: statusMap.obs,
|
|
||||||
disabled: allowedMap.obs === false || statusMap.obs === false,
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -559,6 +559,17 @@ func (h *SystemHandler) isKS3Configured(c *gin.Context) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isOBSConfigured checks whether OBS connection info is available from tenant config or env.
|
||||||
|
func (h *SystemHandler) isOBSConfigured(c *gin.Context) bool {
|
||||||
|
if v, exists := c.Get(types.TenantInfoContextKey.String()); exists {
|
||||||
|
if tenant, ok := v.(*types.Tenant); ok && tenant != nil && tenant.StorageEngineConfig != nil && tenant.StorageEngineConfig.OBS != nil {
|
||||||
|
obsConf := tenant.StorageEngineConfig.OBS
|
||||||
|
return obsConf.Endpoint != "" && obsConf.Region != "" && obsConf.AccessKey != "" && obsConf.SecretKey != "" && obsConf.BucketName != ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return h.isOBSEnvAvailable()
|
||||||
|
}
|
||||||
|
|
||||||
// isTOSEnvAvailable checks whether TOS env vars are set.
|
// isTOSEnvAvailable checks whether TOS env vars are set.
|
||||||
func (h *SystemHandler) isTOSEnvAvailable() bool {
|
func (h *SystemHandler) isTOSEnvAvailable() bool {
|
||||||
return os.Getenv("TOS_ENDPOINT") != "" &&
|
return os.Getenv("TOS_ENDPOINT") != "" &&
|
||||||
@@ -568,9 +579,18 @@ func (h *SystemHandler) isTOSEnvAvailable() bool {
|
|||||||
os.Getenv("TOS_BUCKET_NAME") != ""
|
os.Getenv("TOS_BUCKET_NAME") != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isOBSEnvAvailable checks whether OBS env vars are set.
|
||||||
|
func (h *SystemHandler) isOBSEnvAvailable() bool {
|
||||||
|
return os.Getenv("OBS_ENDPOINT") != "" &&
|
||||||
|
os.Getenv("OBS_REGION") != "" &&
|
||||||
|
os.Getenv("OBS_ACCESS_KEY") != "" &&
|
||||||
|
os.Getenv("OBS_SECRET_KEY") != "" &&
|
||||||
|
os.Getenv("OBS_BUCKET_NAME") != ""
|
||||||
|
}
|
||||||
|
|
||||||
// StorageEngineStatusItem describes one storage engine's availability and description.
|
// StorageEngineStatusItem describes one storage engine's availability and description.
|
||||||
type StorageEngineStatusItem struct {
|
type StorageEngineStatusItem struct {
|
||||||
Name string `json:"name"` // "local", "minio", "cos", "tos", "s3", "oss", "ks3"
|
Name string `json:"name"` // "local", "minio", "cos", "tos", "s3", "oss", "ks3", "obs"
|
||||||
Allowed bool `json:"allowed"`
|
Allowed bool `json:"allowed"`
|
||||||
Available bool `json:"available"` // whether the engine can be used
|
Available bool `json:"available"` // whether the engine can be used
|
||||||
Description string `json:"description"` // short description for UI
|
Description string `json:"description"` // short description for UI
|
||||||
@@ -598,6 +618,7 @@ func (h *SystemHandler) GetStorageEngineStatus(c *gin.Context) {
|
|||||||
s3Configured := h.isS3Configured(c)
|
s3Configured := h.isS3Configured(c)
|
||||||
ossConfigured := h.isOSSConfigured(c)
|
ossConfigured := h.isOSSConfigured(c)
|
||||||
ks3Configured := h.isKS3Configured(c)
|
ks3Configured := h.isKS3Configured(c)
|
||||||
|
obsConfigured := h.isOBSConfigured(c)
|
||||||
allowed := getAllowedStorageProviders()
|
allowed := getAllowedStorageProviders()
|
||||||
allowedProviders := make([]string, 0, len(supportedStorageProviders))
|
allowedProviders := make([]string, 0, len(supportedStorageProviders))
|
||||||
for _, provider := range getSupportedStorageProviders() {
|
for _, provider := range getSupportedStorageProviders() {
|
||||||
@@ -613,6 +634,7 @@ func (h *SystemHandler) GetStorageEngineStatus(c *gin.Context) {
|
|||||||
{Name: "s3", Allowed: allowed["s3"], Available: s3Configured, Description: "AWS S3 与兼容对象存储服务,适合公有云与混合云部署"},
|
{Name: "s3", Allowed: allowed["s3"], Available: s3Configured, Description: "AWS S3 与兼容对象存储服务,适合公有云与混合云部署"},
|
||||||
{Name: "oss", Allowed: allowed["oss"], Available: ossConfigured, Description: "阿里云对象存储服务,适合公有云部署,支持 S3 兼容协议"},
|
{Name: "oss", Allowed: allowed["oss"], Available: ossConfigured, Description: "阿里云对象存储服务,适合公有云部署,支持 S3 兼容协议"},
|
||||||
{Name: "ks3", Allowed: allowed["ks3"], Available: ks3Configured, Description: "金山云对象存储服务,适合公有云部署"},
|
{Name: "ks3", Allowed: allowed["ks3"], Available: ks3Configured, Description: "金山云对象存储服务,适合公有云部署"},
|
||||||
|
{Name: "obs", Allowed: allowed["obs"], Available: obsConfigured, Description: "华为云对象存储服务,适合公有云部署"},
|
||||||
}
|
}
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"code": 0,
|
"code": 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user