-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
80 lines (65 loc) · 1.84 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package linkpearl
import (
"context"
"crypto/hmac"
"crypto/sha512"
"database/sql"
"encoding/hex"
"github.com/rs/zerolog"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
)
// Config represents matrix config
type Config struct {
// Homeserver url
Homeserver string
// Login is a localpart for password auth or full mxid for shared secret auth (honoroit - for password, @honoroit:example.com - for shared secret)
Login string
// Password for login/password auth only
Password string
// Shared secret for login/sharedsecret auth only
SharedSecret string
// JoinPermit is a callback function that tells
// if linkpearl should respond to the given "invite" event
// and join the room
JoinPermit func(context.Context, *event.Event) bool
// AutoLeave if true, linkpearl will automatically leave empty rooms
AutoLeave bool
// AccountDataCache size
AccountDataCache int
// AccountDataSecret (Password) for encryption
AccountDataSecret string
// MaxRetries for operations like auto join
MaxRetries int
// EventsLimit for methods like lp.Threads() or lp.FindEventBy()
EventsLimit int
// UserAgent for requests
UserAgent string
// Logger
Logger zerolog.Logger
// DB object
DB *sql.DB
// Dialect of the DB: postgres, sqlite3
Dialect string
}
// LoginAs for cryptohelper
func (cfg *Config) LoginAs() *mautrix.ReqLogin {
loginReq := mautrix.ReqLogin{
Identifier: mautrix.UserIdentifier{
Type: mautrix.IdentifierTypeUser,
User: cfg.Login,
},
StoreCredentials: true,
StoreHomeserverURL: true,
}
if cfg.SharedSecret != "" {
loginReq.Type = mautrix.AuthTypeDevtureSharedSecret
mac := hmac.New(sha512.New, []byte(cfg.SharedSecret))
mac.Write([]byte(cfg.Login))
loginReq.Token = hex.EncodeToString(mac.Sum(nil))
} else {
loginReq.Type = mautrix.AuthTypePassword
loginReq.Password = cfg.Password
}
return &loginReq
}