mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-05-20 01:01:20 +00:00
fix: reload guest metadata after import
- Guest metadata handler now reloads from disk after import - Custom console URLs are immediately available after import - No longer requires service restart to see imported guest URLs
This commit is contained in:
parent
f62016099b
commit
cdc77860ee
4 changed files with 32 additions and 16 deletions
|
|
@ -24,24 +24,26 @@ import (
|
|||
|
||||
// ConfigHandlers handles configuration-related API endpoints
|
||||
type ConfigHandlers struct {
|
||||
config *config.Config
|
||||
persistence *config.ConfigPersistence
|
||||
monitor *monitoring.Monitor
|
||||
reloadFunc func() error
|
||||
wsHub *websocket.Hub
|
||||
setupTokens map[string]time.Time // Temporary tokens for setup script access
|
||||
tokenMutex sync.RWMutex // Mutex for thread-safe token access
|
||||
config *config.Config
|
||||
persistence *config.ConfigPersistence
|
||||
monitor *monitoring.Monitor
|
||||
reloadFunc func() error
|
||||
wsHub *websocket.Hub
|
||||
guestMetadataHandler *GuestMetadataHandler
|
||||
setupTokens map[string]time.Time // Temporary tokens for setup script access
|
||||
tokenMutex sync.RWMutex // Mutex for thread-safe token access
|
||||
}
|
||||
|
||||
// NewConfigHandlers creates a new ConfigHandlers instance
|
||||
func NewConfigHandlers(cfg *config.Config, monitor *monitoring.Monitor, reloadFunc func() error, wsHub *websocket.Hub) *ConfigHandlers {
|
||||
func NewConfigHandlers(cfg *config.Config, monitor *monitoring.Monitor, reloadFunc func() error, wsHub *websocket.Hub, guestMetadataHandler *GuestMetadataHandler) *ConfigHandlers {
|
||||
h := &ConfigHandlers{
|
||||
config: cfg,
|
||||
persistence: config.NewConfigPersistence(cfg.DataPath),
|
||||
monitor: monitor,
|
||||
reloadFunc: reloadFunc,
|
||||
wsHub: wsHub,
|
||||
setupTokens: make(map[string]time.Time),
|
||||
config: cfg,
|
||||
persistence: config.NewConfigPersistence(cfg.DataPath),
|
||||
monitor: monitor,
|
||||
reloadFunc: reloadFunc,
|
||||
wsHub: wsHub,
|
||||
guestMetadataHandler: guestMetadataHandler,
|
||||
setupTokens: make(map[string]time.Time),
|
||||
}
|
||||
|
||||
// Clean up expired tokens periodically
|
||||
|
|
@ -1599,6 +1601,15 @@ func (h *ConfigHandlers) HandleImportConfig(w http.ResponseWriter, r *http.Reque
|
|||
}
|
||||
}
|
||||
|
||||
// Reload guest metadata from disk
|
||||
if h.guestMetadataHandler != nil {
|
||||
if err := h.guestMetadataHandler.Reload(); err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to reload guest metadata after import")
|
||||
} else {
|
||||
log.Info().Msg("Reloaded guest metadata after import")
|
||||
}
|
||||
}
|
||||
|
||||
log.Info().Msg("Configuration imported successfully")
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ func NewGuestMetadataHandler(dataPath string) *GuestMetadataHandler {
|
|||
}
|
||||
}
|
||||
|
||||
// Reload reloads the guest metadata from disk
|
||||
func (h *GuestMetadataHandler) Reload() error {
|
||||
return h.store.Load()
|
||||
}
|
||||
|
||||
// HandleGetMetadata retrieves metadata for a specific guest or all guests
|
||||
func (h *GuestMetadataHandler) HandleGetMetadata(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@ func (r *Router) setupRoutes() {
|
|||
// Create handlers
|
||||
alertHandlers := NewAlertHandlers(r.monitor)
|
||||
notificationHandlers := NewNotificationHandlers(r.monitor)
|
||||
configHandlers := NewConfigHandlers(r.config, r.monitor, r.reloadFunc, r.wsHub)
|
||||
updateHandlers := NewUpdateHandlers(r.updateManager)
|
||||
guestMetadataHandler := NewGuestMetadataHandler(r.config.DataPath)
|
||||
configHandlers := NewConfigHandlers(r.config, r.monitor, r.reloadFunc, r.wsHub, guestMetadataHandler)
|
||||
updateHandlers := NewUpdateHandlers(r.updateManager)
|
||||
|
||||
// API routes
|
||||
r.mux.HandleFunc("/api/health", r.handleHealth)
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue