lab7: безопасность, mTLS, OpenBao и PKI lifecycle
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"mtusi-messenger/internal/transport/rest/internal/oas"
|
||||
)
|
||||
|
||||
func NewRouter(
|
||||
handler oas.Handler,
|
||||
security oas.SecurityHandler,
|
||||
extensions *Extensions,
|
||||
log *slog.Logger,
|
||||
maxBodyBytes, maxUploadBytes int64,
|
||||
) (http.Handler, error) {
|
||||
server, err := oas.NewServer(
|
||||
handler,
|
||||
security,
|
||||
oas.WithErrorHandler(newErrorHandler(log)),
|
||||
oas.WithNotFound(newNotFoundHandler(log)),
|
||||
oas.WithMethodNotAllowed(newMethodNotAllowedHandler(log)),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
if extensions != nil {
|
||||
// These routes are an optional contract extension (presigned uploads).
|
||||
// They live outside the generated server so contracts/openapi.json stays
|
||||
// byte-identical to the mandatory contract.
|
||||
mux.Handle("/api/v1/chats/{chat_id}/attachments/presign", extensions.Presign())
|
||||
mux.Handle("/api/v1/attachments/{attachment_id}/complete", extensions.Complete())
|
||||
}
|
||||
|
||||
mux.Handle("/", server)
|
||||
|
||||
limited := bodyLimitMiddleware(maxBodyBytes, maxUploadBytes, log, mux)
|
||||
|
||||
return requestIDMiddleware(
|
||||
instanceIDMiddleware(InstanceID(), telemetryMiddleware(log, server, mux, limited)),
|
||||
), nil
|
||||
}
|
||||
Reference in New Issue
Block a user