mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 17:33:09 -06:00
Compile room and alias namespace regexs
We'll be needing these for event filtering in the appservice component. Signed-off-by: Andrew Morgan <andrewm@matrix.org>
This commit is contained in:
parent
ed388a32b7
commit
3d8de687e3
|
|
@ -17,6 +17,7 @@ package consumers
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
|
|
@ -85,6 +86,7 @@ func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
ev := output.NewRoomEvent.Event
|
ev := output.NewRoomEvent.Event
|
||||||
|
fmt.Println("got event", ev)
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"event_id": ev.EventID(),
|
"event_id": ev.EventID(),
|
||||||
"room_id": ev.RoomID(),
|
"room_id": ev.RoomID(),
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ package consumers
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
|
|
@ -85,6 +86,7 @@ func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
ev := output.NewRoomEvent.Event
|
ev := output.NewRoomEvent.Event
|
||||||
|
fmt.Println("ClientAPI got an event:", ev)
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"event_id": ev.EventID(),
|
"event_id": ev.EventID(),
|
||||||
"room_id": ev.RoomID(),
|
"room_id": ev.RoomID(),
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,8 @@ type ApplicationService struct {
|
||||||
HSToken string `yaml:"hs_token"`
|
HSToken string `yaml:"hs_token"`
|
||||||
// Localpart of application service user
|
// Localpart of application service user
|
||||||
SenderLocalpart string `yaml:"sender_localpart"`
|
SenderLocalpart string `yaml:"sender_localpart"`
|
||||||
// Information about an application service's namespaces
|
// Information about an application service's namespaces. Key is either
|
||||||
|
// "users", "aliases" or "rooms"
|
||||||
NamespaceMap map[string][]ApplicationServiceNamespace `yaml:"namespaces"`
|
NamespaceMap map[string][]ApplicationServiceNamespace `yaml:"namespaces"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,21 +113,28 @@ func setupRegexps(cfg *Dendrite) {
|
||||||
// Later we can check if a username or some other string matches any exclusive
|
// Later we can check if a username or some other string matches any exclusive
|
||||||
// regex and deny access if it isn't from an application service
|
// regex and deny access if it isn't from an application service
|
||||||
exclusiveUsernames := strings.Join(exclusiveUsernameStrings, "|")
|
exclusiveUsernames := strings.Join(exclusiveUsernameStrings, "|")
|
||||||
|
exclusiveAliases := strings.Join(exclusiveAliasStrings, "|")
|
||||||
|
exclusiveRooms := strings.Join(exclusiveRoomStrings, "|")
|
||||||
|
|
||||||
// If there are no exclusive username regexes, compile string so that it
|
// If there are no exclusive regexes, compile string so that it will not match
|
||||||
// will not match any valid usernames
|
// any valid usernames/aliases/roomIDs
|
||||||
if exclusiveUsernames == "" {
|
if exclusiveUsernames == "" {
|
||||||
exclusiveUsernames = "^$"
|
exclusiveUsernames = "^$"
|
||||||
}
|
}
|
||||||
|
if exclusiveAliases == "" {
|
||||||
|
exclusiveAliases = "^$"
|
||||||
|
}
|
||||||
|
if exclusiveRooms == "" {
|
||||||
|
exclusiveRooms = "^$"
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Aliases and rooms. Needed?
|
// Store compiled Regex
|
||||||
//exclusiveAliases := strings.Join(exclusiveAliasStrings, "|")
|
|
||||||
//exclusiveRooms := strings.Join(exclusiveRoomStrings, "|")
|
|
||||||
|
|
||||||
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveUsernames)
|
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveUsernames)
|
||||||
|
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveAliases)
|
||||||
|
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveRooms)
|
||||||
}
|
}
|
||||||
|
|
||||||
// concatenateExclusiveNamespaces takes a slice of strings and a slice of
|
// appendExclusiveNamespaceRegexs takes a slice of strings and a slice of
|
||||||
// namespaces and will append the regexes of only the exclusive namespaces
|
// namespaces and will append the regexes of only the exclusive namespaces
|
||||||
// into the string slice
|
// into the string slice
|
||||||
func appendExclusiveNamespaceRegexs(
|
func appendExclusiveNamespaceRegexs(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue