Add a read-only integration feed of walks and meals

GET /api/integration/events?since=<unix ms> returns one account's walk
starts and meals that happened or changed since then, tombstones
included, for other services on the same host. It is authenticated
with a bearer token rather than a session and cannot write anything.

Enabled with -integration-token-file (services.puppy-tracker
.integration.tokenFile); -integration-user picks the account, and
defaults to the only one.
This commit is contained in:
Alexander Heldt committed 2026-09-29 19:13:28 +00:00
1 parent b572371666
commit 15211e32b0
4 files changed
+220 -1

No files matched your search

+15
View File
@@ -864,6 +864,10 @@ func main() {
"mark session cookies Secure (enable when served over HTTPS / behind a TLS proxy)")
vapidKey := flag.String("vapid-key", os.Getenv("PUPPY_VAPID_KEY"),
"base64url P-256 private key for Web Push (env PUPPY_VAPID_KEY); generated next to the DB when unset")
integrationTokenFile := flag.String("integration-token-file", "",
"file holding the bearer token for the read-only /api/integration/events; unset disables it")
integrationUser := flag.String("integration-user", "",
"email of the account /api/integration/events exposes; empty means the only account")
flag.Parse()
db, err := openDB(*dataPath)
@@ -1096,6 +1100,17 @@ func main() {
mux.HandleFunc("/api/reminders", auth.requireOwner(scheduler.handleReminders))
}
// Read-only feed of walks and meals for other services on this host.
if *integrationTokenFile != "" {
raw, err := os.ReadFile(*integrationTokenFile)
token := strings.TrimSpace(string(raw))
if err != nil || token == "" {
log.Fatalf("integration token file %s: unreadable or empty (%v)", *integrationTokenFile, err)
}
in := &Integration{db: db, token: token, email: *integrationUser}
mux.HandleFunc("/api/integration/events", in.handleEvents)
}
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok"))
})