2020-05-20 12:28:08 +00:00
|
|
|
package eventsourcing
|
|
|
|
|
|
|
|
import (
|
2020-07-08 07:48:11 +00:00
|
|
|
"net/http"
|
|
|
|
|
2020-05-20 12:28:08 +00:00
|
|
|
sd "github.com/caos/zitadel/internal/config/systemdefaults"
|
|
|
|
"github.com/caos/zitadel/internal/config/types"
|
|
|
|
es_int "github.com/caos/zitadel/internal/eventstore"
|
|
|
|
es_spol "github.com/caos/zitadel/internal/eventstore/spooler"
|
2020-06-09 13:11:42 +00:00
|
|
|
"github.com/caos/zitadel/internal/i18n"
|
2020-05-20 12:28:08 +00:00
|
|
|
"github.com/caos/zitadel/internal/notification/repository/eventsourcing/handler"
|
|
|
|
"github.com/caos/zitadel/internal/notification/repository/eventsourcing/spooler"
|
|
|
|
noti_view "github.com/caos/zitadel/internal/notification/repository/eventsourcing/view"
|
2020-07-07 17:31:51 +00:00
|
|
|
es_org "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
2020-05-20 12:28:08 +00:00
|
|
|
es_usr "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
2020-06-09 13:11:42 +00:00
|
|
|
"golang.org/x/text/language"
|
2020-05-20 12:28:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2020-06-09 13:11:42 +00:00
|
|
|
DefaultLanguage language.Tag
|
|
|
|
Eventstore es_int.Config
|
|
|
|
View types.SQL
|
|
|
|
Spooler spooler.SpoolerConfig
|
2020-07-07 17:31:51 +00:00
|
|
|
Domain string
|
2020-05-20 12:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type EsRepository struct {
|
|
|
|
spooler *es_spol.Spooler
|
|
|
|
}
|
|
|
|
|
2020-06-09 13:11:42 +00:00
|
|
|
func Start(conf Config, dir http.FileSystem, systemDefaults sd.SystemDefaults) (*EsRepository, error) {
|
2020-05-20 12:28:08 +00:00
|
|
|
es, err := es_int.Start(conf.Eventstore)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlClient, err := conf.View.Start()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
view, err := noti_view.StartView(sqlClient)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := es_usr.StartUser(es_usr.UserConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: conf.Eventstore.Cache,
|
|
|
|
}, systemDefaults)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-07 17:31:51 +00:00
|
|
|
org := es_org.StartOrg(es_org.OrgConfig{Eventstore: es, IAMDomain: conf.Domain}, systemDefaults)
|
|
|
|
|
2020-07-08 07:48:11 +00:00
|
|
|
translator, err := i18n.NewTranslator(dir, i18n.TranslatorConfig{DefaultLanguage: conf.DefaultLanguage})
|
2020-06-09 13:11:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-07 17:31:51 +00:00
|
|
|
eventstoreRepos := handler.EventstoreRepos{UserEvents: user, OrgEvents: org}
|
2020-07-08 07:48:11 +00:00
|
|
|
spool := spooler.StartSpooler(conf.Spooler, es, view, sqlClient, eventstoreRepos, systemDefaults, translator, dir)
|
2020-05-20 12:28:08 +00:00
|
|
|
|
|
|
|
return &EsRepository{
|
|
|
|
spool,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *EsRepository) Health() error {
|
|
|
|
return nil
|
|
|
|
}
|