From 8b0f24948b3bfb68bf0eb284a5a984f55c9693d4 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 20 Jan 2026 17:30:15 -0800 Subject: feat: Add POST /api/reload endpoint for config reload - Add /api/reload endpoint that triggers configuration reload - Always requires API key authentication (even if api.access is public) - Returns error if no API keys are configured - Update config.example.yaml with new endpoint and {group}/{name} format docs --- cmd/kaze/main.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'cmd') diff --git a/cmd/kaze/main.go b/cmd/kaze/main.go index a71c03e..f4f61ac 100644 --- a/cmd/kaze/main.go +++ b/cmd/kaze/main.go @@ -131,20 +131,21 @@ func main() { logger.Info("kaze is running", "address", fmt.Sprintf("http://%s:%d", cfg.Server.Host, cfg.Server.Port)) - // Reload function - reloadConfig := func() { + // Reload function (returns error for API endpoint) + var reloadConfig func() error + reloadConfig = func() error { logger.Info("reloading configuration...") newCfg, err := config.Load(*configPath) if err != nil { logger.Error("failed to reload configuration", "error", err) - return + return fmt.Errorf("failed to load configuration: %w", err) } // Validate the new configuration if len(newCfg.Groups) == 0 { logger.Error("invalid configuration: no monitor groups defined") - return + return fmt.Errorf("invalid configuration: no monitor groups defined") } // Stop current scheduler @@ -160,7 +161,7 @@ func main() { logger.Error("failed to create new scheduler", "error", err) // Restart old scheduler sched.Start() - return + return fmt.Errorf("failed to create new scheduler: %w", err) } // Replace scheduler @@ -184,11 +185,12 @@ func main() { logger.Error("server error", "error", err) } }() - return + return fmt.Errorf("failed to create new server: %w", err) } - // Replace server + // Replace server and set reload func on new server srv = newSrv + srv.SetReloadFunc(reloadConfig) // Start new server go func() { @@ -201,8 +203,13 @@ func main() { logger.Info("configuration reloaded successfully", "groups", len(cfg.Groups), "incidents", len(cfg.Incidents)) + + return nil } + // Set reload function on server for API endpoint + srv.SetReloadFunc(reloadConfig) + // Wait for shutdown signal or config changes for { select { -- cgit v1.2.3