feat(api): add POST /api/config/reset endpoint
Add handleResetConfig handler that calls ResetToDefaults, applies runtime log level, and restarts the gateway if running.
This commit is contained in:
parent
d61902d42a
commit
f53222f6a4
1 changed files with 27 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ func (h *Handler) registerConfigRoutes(mux *http.ServeMux) {
|
||||||
mux.HandleFunc("GET /api/config", h.handleGetConfig)
|
mux.HandleFunc("GET /api/config", h.handleGetConfig)
|
||||||
mux.HandleFunc("PUT /api/config", h.handleUpdateConfig)
|
mux.HandleFunc("PUT /api/config", h.handleUpdateConfig)
|
||||||
mux.HandleFunc("PATCH /api/config", h.handlePatchConfig)
|
mux.HandleFunc("PATCH /api/config", h.handlePatchConfig)
|
||||||
|
mux.HandleFunc("POST /api/config/reset", h.handleResetConfig)
|
||||||
mux.HandleFunc("POST /api/config/test-command-patterns", h.handleTestCommandPatterns)
|
mux.HandleFunc("POST /api/config/test-command-patterns", h.handleTestCommandPatterns)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -211,6 +212,32 @@ func (h *Handler) handlePatchConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
|
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleResetConfig resets the configuration to factory defaults.
|
||||||
|
// API keys and security credentials are preserved.
|
||||||
|
//
|
||||||
|
// POST /api/config/reset
|
||||||
|
func (h *Handler) handleResetConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if err := config.ResetToDefaults(h.configPath); err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("Failed to reset config: %v", err), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.applyRuntimeLogLevel()
|
||||||
|
logger.Infof("configuration reset to factory defaults")
|
||||||
|
|
||||||
|
// Restart gateway if running
|
||||||
|
status := h.gatewayStatusData()
|
||||||
|
gatewayStatus, _ := status["gateway_status"].(string)
|
||||||
|
if gatewayStatus == "running" {
|
||||||
|
if _, err := h.RestartGateway(); err != nil {
|
||||||
|
logger.ErrorF("failed to restart gateway after config reset", map[string]any{"error": err.Error()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
|
||||||
|
}
|
||||||
|
|
||||||
// handleTestCommandPatterns tests a command against whitelist and blacklist patterns.
|
// handleTestCommandPatterns tests a command against whitelist and blacklist patterns.
|
||||||
//
|
//
|
||||||
// POST /api/config/test-command-patterns
|
// POST /api/config/test-command-patterns
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue