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:
Slavi Pantaleev
2022-08-26 09:38:36 +03:00
parent 9484758f33
commit 8ad2e29930
7 changed files with 336 additions and 12 deletions

View File

@@ -26,7 +26,13 @@ var (
func main() {
quit := make(chan struct{})
cfg := config.New()
cfg, err := config.New()
if err != nil {
log = logger.New("postmoogle.", "info")
log.Fatal("%s", err)
}
log = logger.New("postmoogle.", cfg.LogLevel)
log.Info("#############################")
@@ -81,7 +87,7 @@ func initBot(cfg *config.Config) {
// nolint // Fatal = panic, not os.Exit()
log.Fatal("cannot initialize matrix bot: %v", err)
}
mxb = bot.New(lp, mxlog, cfg.Prefix, cfg.Domain, cfg.NoOwner, cfg.Federation)
mxb = bot.New(lp, mxlog, cfg.Prefix, cfg.Domain, cfg.NoOwner, cfg.Federation, cfg.Users)
log.Debug("bot has been created")
}