2020-04-07 11:23:04 +00:00
|
|
|
package eventsourcing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-15 14:50:09 +00:00
|
|
|
|
2020-06-09 12:41:09 +00:00
|
|
|
es_iam "github.com/caos/zitadel/internal/iam/repository/eventsourcing"
|
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
|
2020-06-16 09:40:18 +00:00
|
|
|
Domain string
|
2020-05-11 10:16:29 +00:00
|
|
|
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-06-09 12:41:09 +00:00
|
|
|
eventstore.IamRepository
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 14:46:16 +00:00
|
|
|
func Start(conf Config, systemDefaults sd.SystemDefaults, roles []string) (*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-06-16 09:40:18 +00:00
|
|
|
org := es_org.StartOrg(es_org.OrgConfig{Eventstore: es, IAMDomain: conf.Domain}, systemDefaults)
|
|
|
|
|
2020-06-09 12:41:09 +00:00
|
|
|
iam, err := es_iam.StartIam(es_iam.IamConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: conf.Eventstore.Cache,
|
|
|
|
}, systemDefaults)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-26 14:46:16 +00:00
|
|
|
eventstoreRepos := handler.EventstoreRepos{ProjectEvents: project, UserEvents: user, OrgEvents: org}
|
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,
|
2020-05-26 14:46:16 +00:00
|
|
|
OrgRepository: eventstore.OrgRepository{conf.SearchLimit, org, view, roles},
|
|
|
|
ProjectRepo: eventstore.ProjectRepo{conf.SearchLimit, project, view, roles},
|
2020-06-16 09:40:18 +00:00
|
|
|
UserRepo: eventstore.UserRepo{conf.SearchLimit, user, policy, org, view},
|
2020-05-13 12:22:29 +00:00
|
|
|
UserGrantRepo: eventstore.UserGrantRepo{conf.SearchLimit, usergrant, view},
|
2020-05-19 08:12:37 +00:00
|
|
|
PolicyRepo: eventstore.PolicyRepo{policy},
|
2020-06-09 12:41:09 +00:00
|
|
|
IamRepository: eventstore.IamRepository{iam},
|
2020-04-07 11:23:04 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *EsRepository) Health() error {
|
|
|
|
return repo.ProjectEvents.Health(context.Background())
|
|
|
|
}
|