/
service_factory.go
38 lines (29 loc) · 984 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
package server
import (
"github.com/pkg/errors"
"github.com/dpb587/ssoca/config"
serverconfig "github.com/dpb587/ssoca/server/config"
"github.com/dpb587/ssoca/server/service"
svc "github.com/dpb587/ssoca/service/githubauth"
svcconfig "github.com/dpb587/ssoca/service/githubauth/server/config"
)
type ServiceFactory struct {
svc.ServiceType
endpointURL string
redirects serverconfig.ServerRedirectConfig
}
func NewServiceFactory(endpointURL string, redirects serverconfig.ServerRedirectConfig) ServiceFactory {
return ServiceFactory{
endpointURL: endpointURL,
redirects: redirects,
}
}
func (f ServiceFactory) Create(name string, options map[string]interface{}) (service.Service, error) {
var cfg svcconfig.Config
err := config.RemarshalYAML(options, &cfg)
if err != nil {
return nil, errors.Wrap(err, "loading config")
}
cfg.ApplyRedirectDefaults(f.redirects.AuthSuccess, f.redirects.AuthFailure)
return NewService(name, f.endpointURL, cfg), nil
}