2020-05-18 10:06:36 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2022-03-28 08:05:09 +00:00
|
|
|
"context"
|
2020-07-28 07:42:21 +00:00
|
|
|
"time"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
"github.com/zitadel/zitadel/internal/auth/repository/eventsourcing/view"
|
|
|
|
sd "github.com/zitadel/zitadel/internal/config/systemdefaults"
|
|
|
|
v1 "github.com/zitadel/zitadel/internal/eventstore/v1"
|
2022-07-22 10:08:39 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/query"
|
|
|
|
query2 "github.com/zitadel/zitadel/internal/query"
|
2022-07-22 10:08:39 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/view/repository"
|
2020-05-18 10:06:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Configs map[string]*Config
|
|
|
|
|
|
|
|
type Config struct {
|
2022-02-14 16:22:30 +00:00
|
|
|
MinimumCycleDuration time.Duration
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type handler struct {
|
|
|
|
view *view.View
|
|
|
|
bulkLimit uint64
|
|
|
|
cycleDuration time.Duration
|
|
|
|
errorCountUntilSkip uint64
|
2020-12-18 15:47:45 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
es v1.Eventstore
|
2020-12-18 15:47:45 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
func (h *handler) Eventstore() v1.Eventstore {
|
2020-12-18 15:47:45 +00:00
|
|
|
return h.es
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
|
2022-01-21 07:52:12 +00:00
|
|
|
func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es v1.Eventstore, systemDefaults sd.SystemDefaults, queries *query2.Queries) []query.Handler {
|
2020-07-28 07:42:21 +00:00
|
|
|
return []query.Handler{
|
2020-12-18 15:47:45 +00:00
|
|
|
newUser(
|
2022-02-16 15:49:17 +00:00
|
|
|
handler{view, bulkLimit, configs.cycleDuration("User"), errorCount, es}, queries),
|
2020-12-18 15:47:45 +00:00
|
|
|
newUserSession(
|
2022-06-03 12:37:24 +00:00
|
|
|
handler{view, bulkLimit, configs.cycleDuration("UserSession"), errorCount, es}, queries),
|
2020-12-18 15:47:45 +00:00
|
|
|
newToken(
|
2021-02-22 13:08:47 +00:00
|
|
|
handler{view, bulkLimit, configs.cycleDuration("Token"), errorCount, es}),
|
2020-12-18 15:47:45 +00:00
|
|
|
newIDPConfig(
|
|
|
|
handler{view, bulkLimit, configs.cycleDuration("IDPConfig"), errorCount, es}),
|
|
|
|
newIDPProvider(
|
|
|
|
handler{view, bulkLimit, configs.cycleDuration("IDPProvider"), errorCount, es},
|
2022-01-21 07:52:12 +00:00
|
|
|
systemDefaults, queries),
|
2020-12-18 15:47:45 +00:00
|
|
|
newExternalIDP(
|
|
|
|
handler{view, bulkLimit, configs.cycleDuration("ExternalIDP"), errorCount, es},
|
2022-01-21 07:52:12 +00:00
|
|
|
systemDefaults, queries),
|
2021-05-20 11:33:35 +00:00
|
|
|
newRefreshToken(handler{view, bulkLimit, configs.cycleDuration("RefreshToken"), errorCount, es}),
|
2021-08-18 08:49:04 +00:00
|
|
|
newOrgProjectMapping(handler{view, bulkLimit, configs.cycleDuration("OrgProjectMapping"), errorCount, es}),
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (configs Configs) cycleDuration(viewModel string) time.Duration {
|
|
|
|
c, ok := configs[viewModel]
|
|
|
|
if !ok {
|
2020-12-18 15:47:45 +00:00
|
|
|
return 3 * time.Minute
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
2022-02-14 16:22:30 +00:00
|
|
|
return c.MinimumCycleDuration
|
2020-05-18 10:06:36 +00:00
|
|
|
}
|
2020-07-28 07:42:21 +00:00
|
|
|
|
|
|
|
func (h *handler) MinimumCycleDuration() time.Duration {
|
|
|
|
return h.cycleDuration
|
|
|
|
}
|
|
|
|
|
2020-12-22 11:27:55 +00:00
|
|
|
func (h *handler) LockDuration() time.Duration {
|
|
|
|
return h.cycleDuration / 3
|
|
|
|
}
|
|
|
|
|
2020-07-28 07:42:21 +00:00
|
|
|
func (h *handler) QueryLimit() uint64 {
|
|
|
|
return h.bulkLimit
|
|
|
|
}
|
2022-03-28 08:05:09 +00:00
|
|
|
|
|
|
|
func withInstanceID(ctx context.Context, instanceID string) context.Context {
|
2022-03-29 09:53:19 +00:00
|
|
|
return authz.WithInstanceID(ctx, instanceID)
|
2022-03-28 08:05:09 +00:00
|
|
|
}
|
2022-07-22 10:08:39 +00:00
|
|
|
|
|
|
|
func newSearchQuery(sequences []*repository.CurrentSequence, aggregateTypes []models.AggregateType, instanceIDs []string) *models.SearchQuery {
|
|
|
|
searchQuery := models.NewSearchQuery()
|
|
|
|
for _, sequence := range sequences {
|
|
|
|
var seq uint64
|
|
|
|
for _, instanceID := range instanceIDs {
|
|
|
|
if sequence.InstanceID == instanceID {
|
|
|
|
seq = sequence.CurrentSequence
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
searchQuery.AddQuery().
|
|
|
|
AggregateTypeFilter(aggregateTypes...).
|
|
|
|
LatestSequenceFilter(seq).
|
|
|
|
InstanceIDFilter(sequence.InstanceID)
|
|
|
|
}
|
|
|
|
return searchQuery
|
|
|
|
}
|