-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
75 lines (62 loc) · 1.95 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
//go:generate goagen bootstrap -d github.com/Microkubes/identity-provider/design
package main
import (
"net/http"
"os"
"github.com/Microkubes/identity-provider/app"
"github.com/Microkubes/identity-provider/config"
"github.com/Microkubes/identity-provider/db"
jormungandrSamlIdp "github.com/Microkubes/identity-provider/samlidp"
"github.com/Microkubes/microservice-tools/gateway"
"github.com/keitaroinc/goa"
"github.com/keitaroinc/goa/middleware"
)
func main() {
// Create service
service := goa.New("identity-provider")
cf := os.Getenv("SERVICE_CONFIG_FILE")
if cf == "" {
cf = "/run/secrets/microservice_identity_provider_config.json"
}
cfg, err := config.LoadConfig(cf)
if err != nil {
service.LogError("config", "err", err)
return
}
registration := gateway.NewKongGateway(cfg.GatewayAdminURL, &http.Client{}, &cfg.Microservice)
err = registration.SelfRegister()
if err != nil {
panic(err)
}
defer registration.Unregister() // defer the unregister for after main exits
// Mount middleware
service.Use(middleware.RequestID())
service.Use(middleware.LogRequest(true))
service.Use(middleware.ErrorHandler(service, true))
service.Use(middleware.Recover())
// Cretae IDP store
store, cleanup, err := db.NewIDPStore(cfg.Database)
if err != nil {
service.LogError("Creation of IDP store failed", "err", err)
return
}
defer cleanup()
idpServer, err := jormungandrSamlIdp.New(cfg)
if err != nil {
service.LogError("Creation of SAML IDP server failed", "err", err)
return
}
// Mount "idp" controller
c1 := NewIdpController(service, store, &idpServer.IDP, cfg)
app.MountIdpController(service, c1)
// Mount "swagger" controller
c2 := NewSwaggerController(service)
app.MountSwaggerController(service, c2)
// Mount "public" controller
c3 := NewPublicController(service)
app.MountPublicController(service, c3)
// Start service
if err := service.ListenAndServe(":8080"); err != nil {
service.LogError("startup", "err", err)
}
}