diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-16 20:49:54 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-16 20:49:54 +0000 |
| commit | 48aec51b531d995574c5788e5f474343cc6e5c87 (patch) | |
| tree | 72590561f22185707e9bac65d6d14c21f69f309f /internal/storage | |
| parent | 7f920ca63af5329c19a0e5a879c649c594beea35 (diff) | |
fix: persist VAPID keys in DB instead of config file
The service runs as www-data which cannot write to the root-owned
config file. VAPID keys are now stored in the settings table in
SQLite (which is writable), loaded on startup, and generated once.
Removes saveVAPIDToConfig and the stale warning on every restart.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/storage')
| -rw-r--r-- | internal/storage/db.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/storage/db.go b/internal/storage/db.go index 51121e1..25801b2 100644 --- a/internal/storage/db.go +++ b/internal/storage/db.go @@ -94,6 +94,10 @@ func (s *DB) migrate() error { auth_key TEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP )`, + `CREATE TABLE IF NOT EXISTS settings ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL + )`, } for _, m := range migrations { if _, err := s.db.Exec(m); err != nil { @@ -835,3 +839,19 @@ func (s *DB) ListPushSubscriptions() ([]PushSubscription, error) { } return subs, rows.Err() } + +// GetSetting returns the value for a key, or ("", nil) if not found. +func (s *DB) GetSetting(key string) (string, error) { + var value string + err := s.db.QueryRow(`SELECT value FROM settings WHERE key = ?`, key).Scan(&value) + if err == sql.ErrNoRows { + return "", nil + } + return value, err +} + +// SetSetting upserts a key/value pair in the settings table. +func (s *DB) SetSetting(key, value string) error { + _, err := s.db.Exec(`INSERT INTO settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`, key, value) + return err +} |
