set default POSTMOOGLE_USERS pattern
This commit is contained in:
@@ -1,30 +1,15 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"gitlab.com/etke.cc/go/env"
|
||||
|
||||
"gitlab.com/etke.cc/postmoogle/utils"
|
||||
)
|
||||
|
||||
const prefix = "postmoogle"
|
||||
|
||||
// New config
|
||||
func New() (*Config, error) {
|
||||
func New() *Config {
|
||||
env.SetPrefix(prefix)
|
||||
|
||||
userPatterns, err := getUserRegexPatterns("users")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
adminPatterns, err := getUserRegexPatterns("admins")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
Homeserver: env.String("homeserver", defaultConfig.Homeserver),
|
||||
Login: env.String("login", defaultConfig.Login),
|
||||
@@ -35,8 +20,8 @@ func New() (*Config, error) {
|
||||
NoEncryption: env.Bool("noencryption"),
|
||||
MaxSize: env.Int("maxsize", defaultConfig.MaxSize),
|
||||
StatusMsg: env.String("statusmsg", defaultConfig.StatusMsg),
|
||||
Users: userPatterns,
|
||||
Admins: adminPatterns,
|
||||
Users: env.Slice("users"),
|
||||
Admins: env.Slice("admins"),
|
||||
Sentry: Sentry{
|
||||
DSN: env.String("sentry.dsn", defaultConfig.Sentry.DSN),
|
||||
},
|
||||
@@ -47,19 +32,5 @@ func New() (*Config, error) {
|
||||
},
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func getUserRegexPatterns(key string) ([]*regexp.Regexp, error) {
|
||||
mxidPatterns := env.Slice(key)
|
||||
regexPatterns, err := utils.WildcardMXIDsToRegexes(mxidPatterns)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"failed to convert wildcard %s patterns (`%s`) to regular expression: %s",
|
||||
key,
|
||||
mxidPatterns,
|
||||
err,
|
||||
)
|
||||
}
|
||||
return regexPatterns, nil
|
||||
return cfg
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package config
|
||||
|
||||
import "regexp"
|
||||
|
||||
// Config of Postmoogle
|
||||
type Config struct {
|
||||
// Homeserver url
|
||||
@@ -24,10 +22,10 @@ type Config struct {
|
||||
MaxSize int
|
||||
// StatusMsg of the bot
|
||||
StatusMsg string
|
||||
// Users holds list of allowed users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = *
|
||||
Users []*regexp.Regexp
|
||||
// Admins holds list of admin users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = *
|
||||
Admins []*regexp.Regexp
|
||||
// Users holds list of allowed users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = homeserver only
|
||||
Users []string
|
||||
// Admins holds list of admin users (wildcards supported), e.g.: @*:example.com, @bot.*:example.com, @admin:*. Empty = no admins
|
||||
Admins []string
|
||||
|
||||
// DB config
|
||||
DB DB
|
||||
|
||||
Reference in New Issue
Block a user