ЛР7 на 4: HTTPS, mTLS, OpenBao AppRole и ротация leaf.
Skeleton contracts / contracts (pull_request) Blocked by required conditions

Smoke/security/grade4/persistence/failover пройдены; REPORT и DEFENSE.
This commit is contained in:
2026-12-02 23:08:27 +03:00
parent 20afc2c790
commit 2f2047909f
182 changed files with 15169 additions and 90 deletions
+77
View File
@@ -0,0 +1,77 @@
package app
import (
"log/slog"
"net/http"
"time"
"github.com/go-chi/chi/v5"
goredis "github.com/redis/go-redis/v9"
"gavrilenko-sxdees/lab7/internal/handler"
"gavrilenko-sxdees/lab7/internal/middleware"
"gavrilenko-sxdees/lab7/internal/service"
)
func NewRouter(
log *slog.Logger,
instanceID string,
maxInflightRequests int,
maxUploadBytes int,
sessionCache *goredis.Client,
db handler.Pinger,
storage handler.Pinger,
authService *service.AuthService,
userService *service.UserService,
chatService *service.ChatService,
messageService *service.MessageService,
attachmentService *service.AttachmentService,
) http.Handler {
router := chi.NewRouter()
loginLimiter := middleware.NewLoginLimiter(sessionCache)
healthHandler := handler.NewHealthHandler(log, db, storage)
authHandler := handler.NewAuthHandler(authService)
userHandler := handler.NewUserHandler(userService)
chatHandler := handler.NewChatHandler(chatService)
messageHandler := handler.NewMessageHandler(messageService)
attachmentHandler := handler.NewAttachmentHandler(attachmentService, maxUploadBytes)
router.Use(middleware.InstanceID(instanceID))
router.Use(middleware.Telemetry())
router.Use(middleware.RequestTimeout(5 * time.Second))
router.Use(middleware.RequestID)
router.Use(middleware.Logging(log))
router.Use(middleware.ConcurrencyLimit(maxInflightRequests))
router.Get("/health/live", healthHandler.Live)
router.Get("/health/ready", healthHandler.Ready)
router.Post("/api/v1/users", userHandler.Create)
router.With(loginLimiter.Limit).Post("/api/v1/auth/sessions", authHandler.CreateSession)
router.Delete("/api/v1/auth/sessions/current", authHandler.RevokeSession)
router.Group(func(r chi.Router) {
r.Use(middleware.Auth(authService))
r.Get("/api/v1/users/me", userHandler.Me)
r.Post("/api/v1/chats", chatHandler.Create)
r.Get("/api/v1/chats", chatHandler.List)
r.Get("/api/v1/chats/{chat_id}", chatHandler.Get)
r.Post("/api/v1/chats/{chat_id}/messages", messageHandler.Create)
r.Get("/api/v1/chats/{chat_id}/messages", messageHandler.List)
r.Post("/api/v1/chats/{chat_id}/attachments", attachmentHandler.Upload)
r.Get("/api/v1/attachments/{attachment_id}", attachmentHandler.Get)
r.Get("/api/v1/attachments/{attachment_id}/content", attachmentHandler.GetContent)
})
router.Handle("/swagger/*", http.StripPrefix("/swagger/", http.FileServer(http.Dir("web/swagger"))))
router.Handle("/contracts/*", http.StripPrefix("/contracts/", http.FileServer(http.Dir("contracts"))))
return router
}