Files
AIRouter/cmd/createkey/main.go
T
selfrelease da9c8334d8
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
CI / security-scan (push) Has been cancelled
feat: 十轮网关优化 - 安全加固/可观测性/性能/可靠性
- SSE Keepalive Ping (15s心跳防止代理断连)
- Timing HTTP 头 (X-Timing-Queue/Inference/Total-Ms)
- Adapter Request-ID 传播到后端
- Session 清理日志回调
- Server 安全加固 (ReadHeaderTimeout/MaxHeaderBytes 防 slowloris)
- Usage Tracker 数据保留清理 (retentionDays + 定期清理)
- Config Reload 后 Adapter Registry 更新 (RegisterIfAbsent + RWMutex)
- Rate Limiter 空闲 Bucket 清理 (30分钟过期)
- Shutdown Drain 超时可配置 (ShutdownDrainSeconds)
- Config 模型字段校验增强 (provider/endpoint/actual_model)
- Auth 过期 Key 自动清理 (5分钟扫描)
- Admin API Rate Limiting
- Adapter Health Check 独立超时 (每个 adapter 3s)
- TCP 连接阶段超时 (DialContext 5s + KeepAlive 30s)
- 幂等键缓存、审计日志、Gzip 中间件、CORS Expose Headers
- Backpressure 响应头、熔断器 Prometheus 指标
- 连接池优化、Trace-ID 全链路传播
2026-08-03 15:43:11 +08:00

67 lines
1.8 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/edgeai/gateway/internal/auth"
"github.com/edgeai/gateway/internal/observability"
)
func main() {
dbPath := flag.String("db", "/tmp/edgeai-data/auth.db", "auth database path")
appID := flag.String("app", "test", "application ID")
tenantID := flag.String("tenant", "default", "tenant ID")
name := flag.String("name", "test", "key name")
models := flag.String("models", "", "allowed models (comma-separated, empty=all)")
priorities := flag.String("priorities", "0,1,2,3", "allowed priorities (comma-separated)")
isAdmin := flag.Bool("admin", false, "is admin key")
keyValue := flag.String("key", "", "specific API key value (auto-generated if empty)")
flag.Parse()
observability.SetLogLevel("info")
logger := observability.GetLogger()
a, err := auth.NewAuthenticator(*dbPath, logger)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
defer a.Close()
var allowedModels []string
if *models != "" {
allowedModels = strings.Split(*models, ",")
}
var allowedPriorities []int
for _, p := range strings.Split(*priorities, ",") {
p = strings.TrimSpace(p)
if p != "" {
var v int
fmt.Sscanf(p, "%d", &v)
allowedPriorities = append(allowedPriorities, v)
}
}
apiKey := *keyValue
if apiKey == "" {
apiKey = auth.GenerateAPIKey()
}
identity := &auth.AppIdentity{
AppID: *appID,
TenantID: *tenantID,
Name: *name,
AllowedModels: allowedModels,
AllowedPriorities: allowedPriorities,
IsAdmin: *isAdmin,
}
if err := a.AddKey(apiKey, identity); err != nil {
fmt.Fprintf(os.Stderr, "AddKey error: %v\n", err)
os.Exit(1)
}
fmt.Printf("API key created successfully:\n key: %s\n app: %s\n name: %s\n admin: %v\n", apiKey, *appID, *name, *isAdmin)
}