-
Notifications
You must be signed in to change notification settings - Fork 2
/
default_manager.go
58 lines (43 loc) · 1.07 KB
/
default_manager.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
package service
import (
"errors"
"fmt"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type defaultManager struct {
services map[string]Service
}
var _ Manager = defaultManager{}
func NewDefaultManager() defaultManager {
res := defaultManager{}
res.services = map[string]Service{}
return res
}
func (f defaultManager) Add(service Service) {
f.services[service.Name()] = service
}
func (f defaultManager) Get(name string) (Service, error) {
service, ok := f.services[name]
if !ok {
return nil, fmt.Errorf("Unrecognized service type: %s", name)
}
return service, nil
}
func (f defaultManager) GetAuth() (AuthService, error) {
svc, err := f.Get("auth")
if err != nil {
return nil, bosherr.WrapError(err, "Getting auth service")
}
authSvc, ok := svc.(AuthService)
if !ok {
return nil, errors.New("Invalid authentication service configured under 'auth' service")
}
return authSvc, nil
}
func (f defaultManager) Services() []string {
services := []string{}
for name, _ := range f.services {
services = append(services, name)
}
return services
}