База lab7: контракт 1.7.0 и реализация lab1–lab6

Перенесены cmd/internal/config, compose.yaml, Dockerfile, скрипты, student-tests и evidence из mtusi-messenger (master, lab6). Skeleton lab7 (openapi/infrastructure 1.7.0, trust-matrix.md, security/THREAT_MODEL.md, infra/openbao, tests/security.py) сохранён; make test-security добавлен в Makefile.
This commit is contained in:
Vladislav Kunetskiy
2026-11-09 13:03:49 +03:00
parent 20afc2c790
commit 3d216fbd50
479 changed files with 84512 additions and 50 deletions
+38
View File
@@ -0,0 +1,38 @@
package rest
import (
"context"
"net/http"
"regexp"
"github.com/google/uuid"
)
const requestIDHeader = "X-Request-ID"
var requestIDPattern = regexp.MustCompile(`^[A-Za-z0-9._:-]{1,64}$`)
type requestIDKey struct{}
func requestIDFromContext(ctx context.Context) string {
id, _ := ctx.Value(requestIDKey{}).(string)
return id
}
func withRequestID(ctx context.Context, id string) context.Context {
return context.WithValue(ctx, requestIDKey{}, id)
}
func requestIDMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
id := r.Header.Get(requestIDHeader)
if !requestIDPattern.MatchString(id) {
id = uuid.NewString()
}
w.Header().Set(requestIDHeader, id)
next.ServeHTTP(w, r.WithContext(withRequestID(r.Context(), id)))
})
}