2020-04-07 11:23:04 +00:00
|
|
|
package eventsourcing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-13 12:22:29 +00:00
|
|
|
|
2020-04-23 08:43:39 +00:00
|
|
|
sd "github.com/caos/zitadel/internal/config/systemdefaults"
|
2020-05-11 10:16:29 +00:00
|
|
|
"github.com/caos/zitadel/internal/config/types"
|
2020-04-07 11:23:04 +00:00
|
|
|
es_int "github.com/caos/zitadel/internal/eventstore"
|
2020-05-11 10:16:29 +00:00
|
|
|
es_spol "github.com/caos/zitadel/internal/eventstore/spooler"
|
|
|
|
"github.com/caos/zitadel/internal/management/repository/eventsourcing/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/management/repository/eventsourcing/handler"
|
|
|
|
"github.com/caos/zitadel/internal/management/repository/eventsourcing/spooler"
|
|
|
|
mgmt_view "github.com/caos/zitadel/internal/management/repository/eventsourcing/view"
|
2020-05-13 12:22:29 +00:00
|
|
|
es_org "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
2020-05-14 09:48:57 +00:00
|
|
|
es_pol "github.com/caos/zitadel/internal/policy/repository/eventsourcing"
|
2020-04-07 11:23:04 +00:00
|
|
|
es_proj "github.com/caos/zitadel/internal/project/repository/eventsourcing"
|
2020-05-11 08:16:27 +00:00
|
|
|
es_usr "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
|
|
|
es_grant "github.com/caos/zitadel/internal/usergrant/repository/eventsourcing"
|
2020-04-07 11:23:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2020-05-11 10:16:29 +00:00
|
|
|
SearchLimit uint64
|
|
|
|
Eventstore es_int.Config
|
|
|
|
View types.SQL
|
|
|
|
Spooler spooler.SpoolerConfig
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type EsRepository struct {
|
2020-05-11 10:16:29 +00:00
|
|
|
spooler *es_spol.Spooler
|
2020-05-13 12:22:29 +00:00
|
|
|
eventstore.OrgRepository
|
2020-05-11 10:16:29 +00:00
|
|
|
eventstore.ProjectRepo
|
|
|
|
eventstore.UserRepo
|
|
|
|
eventstore.UserGrantRepo
|
2020-05-19 08:12:37 +00:00
|
|
|
eventstore.PolicyRepo
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 08:43:39 +00:00
|
|
|
func Start(conf Config, systemDefaults sd.SystemDefaults) (*EsRepository, error) {
|
2020-04-07 11:23:04 +00:00
|
|
|
es, err := es_int.Start(conf.Eventstore)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-05-11 10:16:29 +00:00
|
|
|
sqlClient, err := conf.View.Start()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
view, err := mgmt_view.StartView(sqlClient)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-07 11:23:04 +00:00
|
|
|
|
2020-04-21 15:00:32 +00:00
|
|
|
project, err := es_proj.StartProject(es_proj.ProjectConfig{
|
2020-04-23 08:43:39 +00:00
|
|
|
Eventstore: es,
|
|
|
|
Cache: conf.Eventstore.Cache,
|
|
|
|
}, systemDefaults)
|
2020-04-07 11:23:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-14 09:48:57 +00:00
|
|
|
policy, err := es_pol.StartPolicy(es_pol.PolicyConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: conf.Eventstore.Cache,
|
|
|
|
}, systemDefaults)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-11 08:16:27 +00:00
|
|
|
user, err := es_usr.StartUser(es_usr.UserConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: conf.Eventstore.Cache,
|
|
|
|
}, systemDefaults)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
usergrant, err := es_grant.StartUserGrant(es_grant.UserGrantConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: conf.Eventstore.Cache,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-13 12:22:29 +00:00
|
|
|
org := es_org.StartOrg(es_org.OrgConfig{Eventstore: es})
|
|
|
|
|
2020-05-20 12:28:08 +00:00
|
|
|
eventstoreRepos := handler.EventstoreRepos{ProjectEvents: project, UserEvents: user}
|
2020-05-11 10:16:29 +00:00
|
|
|
spool := spooler.StartSpooler(conf.Spooler, es, view, sqlClient, eventstoreRepos)
|
|
|
|
|
2020-04-07 11:23:04 +00:00
|
|
|
return &EsRepository{
|
2020-05-13 12:22:29 +00:00
|
|
|
spooler: spool,
|
|
|
|
OrgRepository: eventstore.OrgRepository{org},
|
|
|
|
ProjectRepo: eventstore.ProjectRepo{conf.SearchLimit, project, view},
|
|
|
|
UserRepo: eventstore.UserRepo{conf.SearchLimit, user, view},
|
|
|
|
UserGrantRepo: eventstore.UserGrantRepo{conf.SearchLimit, usergrant, view},
|
2020-05-19 08:12:37 +00:00
|
|
|
PolicyRepo: eventstore.PolicyRepo{policy},
|
2020-04-07 11:23:04 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *EsRepository) Health() error {
|
|
|
|
return repo.ProjectEvents.Health(context.Background())
|
|
|
|
}
|