CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
Implements PLAN.md Phase 1. A client can now register, log in, manage its devices and set its profile; an operator can create accounts and flip the runtime switches. There are still no rooms and no real /sync. userapi: accounts, argon2id passwords in PHC format, devices, access and refresh tokens stored as SHA-256 hashes, account data and the admin flag. Its storage interface is storage.UserStore, implemented once in sqlstore with `?` placeholders; the postgres driver supplies a rebind function and unique-violation recognition rather than keeping a second copy of thirty statements. Timestamps in these tables are int64 milliseconds, the unit the Client-Server API uses on the wire. Client-Server API: register (user-interactive auth with m.login.dummy and optional registration tokens), register/available, token validity, login with m.login.password, logout, logout/all, refresh, account/whoami, capabilities, devices/* with password-gated deletion, profile/*, global and per-room account data. GET /sync is a deliberate placeholder: it answers a valid token with an empty but well-formed response and refuses a revoked one. Phase 1 has no rooms, so that is the whole truth, and it is what makes session revocation observable. Phase 4 replaces it with the syncapi. Auth middleware resolves a bearer token (header or the legacy query parameter) to a device and user, answering an expired token with the soft logout the spec asks for. Rate limiting is a token bucket per endpoint class keyed on the client address, returning M_LIMIT_EXCEEDED with retry_after_ms. adminapi v1 under /_warp/admin/v1: admin-only auth via a normal Matrix token, GET/PUT /federation and /registration driving internal/settings and reporting a config-pinned switch as a 409, GET/POST /users, GET /stats. warp create-account [--admin] creates the first account straight in the database, so a new install with registration off has a way in. Complement is wired up for the federation=off profile: an image meeting its contract, an entrypoint that configures Warp entirely from WARP_* variables, and a runner that builds, clones and executes the target set (TestRegistration, TestLogin, TestDeviceManagement). It has not been run yet -- there is no container runtime on the development machine -- so the three tests' assertions were read from the Complement sources and pinned as httptest tests instead, and CI gained a job that runs the real thing. Also fixes a .gitignore bug from Phase 0: the unanchored `warp` pattern, meant for the built binary, also matched the directory server/cmd/warp and silently excluded the entire command package from the repository. The binary patterns are now anchored to the repository root, and cmd/warp is committed for the first time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
171 lines
5.9 KiB
Go
171 lines
5.9 KiB
Go
// Package pocketbase is the placeholder for the PocketBase storage driver.
|
|
//
|
|
// The plan (PLAN.md section 4) is an appliance deployment: one binary that
|
|
// also brings admin auth, a filesystem abstraction for media (local or S3)
|
|
// and realtime for the admin panel. The event DAG is a poor fit for
|
|
// PocketBase's record model, so the roomserver and syncapi tables will use
|
|
// its underlying dbx connection directly rather than its collection API.
|
|
//
|
|
// Until that work starts (Phase 10) the driver is compiled in, registered
|
|
// and fails loudly, so that `database.driver: pocketbase` is a clear error
|
|
// instead of an unknown-driver one, and so the interface stays honest:
|
|
// every method the other drivers implement exists here too.
|
|
package pocketbase
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/dariuszjaniak/warp/server/internal/storage"
|
|
)
|
|
|
|
func init() {
|
|
storage.Register(storage.DriverPocketBase, Open)
|
|
}
|
|
|
|
// Database is the not-yet-implemented PocketBase driver.
|
|
type Database struct{}
|
|
|
|
// Open always fails with storage.ErrNotImplemented.
|
|
func Open(context.Context, storage.Config, *slog.Logger) (storage.Database, error) {
|
|
return nil, fmt.Errorf(
|
|
"pocketbase driver is not implemented yet (planned for Phase 10); use %q or %q: %w",
|
|
storage.DriverSQLite, storage.DriverPostgres, storage.ErrNotImplemented)
|
|
}
|
|
|
|
// Driver implements storage.Database.
|
|
func (*Database) Driver() string { return storage.DriverPocketBase }
|
|
|
|
// Ping implements storage.Database.
|
|
func (*Database) Ping(context.Context) error { return storage.ErrNotImplemented }
|
|
|
|
// Migrate implements storage.Database.
|
|
func (*Database) Migrate(context.Context) error { return storage.ErrNotImplemented }
|
|
|
|
// PendingMigrations implements storage.Database.
|
|
func (*Database) PendingMigrations(context.Context) ([]string, error) {
|
|
return nil, storage.ErrNotImplemented
|
|
}
|
|
|
|
// Settings implements storage.Database.
|
|
func (*Database) Settings() storage.SettingsStore { return notImplementedSettings{} }
|
|
|
|
// Users implements storage.Database.
|
|
func (*Database) Users() storage.UserStore { return notImplementedUsers{} }
|
|
|
|
// Close implements storage.Database.
|
|
func (*Database) Close() error { return nil }
|
|
|
|
// notImplementedSettings satisfies storage.SettingsStore by refusing every
|
|
// call, so a partially wired-up PocketBase deployment cannot silently lose
|
|
// an admin's federation switch.
|
|
type notImplementedSettings struct{}
|
|
|
|
func (notImplementedSettings) Get(context.Context, string) (string, bool, error) {
|
|
return "", false, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedSettings) GetAll(context.Context) (map[string]string, error) {
|
|
return nil, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedSettings) Set(context.Context, string, string) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedSettings) Delete(context.Context, string) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
// notImplementedUsers satisfies storage.UserStore the same way: a
|
|
// half-wired PocketBase deployment must not accept a registration it cannot
|
|
// store, or hand out an access token it cannot look up again.
|
|
type notImplementedUsers struct{}
|
|
|
|
func (notImplementedUsers) CreateAccount(context.Context, storage.NewAccount) (storage.Account, error) {
|
|
return storage.Account{}, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) Account(context.Context, string) (storage.Account, error) {
|
|
return storage.Account{}, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) PasswordHash(context.Context, string) (string, error) {
|
|
return "", storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) SetPasswordHash(context.Context, string, string) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) SetAdmin(context.Context, string, bool) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) SetDisplayName(context.Context, string, string) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) SetAvatarURL(context.Context, string, string) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) ListAccounts(context.Context, storage.AccountFilter) ([]storage.Account, int, error) {
|
|
return nil, 0, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) Stats(context.Context) (storage.Stats, error) {
|
|
return storage.Stats{}, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) CreateSession(context.Context, storage.NewSession) (storage.Device, error) {
|
|
return storage.Device{}, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) RefreshSession(context.Context, storage.RefreshedSession) (storage.TokenInfo, error) {
|
|
return storage.TokenInfo{}, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) TokenInfo(context.Context, string) (storage.TokenInfo, error) {
|
|
return storage.TokenInfo{}, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) TouchDevice(context.Context, string, string, string, string, int64) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) Device(context.Context, string, string) (storage.Device, error) {
|
|
return storage.Device{}, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) Devices(context.Context, string) ([]storage.Device, error) {
|
|
return nil, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) SetDeviceDisplayName(context.Context, string, string, string) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) DeleteDevices(context.Context, string, []string) (int, error) {
|
|
return 0, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) DeleteAllDevices(context.Context, string) (int, error) {
|
|
return 0, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) AccountData(context.Context, string, string, string) ([]byte, error) {
|
|
return nil, storage.ErrNotImplemented
|
|
}
|
|
|
|
func (notImplementedUsers) SetAccountData(context.Context, string, string, string, []byte) error {
|
|
return storage.ErrNotImplemented
|
|
}
|
|
|
|
// Compile-time proof that the stub keeps up with the interfaces.
|
|
var (
|
|
_ storage.Database = (*Database)(nil)
|
|
_ storage.UserStore = notImplementedUsers{}
|
|
)
|