From cdbc6057b0c11efc22352d71333b86d603da5b6f Mon Sep 17 00:00:00 2001 From: rcourtman Date: Tue, 21 Oct 2025 11:37:25 +0000 Subject: [PATCH] feat: export API tokens in config export Add API tokens to the export data so they are included when exporting/backing up configuration. This ensures API tokens are preserved when migrating or restoring Pulse instances. Changes: - Add APITokens field to ExportData struct - Load API tokens during export process - Include tokens in exported JSON (omitempty if none exist) --- internal/config/export.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/config/export.go b/internal/config/export.go index 1aca2d0..e855195 100644 --- a/internal/config/export.go +++ b/internal/config/export.go @@ -29,6 +29,7 @@ type ExportData struct { System SystemSettings `json:"system"` GuestMetadata map[string]*GuestMetadata `json:"guestMetadata,omitempty"` OIDC *OIDCConfig `json:"oidc,omitempty"` + APITokens []APITokenRecord `json:"apiTokens,omitempty"` } // ExportConfig exports all configuration with passphrase-based encryption @@ -79,6 +80,14 @@ func (c *ConfigPersistence) ExportConfig(passphrase string) (string, error) { return "", fmt.Errorf("failed to load oidc configuration: %w", err) } + apiTokens, err := c.LoadAPITokens() + if err != nil { + return "", fmt.Errorf("failed to load api tokens: %w", err) + } + if len(apiTokens) == 0 { + apiTokens = nil + } + // Load guest metadata (stored in data directory) // Use PULSE_DATA_DIR if set, otherwise use /etc/pulse for backwards compatibility dataPath := os.Getenv("PULSE_DATA_DIR") @@ -100,6 +109,7 @@ func (c *ConfigPersistence) ExportConfig(passphrase string) (string, error) { System: *systemSettings, GuestMetadata: guestMetadata, OIDC: oidcConfig, + APITokens: apiTokens, } // Marshal to JSON