Files
syncwarden/internal/syncthing/config_xml.go

28 lines
532 B
Go

package syncthing
import (
"encoding/xml"
"os"
"git.davoryn.de/calic/syncwarden/internal/config"
)
type syncthingConfig struct {
GUI struct {
APIKey string `xml:"apikey"`
} `xml:"gui"`
}
// DiscoverAPIKey reads the Syncthing config.xml and extracts the API key.
func DiscoverAPIKey() (string, error) {
data, err := os.ReadFile(config.SyncthingConfigPath())
if err != nil {
return "", err
}
var cfg syncthingConfig
if err := xml.Unmarshal(data, &cfg); err != nil {
return "", err
}
return cfg.GUI.APIKey, nil
}