feat(providers): provider settings in a table and a careful outbound HTTP client

- feat(storage): provider_settings table (provider, enabled, api_key, contact);
  migration 0007 for both drivers. A provider with no row, or turned off, is
  never contacted
- feat(providers): a service that validates and applies settings: a Last.fm key
  is 32 hexadecimal characters, enabling a provider that needs a key without
  one is refused, clearing the key turns the provider off, a contact cannot
  contain parentheses or control characters. Each provider states what it sends
  and under which terms, and what it never sends
- feat(api): admin-only GET /providers and PUT /providers/{name}. The API key is
  write-only: responses carry only has_api_key, errors never repeat it and the
  request log never contains it (tested)
- feat(providers/outbound): the only way Sonda talks to the outside: plain GET
  with an identifiable User-Agent, no cookies, no Referer, no Authorization, no
  redirects, bounded answers, a timeout per attempt, a minimum interval between
  requests, retries with exponential backoff that honour Retry-After without
  waiting past the caller's deadline or for an absurd time, and a circuit
  breaker that makes a failing provider fail fast
- feat(providers): UserAgent builds "Sonda/version ( contact )" as MusicBrainz
  asks, defaulting to the project address so no personal address is sent
- breaking(config): providers.lastfm and SONDA_LASTFM_API_KEY are gone; an old
  config, or the variable, fails with a hint instead of being ignored
- docs: OpenAPI operations and schemas, README section on the providers and on
  what leaves the server
- test: fake servers and a fake clock only; no network in the suite
This commit is contained in:
tgiachi 2026-11-11 16:07:12 +01:00
commit 9f4da2e77e

View file

@ -1,7 +1,7 @@
# Copy to sonda.toml and adjust. sonda.toml is git-ignored.
# Precedence: defaults < this file < environment variables
# (SONDA_ENV, SONDA_LISTEN, SONDA_DB_DRIVER, SONDA_DB_PATH, SONDA_DB_DSN,
# SONDA_JWT_SECRET, SONDA_LASTFM_API_KEY).
# SONDA_JWT_SECRET).
[server]
listen = "127.0.0.1:8080" # localhost by default
@ -26,5 +26,4 @@ refresh_ttl_hours = 720 # lifetime of a refresh token (30 days)
[listening]
min_listen_seconds = 20 # a play counts as a listen after this long, or when it completes
[providers.lastfm]
api_key = ""
# Last.fm and MusicBrainz are set up through the API, not here: PUT /api/v1/providers/{name}.