feat(admin): 优化后台运维与任务管理
完善平台、基准模型、定价规则和实时负载的紧凑查询与滚动展示,并固定关键操作列。 新增管理员任务记录、批量计费结算和用户组限流、额度及模型权限维护能力,同时补充任务脱敏、查询索引与 OpenAPI 契约。 验证:pnpm openapi、Go 全量测试、pnpm lint、pnpm test、pnpm build、gofmt 与差异格式检查均通过。
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
package store
|
||||
|
||||
import "strings"
|
||||
|
||||
const maskedAdminTaskValue = "***"
|
||||
|
||||
func MaskAdminGatewayTask(task AdminGatewayTask) AdminGatewayTask {
|
||||
task.Request = maskSensitiveObject(task.Request)
|
||||
task.Result = maskSensitiveObject(task.Result)
|
||||
task.Billings = maskSensitiveArray(task.Billings)
|
||||
task.Usage = maskSensitiveObject(task.Usage)
|
||||
task.Metrics = maskSensitiveObject(task.Metrics)
|
||||
task.BillingSummary = maskSensitiveObject(task.BillingSummary)
|
||||
task.PricingSnapshot = maskSensitiveObject(task.PricingSnapshot)
|
||||
task.CompatibilitySubmitHeaders = maskSensitiveObject(task.CompatibilitySubmitHeaders)
|
||||
task.CompatibilitySubmitBody = maskSensitiveObject(task.CompatibilitySubmitBody)
|
||||
task.Attempts = append([]TaskAttempt(nil), task.Attempts...)
|
||||
for index := range task.Attempts {
|
||||
task.Attempts[index].Usage = maskSensitiveObject(task.Attempts[index].Usage)
|
||||
task.Attempts[index].Metrics = maskSensitiveObject(task.Attempts[index].Metrics)
|
||||
task.Attempts[index].RequestSnapshot = maskSensitiveObject(task.Attempts[index].RequestSnapshot)
|
||||
task.Attempts[index].ResponseSnapshot = maskSensitiveObject(task.Attempts[index].ResponseSnapshot)
|
||||
task.Attempts[index].PricingSnapshot = maskSensitiveObject(task.Attempts[index].PricingSnapshot)
|
||||
}
|
||||
return task
|
||||
}
|
||||
|
||||
func MaskTaskParamPreprocessingLogs(items []TaskParamPreprocessingLog) []TaskParamPreprocessingLog {
|
||||
masked := make([]TaskParamPreprocessingLog, len(items))
|
||||
for index, item := range items {
|
||||
item.ActualInput = maskSensitiveObject(item.ActualInput)
|
||||
item.ConvertedOutput = maskSensitiveObject(item.ConvertedOutput)
|
||||
item.Changes = maskSensitiveArray(item.Changes)
|
||||
item.ModelSnapshot = maskSensitiveObject(item.ModelSnapshot)
|
||||
masked[index] = item
|
||||
}
|
||||
return masked
|
||||
}
|
||||
|
||||
func maskSensitiveObject(value map[string]any) map[string]any {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
masked, _ := maskSensitiveValue(value).(map[string]any)
|
||||
return masked
|
||||
}
|
||||
|
||||
func maskSensitiveArray(value []any) []any {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
masked, _ := maskSensitiveValue(value).([]any)
|
||||
return masked
|
||||
}
|
||||
|
||||
func maskSensitiveValue(value any) any {
|
||||
switch typed := value.(type) {
|
||||
case map[string]any:
|
||||
masked := make(map[string]any, len(typed))
|
||||
for key, item := range typed {
|
||||
if adminTaskSensitiveKey(key) {
|
||||
masked[key] = maskedAdminTaskValue
|
||||
continue
|
||||
}
|
||||
masked[key] = maskSensitiveValue(item)
|
||||
}
|
||||
return masked
|
||||
case []any:
|
||||
masked := make([]any, len(typed))
|
||||
for index, item := range typed {
|
||||
masked[index] = maskSensitiveValue(item)
|
||||
}
|
||||
return masked
|
||||
default:
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
func adminTaskSensitiveKey(key string) bool {
|
||||
normalized := strings.NewReplacer("_", "", "-", "", ".", "", " ", "").Replace(strings.ToLower(strings.TrimSpace(key)))
|
||||
switch normalized {
|
||||
case "authorization", "proxyauthorization", "apikey", "xapikey", "accesstoken", "refreshtoken",
|
||||
"idtoken", "token", "secret", "clientsecret", "password", "passwd", "cookie", "setcookie",
|
||||
"credentials", "credential", "privatekey":
|
||||
return true
|
||||
default:
|
||||
return strings.HasSuffix(normalized, "apikey") ||
|
||||
strings.HasSuffix(normalized, "accesstoken") ||
|
||||
strings.HasSuffix(normalized, "refreshtoken") ||
|
||||
strings.HasSuffix(normalized, "clientsecret") ||
|
||||
strings.HasSuffix(normalized, "password") ||
|
||||
strings.HasSuffix(normalized, "privatekey")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user