-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathrunning.go
71 lines (63 loc) · 1.95 KB
/
running.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
package config
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"github.com/activecm/mgosec"
"github.com/blang/semver"
)
type (
//RunningCfg holds configuration options that are parsed at run time
RunningCfg struct {
MongoDB MongoDBRunningCfg
Version semver.Version
}
//MongoDBRunningCfg holds parsed information for connecting to MongoDB
MongoDBRunningCfg struct {
AuthMechanismParsed mgosec.AuthMechanism
TLS struct {
TLSConfig *tls.Config
}
}
)
// initRunningConfig uses data in the static config initialize
// the passed in running config
func initRunningConfig(static *StaticCfg, running *RunningCfg) error {
var err error
//parse the tls configuration
if static.MongoDB.TLS.Enabled {
tlsConf := &tls.Config{}
if !static.MongoDB.TLS.VerifyCertificate {
tlsConf.InsecureSkipVerify = true
}
if len(static.MongoDB.TLS.CAFile) > 0 {
pem, err2 := ioutil.ReadFile(static.MongoDB.TLS.CAFile)
err = err2
if err != nil {
fmt.Println("[!] Could not read MongoDB CA file")
} else {
tlsConf.RootCAs = x509.NewCertPool()
tlsConf.RootCAs.AppendCertsFromPEM(pem)
}
}
running.MongoDB.TLS.TLSConfig = tlsConf
}
//parse out the mongo authentication mechanism
authMechanism, err := mgosec.ParseAuthMechanism(
static.MongoDB.AuthMechanism,
)
if err != nil {
authMechanism = mgosec.None
fmt.Println("[!] Could not parse MongoDB authentication mechanism")
}
running.MongoDB.AuthMechanismParsed = authMechanism
running.Version, err = semver.ParseTolerant(static.Version)
if err != nil {
fmt.Println("\t[!] Version error: please ensure that you cloned the git repo and are using make to build.")
fmt.Println("\t[!] See the following resources for further information:")
fmt.Println("\t[>] https://github.com/activecm/rita-legacy/blob/master/Contributing.md#common-issues")
fmt.Println("\t[>] https://github.com/activecm/rita-legacy/blob/master/docs/Manual%20Installation.md")
}
return err
}