backup: pre-hardening baseline

This commit is contained in:
backup 2026-09-02 11:20:31 -05:00
commit 9e4c612dcb
57 changed files with 10393 additions and 0 deletions

View file

@ -0,0 +1,53 @@
package handlers
import (
"net/http"
"os"
"time"
"github.com/gin-gonic/gin"
)
type HealthHandler struct {
startTime time.Time
configDir string
}
func NewHealthHandler() *HealthHandler {
return &HealthHandler{startTime: time.Now()}
}
func (h *HealthHandler) SetConfigDir(dir string) {
h.configDir = dir
}
func (h *HealthHandler) Health(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
"uptime": time.Since(h.startTime).String(),
"timestamp": time.Now().Format(time.RFC3339),
"version": "dev",
})
}
func (h *HealthHandler) Ready(c *gin.Context) {
configStatus := "ok"
if h.configDir != "" {
if _, err := os.Stat(h.configDir); err != nil {
configStatus = "error: " + err.Error()
} else if f, err := os.CreateTemp(h.configDir, ".writetest"); err != nil {
configStatus = "not writable: " + err.Error()
} else {
f.Close()
os.Remove(f.Name())
}
}
c.JSON(http.StatusOK, gin.H{
"status": "ready",
"checks": gin.H{
"database": "ok",
"traefik": "ok",
"configDir": configStatus,
},
})
}