-
Notifications
You must be signed in to change notification settings - Fork 928
/
brokers.go
42 lines (35 loc) · 1 KB
/
brokers.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
package store
import (
"code.cloudfoundry.org/cli/integration/assets/hydrabroker/config"
"code.cloudfoundry.org/cli/integration/assets/hydrabroker/database"
)
func (st *Store) CreateBroker(cfg config.BrokerConfiguration) BrokerID {
id := database.NewID()
st.db.Create(id, cfg)
return BrokerID(id)
}
func (st *Store) RetrieveBroker(id BrokerID) (config.BrokerConfiguration, bool) {
if cfg, ok := st.db.Retrieve(database.ID(id)); ok {
return cfg.(config.BrokerConfiguration), true
}
return config.BrokerConfiguration{}, false
}
func (st *Store) UpdateBroker(id BrokerID, cfg config.BrokerConfiguration) {
st.db.Update(database.ID(id), cfg)
}
func (st *Store) DeleteBroker(id BrokerID) {
st.db.Delete(database.ID(id))
}
func (st *Store) ListBrokers() []BrokerID {
var brokers []BrokerID
for _, id := range st.db.List() {
if cfg, ok := st.db.Retrieve(id); ok {
switch cfg.(type) {
case config.BrokerConfiguration:
brokers = append(brokers, BrokerID(id))
default:
}
}
}
return brokers
}