-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (63 loc) · 2.25 KB
/
main.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
package main
import (
"net/http"
"os"
"github.com/FoOTOo/cf-mongodb-broker/broker"
"github.com/FoOTOo/cf-mongodb-broker/config"
"github.com/pivotal-cf/brokerapi"
"code.cloudfoundry.org/lager"
"github.com/FoOTOo/cf-mongodb-broker/mongo"
)
const (
BrokerName = "cf-mongodb-broker"
)
func main() {
brokerLogger := lager.NewLogger(BrokerName)
//brokerLogger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
brokerLogger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
brokerLogger.RegisterSink(lager.NewWriterSink(os.Stderr, lager.ERROR))
brokerLogger.Info("Starting Mongodb broker")
// Config
brokerConfigPath := configPath()
config, err := config.ParseConfig(brokerConfigPath)
if err != nil {
brokerLogger.Fatal("Loading config file", err, lager.Data{
"broker-config-path": brokerConfigPath,
})
}
//adminService, err := mongo.NewAdminService("172.16.0.156", "rootusername", "rootpassword", "admin")
adminService, err := mongo.NewAdminService(config.MongoHosts(), config.MongoUsername(), config.MongoPassword(), config.ReplSetName(), "admin")
if err != nil {
brokerLogger.Fatal("mongo-admin-service", err)
return
}
repository := mongo.NewRepository(adminService)
instanceCreator := mongo.NewInstanceCreator(adminService, repository)
instanceBinder := mongo.NewInstanceBinder(adminService, repository)
serviceBroker := &broker.MongoServiceBroker{
InstanceCreators: map[string]broker.InstanceCreator{
"standard": instanceCreator,
},
InstanceBinders: map[string]broker.InstanceBinder{
"standard": instanceBinder,
},
Config: config,
}
brokerCredentials := brokerapi.BrokerCredentials{
Username: config.BrokerConfig.BrokerUsername,
Password: config.BrokerConfig.BrokerPassword,
}
// broker
brokerAPI := brokerapi.New(serviceBroker, brokerLogger, brokerCredentials)
// authWrapper := auth.NewWrapper(brokerCredentials.Username, brokerCredentials.Password)
// TODO: ??? /instance /debug
http.Handle("/", brokerAPI)
brokerLogger.Fatal("http-listen", http.ListenAndServe(":"+"80", nil)) // TODO: ???Listening on host in config
}
func configPath() string {
brokerConfigYamlPath := os.Getenv("BROKER_CONFIG_PATH")
if brokerConfigYamlPath == "" {
panic("BROKER_CONFIG_PATH not set")
}
return brokerConfigYamlPath
}