diff --git a/go.mod b/go.mod index c388797d..4294fc24 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module go.mau.fi/mautrix-signal go 1.20 require ( + github.com/beeper/libserv v0.0.0-20231227020056-a328525edf81 github.com/google/uuid v1.5.0 github.com/gorilla/mux v1.8.0 github.com/lib/pq v1.10.9 @@ -40,6 +41,7 @@ require ( github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.11.1 // indirect + github.com/rs/xid v1.5.0 // indirect github.com/tidwall/gjson v1.17.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect diff --git a/go.sum b/go.sum index 54efb039..1194d0e3 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= +github.com/beeper/libserv v0.0.0-20231227020056-a328525edf81 h1:cJxudtYacDvDlf/QmLntrYVRpjeG9m6Z4WbULWhq+AY= +github.com/beeper/libserv v0.0.0-20231227020056-a328525edf81/go.mod h1:zekSFC1TjpRSe85AbIRRXxLsNW22df/MgjLqXVGaO1U= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= @@ -49,6 +51,7 @@ github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI= github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= diff --git a/provisioning.go b/provisioning.go index ae995c93..3218702c 100644 --- a/provisioning.go +++ b/provisioning.go @@ -30,8 +30,10 @@ import ( "sync" "time" + "github.com/beeper/libserv/pkg/requestlog" "github.com/gorilla/mux" "github.com/rs/zerolog" + "github.com/rs/zerolog/hlog" "maunium.net/go/mautrix/id" "go.mau.fi/mautrix-signal/pkg/signalmeow" @@ -53,10 +55,12 @@ type ProvisioningAPI struct { } func (prov *ProvisioningAPI) Init() { - prov.log.Debug().Msgf("Enabling provisioning API at %v", prov.bridge.Config.Bridge.Provisioning.Prefix) + prov.log.Debug().Str("prefix", prov.bridge.Config.Bridge.Provisioning.Prefix).Msg("Enabling provisioning API") prov.provisioningUsers = make(map[string]int) prov.provisioningMutexes = make(map[string]*sync.Mutex) r := prov.bridge.AS.Router.PathPrefix(prov.bridge.Config.Bridge.Provisioning.Prefix).Subrouter() + r.Use(hlog.NewHandler(prov.log)) + r.Use(requestlog.AccessLogger(true)) r.Use(prov.AuthMiddleware) r.HandleFunc("/v2/link/new", prov.LinkNew).Methods(http.MethodPost) r.HandleFunc("/v2/link/wait/scan", prov.LinkWaitForScan).Methods(http.MethodPost) @@ -115,11 +119,8 @@ func (prov *ProvisioningAPI) AuthMiddleware(h http.Handler) http.Handler { } userID := r.URL.Query().Get("user_id") user := prov.bridge.GetUserByMXID(id.UserID(userID)) - start := time.Now() wWrap := &responseWrap{w, 200} h.ServeHTTP(wWrap, r.WithContext(context.WithValue(r.Context(), "user", user))) - duration := time.Now().Sub(start).Seconds() - prov.log.Info().Msgf("%s %s from %s took %.2f seconds and returned status %d", r.Method, r.URL.Path, user.MXID, duration, wWrap.statusCode) }) }