-
Notifications
You must be signed in to change notification settings - Fork 2
/
service_factory.go
40 lines (30 loc) · 904 Bytes
/
service_factory.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
package server
import (
"time"
"github.com/pkg/errors"
"github.com/dpb587/ssoca/certauth"
"github.com/dpb587/ssoca/config"
"github.com/dpb587/ssoca/server/service"
svc "github.com/dpb587/ssoca/service/openvpn"
svcconfig "github.com/dpb587/ssoca/service/openvpn/server/config"
)
type ServiceFactory struct {
svc.ServiceType
caManager certauth.Manager
}
var _ service.ServiceFactory = ServiceFactory{}
func NewServiceFactory(caManager certauth.Manager) ServiceFactory {
return ServiceFactory{
caManager: caManager,
}
}
func (f ServiceFactory) Create(name string, options map[string]interface{}) (service.Service, error) {
var cfg svcconfig.Config
cfg.CertAuth = certauth.NewConfigValue(f.caManager)
cfg.Validity = 2 * time.Minute
err := config.RemarshalYAML(options, &cfg)
if err != nil {
return nil, errors.Wrap(err, "loading config")
}
return NewService(name, cfg), nil
}