feat: add DB flags, fix presence config, switch basicauth to map

This commit is contained in:
Victor Lacasse-Beaudoin 2025-05-13 16:15:05 -04:00
parent 2dcf0ec867
commit 940c6d8a25
4 changed files with 98 additions and 30 deletions

View file

@ -41,19 +41,19 @@ func RunUIServer(ctx context.Context, cfg Config, bottinClient *bottin.APIClient
e.Pre(middleware.AddTrailingSlash())
// basic auth
if cfg.UI.Username == "" || cfg.UI.Password == "" {
return fmt.Errorf("UI username and password cannot be empty, please set UI.Password and UI.Username (PRESENCES_UI_PASSWORD and PRESENCES_UI_USERNAME")
if len(cfg.UI.Credentials) == 0 {
return fmt.Errorf("UI.Credentials config file option of type map[string]string must contain at least one username-password key-value pair. Note that there is no flag or ENV counterpart, this must be done through a config file.")
}
e.Pre(middleware.BasicAuth(
func(username, password string, c echo.Context) (bool, error) {
userOK := subtle.ConstantTimeCompare([]byte(username), []byte(cfg.UI.Username)) == 1
passOK := subtle.ConstantTimeCompare([]byte(password), []byte(cfg.UI.Password)) == 1
if userOK && passOK {
return true, nil
rightPassword, userExists := cfg.UI.Credentials[username]
if !userExists {
return false, nil
}
return false, nil
passwordOK := subtle.ConstantTimeCompare([]byte(password), []byte(rightPassword)) == 1
return passwordOK, nil
}),
)