security: hardening по результатам аудита безопасности

This commit is contained in:
2026-08-08 22:48:16 +03:00
parent 8c8631ac9c
commit bf2bceb520
18 changed files with 400 additions and 20 deletions
+45
View File
@@ -0,0 +1,45 @@
package main
import (
"context"
"fmt"
"net/http"
"time"
"github.com/spf13/cobra"
)
func newHealthcheckCmd() *cobra.Command {
var port int
cmd := &cobra.Command{
Use: "healthcheck",
Short: "Check the scheduler health endpoint",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), 3*time.Second)
defer cancel()
url := fmt.Sprintf("http://127.0.0.1:%d/healthz", port)
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return fmt.Errorf("build health request: %w", err)
}
response, err := http.DefaultClient.Do(request)
if err != nil {
return fmt.Errorf("health request failed: %w", err)
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return fmt.Errorf("health check returned status %d", response.StatusCode)
}
return nil
},
}
cmd.Flags().IntVar(&port, "port", 8080, "Health check server port")
return cmd
}