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 9. internal/appservice reads registration files (appservice.config_files), matches namespaces the way Synapse does (anchored at the start), and delivers events to each service as transactions read from the roomserver's event stream at a cursor kept in appservice_state. A transaction in flight is recorded, so after a restart it is resent under the same ID; failures back off from 2s to 5m, and a successful ping cuts the backoff short. In the Client-Server API an as_token acts as the service's sender or, with ?user_id=, as any existing user in its namespace. Services register and log in their users with m.login.application_service; exclusive user and alias namespaces are refused to everybody else with M_EXCLUSIVE. Unknown aliases and users in a namespace are asked of the service first. The ping endpoint reports M_URL_NOT_SET, M_BAD_STATUS, M_CONNECTION_FAILED and M_CONNECTION_TIMEOUT. Services' own requests, and their users' when rate_limited is false, skip the rate limiter. Users can change their password (POST /account/password) and deactivate their account (POST /account/deactivate), both behind the password. Deactivation revokes tokens, deletes devices, optionally erases the profile and leaves every room through a new userapi.AccountObserver. The admin API is complete: user detail, the admin flag, deactivation and reactivation, password resets, devices, media quotas (media.max_user_storage_bytes plus per-user overrides), registration tokens with use limits and expiry (registration.require_token), server notices (internal/servernotices, server_notices.*), an editor for the federation allow/deny lists persisted in server_settings, a delivery view of the application services, and an audit log of every change. Migration 0011 adds the registration token, server notice room, media quota, audit log and appservice cursor tables. Policy lists are now returned sorted. The Complement entrypoint loads the registrations Complement mounts in /complement/appservice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
3.3 KiB
Go
97 lines
3.3 KiB
Go
package adminapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/dariuszjaniak/warp/server/internal/appservice"
|
|
"github.com/dariuszjaniak/warp/server/internal/httputil"
|
|
"github.com/dariuszjaniak/warp/server/internal/userapi"
|
|
)
|
|
|
|
// appServiceNamespace is one namespace in the status view.
|
|
type appServiceNamespace struct {
|
|
Regex string `json:"regex"`
|
|
Exclusive bool `json:"exclusive"`
|
|
}
|
|
|
|
// appServiceDelivery is a service's delivery health. It is absent for a
|
|
// service without a URL, which is sent nothing.
|
|
type appServiceDelivery struct {
|
|
StreamPos int64 `json:"stream_pos"`
|
|
Behind int64 `json:"behind"`
|
|
TxnID int64 `json:"txn_id"`
|
|
EventsDelivered int64 `json:"events_delivered"`
|
|
Failures int `json:"failures"`
|
|
LastError string `json:"last_error,omitempty"`
|
|
LastSuccessMS int64 `json:"last_success_ms"`
|
|
LastFailureMS int64 `json:"last_failure_ms"`
|
|
RetryAtMS int64 `json:"retry_at_ms"`
|
|
}
|
|
|
|
// appServiceResponse is one service in GET /appservices.
|
|
type appServiceResponse struct {
|
|
ID string `json:"id"`
|
|
URL string `json:"url,omitempty"`
|
|
Sender string `json:"sender"`
|
|
RateLimited bool `json:"rate_limited"`
|
|
Protocols []string `json:"protocols"`
|
|
Namespaces map[string][]appServiceNamespace `json:"namespaces"`
|
|
Delivery *appServiceDelivery `json:"delivery,omitempty"`
|
|
}
|
|
|
|
// handleGetAppServices implements GET /_warp/admin/v1/appservices: what is
|
|
// registered, and how delivery to each is going. Registrations are read
|
|
// from files at startup, so this is a view, not an editor; the tokens are
|
|
// never shown.
|
|
func (a *AdminAPI) handleGetAppServices(w http.ResponseWriter, r *http.Request, _ userapi.Authenticated) error {
|
|
var top int64
|
|
if a.rooms != nil {
|
|
var err error
|
|
if top, err = a.rooms.StreamTop(r.Context()); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
statuses := map[string]appServiceDelivery{}
|
|
for _, s := range a.appservices.Statuses() {
|
|
statuses[s.ID] = appServiceDelivery{
|
|
StreamPos: s.StreamPos, Behind: max(top-s.StreamPos, 0), TxnID: s.TxnID,
|
|
EventsDelivered: s.EventsDelivered, Failures: s.Failures, LastError: s.LastError,
|
|
LastSuccessMS: s.LastSuccessMS, LastFailureMS: s.LastFailureMS, RetryAtMS: s.RetryAtMS,
|
|
}
|
|
}
|
|
|
|
out := []appServiceResponse{}
|
|
for _, svc := range a.appservices.Registry().Services() {
|
|
resp := appServiceResponse{
|
|
ID: svc.ID,
|
|
URL: svc.URL,
|
|
Sender: svc.SenderUserID(),
|
|
RateLimited: svc.RateLimitedUsers(),
|
|
Protocols: svc.Protocols,
|
|
Namespaces: map[string][]appServiceNamespace{
|
|
"users": namespacesOf(svc.Namespaces.Users),
|
|
"aliases": namespacesOf(svc.Namespaces.Aliases),
|
|
"rooms": namespacesOf(svc.Namespaces.Rooms),
|
|
},
|
|
}
|
|
if resp.Protocols == nil {
|
|
resp.Protocols = []string{}
|
|
}
|
|
if d, ok := statuses[svc.ID]; ok {
|
|
resp.Delivery = &d
|
|
}
|
|
out = append(out, resp)
|
|
}
|
|
httputil.NoCache(w)
|
|
httputil.WriteJSON(w, http.StatusOK, map[string]any{"appservices": out})
|
|
return nil
|
|
}
|
|
|
|
func namespacesOf(list []appservice.Namespace) []appServiceNamespace {
|
|
out := make([]appServiceNamespace, 0, len(list))
|
|
for _, ns := range list {
|
|
out = append(out, appServiceNamespace{Regex: ns.Regex, Exclusive: ns.Exclusive})
|
|
}
|
|
return out
|
|
}
|