ЛР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
+62
View File
@@ -0,0 +1,62 @@
package handler
import (
"context"
"encoding/json"
"log/slog"
"net/http"
"time"
"gavrilenko-sxdees/lab7/internal/dto"
"gavrilenko-sxdees/lab7/internal/httpx"
)
const readyPingTimeout = 2 * time.Second
type Pinger interface {
Ping(ctx context.Context) error
}
type HealthHandler struct {
log *slog.Logger
dependencies []Pinger
}
func NewHealthHandler(log *slog.Logger, dependencies ...Pinger) *HealthHandler {
return &HealthHandler{log: log, dependencies: dependencies}
}
func (h *HealthHandler) Live(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(dto.HealthResponse{
Status: "ok",
})
}
func (h *HealthHandler) Ready(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), readyPingTimeout)
defer cancel()
for _, dependency := range h.dependencies {
if err := dependency.Ping(ctx); err != nil {
h.log.ErrorContext(r.Context(), "readiness check failed", "error", err)
httpx.WriteError(
w,
http.StatusServiceUnavailable,
dto.ErrorCodeUnavailable,
"service unavailable",
w.Header().Get("X-Request-Id"),
)
return
}
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(dto.HealthResponse{
Status: "ok",
})
}