feat(admin): 增加登录限流、审计与令牌退出 (#42)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
fu500f
2026-10-31 00:50:23 +00:00
co-authored by Devin AI
parent 36f9c95fa7
commit 065198f227
11 changed files with 496 additions and 12 deletions
+9 -1
View File
@@ -32,6 +32,14 @@ func main() {
dbURL := getenv("OPENGOODS_DATABASE_URL", "postgres://opengoods:opengoods@localhost:5432/opengoods?sslmode=disable")
basePath := getenv("GOODS_ADMIN_BASE_PATH", "/ping")
username := getenv("GOODS_ADMIN_USER", "admin")
tokenTTL := 12 * time.Hour
if value := os.Getenv("GOODS_ADMIN_TOKEN_TTL"); value != "" {
parsed, err := time.ParseDuration(value)
if err != nil || parsed <= 0 {
log.Fatalf("invalid GOODS_ADMIN_TOKEN_TTL %q: expected a positive duration", value)
}
tokenTTL = parsed
}
// Password: prefer a bcrypt hash; otherwise hash a plaintext password.
var passwordHash []byte
@@ -69,7 +77,7 @@ func main() {
log.Printf("warning: database not reachable at startup: %v", err)
}
authn := auth.New(username, passwordHash, secret, 12*time.Hour)
authn := auth.New(username, passwordHash, secret, tokenTTL)
usage := ratelimit.New(getenv("OPENGOODS_REDIS_URL", "redis://localhost:6379/0"))
h := adminhandler.New(adminstore.New(pool), authn, basePath, adminweb.Dist()).
WithUsage(usage)