It's state, not config.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
@@ -54,10 +55,6 @@ type API struct {
|
||||
func NewAPI(dataDir, version string, allowedOrigins []string) (*API, error) {
|
||||
configMgr := config.NewManager()
|
||||
|
||||
if err := configMgr.EnsureGlobalConfig(dataDir); err != nil {
|
||||
return nil, fmt.Errorf("failed to ensure global config: %w", err)
|
||||
}
|
||||
|
||||
// Determine config paths from env or defaults
|
||||
dnsmasqConfigPath := envOrDefault("WILD_CENTRAL_DNSMASQ_CONFIG_PATH", "/etc/dnsmasq.d/wild-cloud.conf")
|
||||
haproxyConfigPath := envOrDefault("WILD_CENTRAL_HAPROXY_CONFIG_PATH", "/etc/haproxy/haproxy.cfg")
|
||||
@@ -118,8 +115,7 @@ func (api *API) StartDDNS(ctx gocontext.Context) {
|
||||
|
||||
// reloadDDNSIfEnabled re-reads DDNS config and secrets and restarts the DDNS goroutine.
|
||||
func (api *API) reloadDDNSIfEnabled() {
|
||||
globalConfigPath := filepath.Join(api.dataDir, "config.yaml")
|
||||
globalCfg, err := config.LoadGlobalConfig(globalConfigPath)
|
||||
globalCfg, err := config.LoadState(api.statePath())
|
||||
if err != nil || !globalCfg.Cloud.DDNS.Enabled {
|
||||
api.ddns.Stop()
|
||||
return
|
||||
@@ -246,9 +242,9 @@ func (api *API) RegisterRoutes(r *mux.Router) {
|
||||
|
||||
// --- Global Config/Secrets handlers ---
|
||||
|
||||
// GetGlobalConfig returns the global config wrapped in { configured, config }.
|
||||
// GetGlobalConfig returns the global state wrapped in { configured, config }.
|
||||
func (api *API) GetGlobalConfig(w http.ResponseWriter, r *http.Request) {
|
||||
configPath := filepath.Join(api.dataDir, "config.yaml")
|
||||
configPath := api.statePath()
|
||||
data, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
respondJSON(w, http.StatusOK, map[string]any{
|
||||
@@ -269,9 +265,9 @@ func (api *API) GetGlobalConfig(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateGlobalConfig updates the global config
|
||||
// UpdateGlobalConfig updates the global state
|
||||
func (api *API) UpdateGlobalConfig(w http.ResponseWriter, r *http.Request) {
|
||||
configPath := filepath.Join(api.dataDir, "config.yaml")
|
||||
configPath := api.statePath()
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
@@ -285,10 +281,10 @@ func (api *API) UpdateGlobalConfig(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Read existing config
|
||||
// Read existing state (may not exist yet)
|
||||
existingContent, err := storage.ReadFile(configPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
respondError(w, http.StatusInternalServerError, "Failed to read existing config")
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
respondError(w, http.StatusInternalServerError, "Failed to read existing state")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -423,18 +419,12 @@ func (api *API) UpdateGlobalSecrets(w http.ResponseWriter, r *http.Request) {
|
||||
func (api *API) StatusHandler(w http.ResponseWriter, r *http.Request, startTime time.Time, dataDir string) {
|
||||
uptime := time.Since(startTime)
|
||||
|
||||
pendingRestart := false
|
||||
if info, err := os.Stat(filepath.Join(dataDir, "config.yaml")); err == nil {
|
||||
pendingRestart = info.ModTime().After(startTime)
|
||||
}
|
||||
|
||||
respondJSON(w, http.StatusOK, map[string]any{
|
||||
"status": "running",
|
||||
"version": api.version,
|
||||
"uptime": uptime.String(),
|
||||
"uptimeSeconds": int(uptime.Seconds()),
|
||||
"dataDir": dataDir,
|
||||
"pendingRestart": pendingRestart,
|
||||
"status": "running",
|
||||
"version": api.version,
|
||||
"uptime": uptime.String(),
|
||||
"uptimeSeconds": int(uptime.Seconds()),
|
||||
"dataDir": dataDir,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user