forked from tolsen/mongonet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
87 lines (75 loc) · 2.07 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
81
82
83
84
85
86
87
package mongonet
import (
"crypto/x509"
"fmt"
"github.com/mongodb/mongonet/util"
"github.com/mongodb/slogger/v2/slogger"
)
type SSLPair struct {
Cert string `json:"cert"`
Key string `json:"key"`
Id string
}
// driver defaults
const (
DefaultMaxPoolSize = 100
DefaultMaxPoolIdleTimeSec = 0
DefaultConnectionPoolHeartbeatIntervalMs = 0
)
type ProxyConfig struct {
ServerConfig
MongoURI string
MongoHost string
MongoPort int
MongoSSL bool
MongoRootCAs *x509.CertPool
MongoSSLSkipVerify bool
MongoUser string
MongoPassword string
InterceptorFactory ProxyInterceptorFactory
CollectorHookFactory MetricsHookFactory
AppName string
TraceConnPool bool
ConnectionMode util.MongoConnectionMode
ServerSelectionTimeoutSec int
MaxPoolSize int
MaxPoolIdleTimeSec int
ConnectionPoolHeartbeatIntervalMs int
}
func NewProxyConfig(bindHost string, bindPort int, mongoUri, mongoHost string, mongoPort int, mongoUser, mongoPassword, appName string, traceConnPool bool, connectionMode util.MongoConnectionMode, serverSelectionTimeoutSec, maxPoolSize, maxPoolIdleTimeSec, connectionPoolHeartbeatIntervalMs int) ProxyConfig {
syncTlsConfig := NewSyncTlsConfig()
return ProxyConfig{
ServerConfig{
bindHost,
bindPort,
false, // UseSSL
nil, // SSLKeys
syncTlsConfig,
0, // MinTlsVersion
0, // TCPKeepAlivePeriod
nil, // CipherSuites
slogger.OFF, // LogLevel
nil, // Appenders
},
mongoUri,
mongoHost,
mongoPort,
false, // MongoSSL
nil, // MongoRootCAs
false, // MongoSSLSkipVerify
mongoUser,
mongoPassword,
nil, // InterceptorFactory
nil, // CollectorHookFactory
appName,
traceConnPool,
connectionMode,
serverSelectionTimeoutSec,
maxPoolSize,
maxPoolIdleTimeSec,
connectionPoolHeartbeatIntervalMs,
}
}
func (pc *ProxyConfig) MongoAddress() string {
return fmt.Sprintf("%s:%d", pc.MongoHost, pc.MongoPort)
}