2020-04-07 13:23:04 +02:00
|
|
|
package eventsourcing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-09 14:41:09 +02:00
|
|
|
es_iam "github.com/caos/zitadel/internal/iam/repository/eventsourcing"
|
2020-05-13 14:22:29 +02:00
|
|
|
|
2020-04-23 10:43:39 +02:00
|
|
|
sd "github.com/caos/zitadel/internal/config/systemdefaults"
|
2020-05-11 12:16:29 +02:00
|
|
|
"github.com/caos/zitadel/internal/config/types"
|
2020-04-07 13:23:04 +02:00
|
|
|
es_int "github.com/caos/zitadel/internal/eventstore"
|
2020-05-11 12:16:29 +02: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 14:22:29 +02:00
|
|
|
es_org "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
2020-05-14 11:48:57 +02:00
|
|
|
es_pol "github.com/caos/zitadel/internal/policy/repository/eventsourcing"
|
2020-04-07 13:23:04 +02:00
|
|
|
es_proj "github.com/caos/zitadel/internal/project/repository/eventsourcing"
|
2020-05-11 10:16:27 +02:00
|
|
|
es_usr "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
|
|
|
es_grant "github.com/caos/zitadel/internal/usergrant/repository/eventsourcing"
|
2020-04-07 13:23:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2020-05-11 12:16:29 +02:00
|
|
|
SearchLimit uint64
|
|
|
|
Eventstore es_int.Config
|
|
|
|
View types.SQL
|
|
|
|
Spooler spooler.SpoolerConfig
|
2020-04-07 13:23:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type EsRepository struct {
|
2020-05-11 12:16:29 +02:00
|
|
|
spooler *es_spol.Spooler
|
2020-05-13 14:22:29 +02:00
|
|
|
eventstore.OrgRepository
|
2020-05-11 12:16:29 +02:00
|
|
|
eventstore.ProjectRepo
|
|
|
|
eventstore.UserRepo
|
|
|
|
eventstore.UserGrantRepo
|
2020-05-19 10:12:37 +02:00
|
|
|
eventstore.PolicyRepo
|
2020-06-09 14:41:09 +02:00
|
|
|
eventstore.IamRepository
|
2020-04-07 13:23:04 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 16:46:16 +02:00
|
|
|
func Start(conf Config, systemDefaults sd.SystemDefaults, roles []string) (*EsRepository, error) {
|
2020-04-07 13:23:04 +02:00
|
|
|
es, err := es_int.Start(conf.Eventstore)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-05-11 12:16:29 +02: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 13:23:04 +02:00
|
|
|
|
2020-04-21 17:00:32 +02:00
|
|
|
project, err := es_proj.StartProject(es_proj.ProjectConfig{
|
2020-04-23 10:43:39 +02:00
|
|
|
Eventstore: es,
|
|
|
|
Cache: conf.Eventstore.Cache,
|
|
|
|
}, systemDefaults)
|
2020-04-07 13:23:04 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-14 11:48:57 +02: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 10:16:27 +02: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 14:22:29 +02:00
|
|
|
org := es_org.StartOrg(es_org.OrgConfig{Eventstore: es})
|
2020-06-09 14:41:09 +02:00
|
|
|
iam, err := es_iam.StartIam(es_iam.IamConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: conf.Eventstore.Cache,
|
|
|
|
}, systemDefaults)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-13 14:22:29 +02:00
|
|
|
|
2020-05-26 16:46:16 +02:00
|
|
|
eventstoreRepos := handler.EventstoreRepos{ProjectEvents: project, UserEvents: user, OrgEvents: org}
|
2020-05-11 12:16:29 +02:00
|
|
|
spool := spooler.StartSpooler(conf.Spooler, es, view, sqlClient, eventstoreRepos)
|
|
|
|
|
2020-04-07 13:23:04 +02:00
|
|
|
return &EsRepository{
|
2020-05-13 14:22:29 +02:00
|
|
|
spooler: spool,
|
2020-05-26 16:46:16 +02:00
|
|
|
OrgRepository: eventstore.OrgRepository{conf.SearchLimit, org, view, roles},
|
|
|
|
ProjectRepo: eventstore.ProjectRepo{conf.SearchLimit, project, view, roles},
|
2020-05-29 08:44:01 +02:00
|
|
|
UserRepo: eventstore.UserRepo{conf.SearchLimit, user, policy, view},
|
2020-05-13 14:22:29 +02:00
|
|
|
UserGrantRepo: eventstore.UserGrantRepo{conf.SearchLimit, usergrant, view},
|
2020-05-19 10:12:37 +02:00
|
|
|
PolicyRepo: eventstore.PolicyRepo{policy},
|
2020-06-09 14:41:09 +02:00
|
|
|
IamRepository: eventstore.IamRepository{iam},
|
2020-04-07 13:23:04 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *EsRepository) Health() error {
|
|
|
|
return repo.ProjectEvents.Health(context.Background())
|
|
|
|
}
|