Remove accounts from config file; add log level

This commit is contained in:
Alex 2020-02-27 10:44:28 +01:00
parent 7fa2842f5d
commit be9278ab02

28
main.go
View file

@ -5,12 +5,8 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"flag" "flag"
"fmt"
_ "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
_ "strings"
_ "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -18,12 +14,8 @@ import (
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib" "git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
) )
type ConfigAccount struct {
Protocol string `json:"protocol"`
Config map[string]string `json:"config"`
}
type ConfigFile struct { type ConfigFile struct {
LogLevel string `json:"log_level"`
ASBindAddr string `json:"appservice_bind_addr"` ASBindAddr string `json:"appservice_bind_addr"`
WebBindAddr string `json:"web_bind_addr"` WebBindAddr string `json:"web_bind_addr"`
Registration string `json:"registration"` Registration string `json:"registration"`
@ -31,7 +23,6 @@ type ConfigFile struct {
DbType string `json:"db_type"` DbType string `json:"db_type"`
DbPath string `json:"db_path"` DbPath string `json:"db_path"`
MatrixDomain string `json:"matrix_domain"` MatrixDomain string `json:"matrix_domain"`
Accounts map[string]map[string]ConfigAccount `json:"accounts"`
} }
var configFlag = flag.String("config", "./config.json", "Configuration file path") var configFlag = flag.String("config", "./config.json", "Configuration file path")
@ -41,13 +32,13 @@ var registration *mxlib.Registration
func readConfig() ConfigFile { func readConfig() ConfigFile {
config_file := ConfigFile{ config_file := ConfigFile{
LogLevel: "info",
ASBindAddr: "0.0.0.0:8321", ASBindAddr: "0.0.0.0:8321",
WebBindAddr: "0.0.0.0:8281", WebBindAddr: "0.0.0.0:8281",
Registration: "./registration.yaml", Registration: "./registration.yaml",
Server: "http://localhost:8008", Server: "http://localhost:8008",
DbType: "sqlite3", DbType: "sqlite3",
DbPath: "easybridge.db", DbPath: "easybridge.db",
Accounts: map[string]map[string]ConfigAccount{},
} }
_, err := os.Stat(*configFlag) _, err := os.Stat(*configFlag)
@ -152,13 +143,17 @@ func readRegistration(file string) mxlib.Registration {
} }
func main() { func main() {
log.SetLevel(log.DebugLevel)
flag.Parse() flag.Parse()
config_file := readConfig() config_file := readConfig()
config = &config_file config = &config_file
log_level, err := log.ParseLevel(config.LogLevel)
if err != nil {
log.Fatal(err)
}
log.SetLevel(log_level)
reg_file := readRegistration(config.Registration) reg_file := readRegistration(config.Registration)
registration = &reg_file registration = &reg_file
@ -169,13 +164,6 @@ func main() {
StartWeb() StartWeb()
for user, accounts := range config.Accounts {
mxid := fmt.Sprintf("@%s:%s", user, config.MatrixDomain)
for name, params := range accounts {
SetAccount(mxid, name, params.Protocol, params.Config)
}
}
err = <-errch err = <-errch
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)