mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2,federation,mediaproxy: enable http access logging
This commit is contained in:
parent
26e66f293e
commit
b4c7abd62b
4 changed files with 33 additions and 10 deletions
|
|
@ -39,7 +39,7 @@ func (br *Connector) initDirectMedia() error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize media proxy: %w", err)
|
||||
}
|
||||
br.MediaProxy.RegisterRoutes(br.AS.Router)
|
||||
br.MediaProxy.RegisterRoutes(br.AS.Router, br.Log.With().Str("component", "media proxy").Logger())
|
||||
br.dmaSigKey = sha256.Sum256(br.MediaProxy.GetServerKey().Priv.Seed())
|
||||
dmn.SetUseDirectMedia()
|
||||
br.Log.Debug().Str("server_name", br.MediaProxy.GetServerName()).Msg("Enabled direct media access")
|
||||
|
|
|
|||
|
|
@ -20,9 +20,11 @@ import (
|
|||
"github.com/rs/xid"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"go.mau.fi/util/exerrors"
|
||||
"go.mau.fi/util/exhttp"
|
||||
"go.mau.fi/util/exstrings"
|
||||
"go.mau.fi/util/jsontime"
|
||||
"go.mau.fi/util/ptr"
|
||||
"go.mau.fi/util/requestlog"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
|
|
@ -146,10 +148,15 @@ func (prov *ProvisioningAPI) Init() {
|
|||
debugRouter,
|
||||
exhttp.StripPrefix("/debug"),
|
||||
hlog.NewHandler(prov.br.Log.With().Str("component", "debug api").Logger()),
|
||||
requestlog.AccessLogger(requestlog.Options{TrustXForwardedFor: true}),
|
||||
prov.DebugAuthMiddleware,
|
||||
))
|
||||
}
|
||||
|
||||
errorBodies := exhttp.ErrorBodies{
|
||||
NotFound: exerrors.Must(ptr.Ptr(mautrix.MUnrecognized.WithMessage("Unrecognized endpoint")).MarshalJSON()),
|
||||
MethodNotAllowed: exerrors.Must(ptr.Ptr(mautrix.MUnrecognized.WithMessage("Invalid method for endpoint")).MarshalJSON()),
|
||||
}
|
||||
prov.br.AS.Router.Handle("/_matrix/provision/", exhttp.ApplyMiddleware(
|
||||
prov.Router,
|
||||
exhttp.StripPrefix("/_matrix/provision"),
|
||||
|
|
@ -157,6 +164,7 @@ func (prov *ProvisioningAPI) Init() {
|
|||
hlog.RequestIDHandler("request_id", "Request-Id"),
|
||||
exhttp.CORSMiddleware,
|
||||
requestlog.AccessLogger(requestlog.Options{TrustXForwardedFor: true}),
|
||||
exhttp.HandleErrors(errorBodies),
|
||||
prov.AuthMiddleware,
|
||||
))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,13 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"go.mau.fi/util/exerrors"
|
||||
"go.mau.fi/util/exhttp"
|
||||
"go.mau.fi/util/jsontime"
|
||||
"go.mau.fi/util/ptr"
|
||||
"go.mau.fi/util/requestlog"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
|
@ -51,7 +55,7 @@ type KeyServer struct {
|
|||
}
|
||||
|
||||
// Register registers the key server endpoints to the given router.
|
||||
func (ks *KeyServer) Register(r *http.ServeMux) {
|
||||
func (ks *KeyServer) Register(r *http.ServeMux, log zerolog.Logger) {
|
||||
r.HandleFunc("GET /.well-known/matrix/server", ks.GetWellKnown)
|
||||
r.HandleFunc("GET /_matrix/federation/v1/version", ks.GetServerVersion)
|
||||
keyRouter := http.NewServeMux()
|
||||
|
|
@ -59,12 +63,15 @@ func (ks *KeyServer) Register(r *http.ServeMux) {
|
|||
keyRouter.HandleFunc("GET /v2/query/{serverName}", ks.GetQueryKeys)
|
||||
keyRouter.HandleFunc("POST /v2/query", ks.PostQueryKeys)
|
||||
errorBodies := exhttp.ErrorBodies{
|
||||
NotFound: exerrors.Must(json.Marshal(mautrix.MUnrecognized.WithMessage("Unrecognized endpoint"))),
|
||||
MethodNotAllowed: exerrors.Must(json.Marshal(mautrix.MUnrecognized.WithMessage("Invalid method for endpoint"))),
|
||||
NotFound: exerrors.Must(ptr.Ptr(mautrix.MUnrecognized.WithMessage("Unrecognized endpoint")).MarshalJSON()),
|
||||
MethodNotAllowed: exerrors.Must(ptr.Ptr(mautrix.MUnrecognized.WithMessage("Invalid method for endpoint")).MarshalJSON()),
|
||||
}
|
||||
r.Handle("/_matrix/key/", exhttp.ApplyMiddleware(
|
||||
keyRouter,
|
||||
exhttp.StripPrefix("/_matrix/key"),
|
||||
hlog.NewHandler(log),
|
||||
hlog.RequestIDHandler("request_id", "Request-Id"),
|
||||
requestlog.AccessLogger(requestlog.Options{TrustXForwardedFor: true}),
|
||||
exhttp.HandleErrors(errorBodies),
|
||||
))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ package mediaproxy
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
|
@ -23,8 +22,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
"go.mau.fi/util/exerrors"
|
||||
"go.mau.fi/util/exhttp"
|
||||
"go.mau.fi/util/ptr"
|
||||
"go.mau.fi/util/requestlog"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/federation"
|
||||
|
|
@ -178,7 +180,7 @@ type ServerConfig struct {
|
|||
|
||||
func (mp *MediaProxy) Listen(cfg ServerConfig) error {
|
||||
router := http.NewServeMux()
|
||||
mp.RegisterRoutes(router)
|
||||
mp.RegisterRoutes(router, zerolog.Nop())
|
||||
return http.ListenAndServe(fmt.Sprintf("%s:%d", cfg.Hostname, cfg.Port), router)
|
||||
}
|
||||
|
||||
|
|
@ -203,23 +205,29 @@ func (mp *MediaProxy) EnableServerAuth(client *federation.Client, keyCache feder
|
|||
})
|
||||
}
|
||||
|
||||
func (mp *MediaProxy) RegisterRoutes(router *http.ServeMux) {
|
||||
func (mp *MediaProxy) RegisterRoutes(router *http.ServeMux, log zerolog.Logger) {
|
||||
errorBodies := exhttp.ErrorBodies{
|
||||
NotFound: exerrors.Must(json.Marshal(mautrix.MUnrecognized.WithMessage("Unrecognized endpoint"))),
|
||||
MethodNotAllowed: exerrors.Must(json.Marshal(mautrix.MUnrecognized.WithMessage("Invalid method for endpoint"))),
|
||||
NotFound: exerrors.Must(ptr.Ptr(mautrix.MUnrecognized.WithMessage("Unrecognized endpoint")).MarshalJSON()),
|
||||
MethodNotAllowed: exerrors.Must(ptr.Ptr(mautrix.MUnrecognized.WithMessage("Invalid method for endpoint")).MarshalJSON()),
|
||||
}
|
||||
router.Handle("/_matrix/federation/", exhttp.ApplyMiddleware(
|
||||
mp.FederationRouter,
|
||||
exhttp.StripPrefix("/_matrix/federation"),
|
||||
hlog.NewHandler(log),
|
||||
hlog.RequestIDHandler("request_id", "Request-Id"),
|
||||
requestlog.AccessLogger(requestlog.Options{TrustXForwardedFor: true}),
|
||||
exhttp.HandleErrors(errorBodies),
|
||||
))
|
||||
router.Handle("/_matrix/client/v1/media/", exhttp.ApplyMiddleware(
|
||||
mp.ClientMediaRouter,
|
||||
exhttp.StripPrefix("/_matrix/client/v1/media"),
|
||||
hlog.NewHandler(log),
|
||||
hlog.RequestIDHandler("request_id", "Request-Id"),
|
||||
exhttp.CORSMiddleware,
|
||||
requestlog.AccessLogger(requestlog.Options{TrustXForwardedFor: true}),
|
||||
exhttp.HandleErrors(errorBodies),
|
||||
))
|
||||
mp.KeyServer.Register(router)
|
||||
mp.KeyServer.Register(router, log)
|
||||
}
|
||||
|
||||
var ErrInvalidMediaIDSyntax = errors.New("invalid media ID syntax")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue