ЛР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
+46
View File
@@ -0,0 +1,46 @@
package middleware
import (
"net/http"
"time"
"go.opentelemetry.io/otel/trace"
"gavrilenko-sxdees/lab7/internal/telemetry"
)
type statusWriter struct {
http.ResponseWriter
status int
}
func (w *statusWriter) Unwrap() http.ResponseWriter {
return w.ResponseWriter
}
func (w *statusWriter) WriteHeader(status int) {
w.status = status
w.ResponseWriter.WriteHeader(status)
}
func Telemetry() func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
ctx, span := telemetry.Start(telemetry.Incoming(r), "http.request", trace.SpanKindServer)
defer span.End()
writer := &statusWriter{ResponseWriter: w, status: http.StatusOK}
next.ServeHTTP(writer, r.WithContext(ctx))
route := telemetry.RoutePattern(r)
if route == "/health/live" || route == "/health/ready" {
return
}
telemetry.HTTP(ctx, r.Method, route, writer.status, time.Since(start).Seconds())
if tid := telemetry.TraceID(ctx); tid != "" && tid != "00000000000000000000000000000000" {
w.Header().Set("X-Trace-Id", tid)
}
})
}
}