shared-sqs: Этапы 5+6 — Admin API, auth middleware, graceful shutdown
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// app/router/router.go
|
||||
// HTTP router для shared-sqs
|
||||
// Updated: 2026-04-09 — добавлены TenantStore, admin API, auth middleware
|
||||
package router
|
||||
|
||||
import (
|
||||
@@ -8,23 +11,34 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"shared-sqs/app/admin"
|
||||
"shared-sqs/app/auth"
|
||||
"shared-sqs/app/interfaces"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
sqs "shared-sqs/app/gosqs"
|
||||
"shared-sqs/app/tenant"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// New returns a new router
|
||||
func New() http.Handler {
|
||||
// New — создаёт HTTP router с tenant auth и admin API
|
||||
func New(tenantStore *tenant.TenantStore, adminToken string) http.Handler {
|
||||
r := mux.NewRouter()
|
||||
|
||||
r.HandleFunc("/", actionHandler).Methods("GET", "POST")
|
||||
// /health — публичный, без auth
|
||||
r.HandleFunc("/health", health).Methods("GET")
|
||||
r.HandleFunc("/{account}", actionHandler).Methods("GET", "POST")
|
||||
r.HandleFunc("/queue/{queueName}", actionHandler).Methods("GET", "POST")
|
||||
r.HandleFunc("/{account}/{queueName}", actionHandler).Methods("GET", "POST")
|
||||
|
||||
// Admin API — Bearer token auth, регистрируется через AdminHandler
|
||||
adminHandler := admin.NewHandler(tenantStore, adminToken)
|
||||
adminHandler.RegisterRoutes(r)
|
||||
|
||||
// SQS API — tenant auth middleware
|
||||
sqsRouter := r.NewRoute().Subrouter()
|
||||
sqsRouter.Use(auth.AuthMiddleware(tenantStore))
|
||||
sqsRouter.HandleFunc("/", actionHandler).Methods("GET", "POST")
|
||||
sqsRouter.HandleFunc("/{account}", actionHandler).Methods("GET", "POST")
|
||||
sqsRouter.HandleFunc("/queue/{queueName}", actionHandler).Methods("GET", "POST")
|
||||
sqsRouter.HandleFunc("/{account}/{queueName}", actionHandler).Methods("GET", "POST")
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -56,7 +70,7 @@ _, _ = w.Write(result)
|
||||
}
|
||||
}
|
||||
|
||||
// routingTableV1 содержит только SQS actions — SNS удалён
|
||||
// routingTableV1 — только SQS actions (SNS удалён)
|
||||
var routingTableV1 = map[string]func(r *http.Request) (int, interfaces.AbstractResponseBody){
|
||||
"CreateQueue": sqs.CreateQueueV1,
|
||||
"ListQueues": sqs.ListQueuesV1,
|
||||
@@ -80,8 +94,7 @@ fmt.Fprint(w, "OK")
|
||||
|
||||
func actionHandler(w http.ResponseWriter, req *http.Request) {
|
||||
action := extractAction(req)
|
||||
log.WithFields(
|
||||
log.Fields{
|
||||
log.WithFields(log.Fields{
|
||||
"action": action,
|
||||
"url": req.URL,
|
||||
}).Debug("Handling URL request")
|
||||
|
||||
Reference in New Issue
Block a user