Add support for configuring user whitelisting
This does not do anything useful just yet. It will be hooked to access control checks later on. Wildcards are converted to regular expressions, because it was simpler to do that than to write (or include) some ugly wildcard matcher library. It also provides more flexibility, should we wish to use it later. Regular expressions should also work well performance-wise. We compile wildcards to regexes early on (during configuration processing) and fail if we detect a bad pattern. This is meant to catch various problems (typos or other mistakes) that could happen. For this to work, configuration building had to be redone, since it can now return an error. This may be useful in the future for validating other configuration settings. Related to https://gitlab.com/etke.cc/postmoogle/-/issues/1
This commit is contained in:
19
bot/bot.go
19
bot/bot.go
@@ -3,6 +3,7 @@ package bot
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sync"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
@@ -19,6 +20,7 @@ type Bot struct {
|
||||
federation bool
|
||||
prefix string
|
||||
domain string
|
||||
allowedUsers []*regexp.Regexp
|
||||
rooms sync.Map
|
||||
log *logger.Logger
|
||||
lp *linkpearl.Linkpearl
|
||||
@@ -26,15 +28,16 @@ type Bot struct {
|
||||
}
|
||||
|
||||
// New creates a new matrix bot
|
||||
func New(lp *linkpearl.Linkpearl, log *logger.Logger, prefix, domain string, noowner, federation bool) *Bot {
|
||||
func New(lp *linkpearl.Linkpearl, log *logger.Logger, prefix, domain string, noowner, federation bool, allowedUsers []*regexp.Regexp) *Bot {
|
||||
return &Bot{
|
||||
noowner: noowner,
|
||||
federation: federation,
|
||||
prefix: prefix,
|
||||
domain: domain,
|
||||
rooms: sync.Map{},
|
||||
log: log,
|
||||
lp: lp,
|
||||
noowner: noowner,
|
||||
federation: federation,
|
||||
prefix: prefix,
|
||||
domain: domain,
|
||||
allowedUsers: allowedUsers,
|
||||
rooms: sync.Map{},
|
||||
log: log,
|
||||
lp: lp,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user