2020-05-18 12:06:36 +02:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2022-03-28 10:05:09 +02:00
|
|
|
"context"
|
2020-07-28 09:42:21 +02:00
|
|
|
"time"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/auth/repository/eventsourcing/view"
|
2023-10-19 12:19:10 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
handler2 "github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
2022-04-27 01:01:45 +02:00
|
|
|
query2 "github.com/zitadel/zitadel/internal/query"
|
2020-05-18 12:06:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2023-10-19 12:19:10 +02:00
|
|
|
Client *database.DB
|
|
|
|
Eventstore *eventstore.Eventstore
|
2020-05-18 12:06:36 +02:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
BulkLimit uint64
|
|
|
|
FailureCountUntilSkip uint64
|
|
|
|
HandleActiveInstances time.Duration
|
|
|
|
TransactionDuration time.Duration
|
|
|
|
Handlers map[string]*ConfigOverwrites
|
2020-05-18 12:06:36 +02:00
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
type ConfigOverwrites struct {
|
|
|
|
MinimumCycleDuration time.Duration
|
2020-05-18 12:06:36 +02:00
|
|
|
}
|
2020-07-28 09:42:21 +02:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func Register(ctx context.Context, configs Config, view *view.View, queries *query2.Queries) {
|
|
|
|
newUser(ctx,
|
|
|
|
configs.overwrite("User"),
|
|
|
|
view,
|
|
|
|
queries,
|
|
|
|
).Start(ctx)
|
2020-07-28 09:42:21 +02:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
newUserSession(ctx,
|
|
|
|
configs.overwrite("UserSession"),
|
|
|
|
view,
|
|
|
|
queries,
|
|
|
|
).Start(ctx)
|
2020-12-22 12:27:55 +01:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
newToken(ctx,
|
|
|
|
configs.overwrite("Token"),
|
|
|
|
view,
|
|
|
|
).Start(ctx)
|
2022-03-28 10:05:09 +02:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
newRefreshToken(ctx,
|
|
|
|
configs.overwrite("RefreshToken"),
|
|
|
|
view,
|
|
|
|
).Start(ctx)
|
2022-03-28 10:05:09 +02:00
|
|
|
}
|
2022-07-22 12:08:39 +02:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (config Config) overwrite(viewModel string) handler2.Config {
|
|
|
|
c := handler2.Config{
|
|
|
|
Client: config.Client,
|
|
|
|
Eventstore: config.Eventstore,
|
|
|
|
BulkLimit: uint16(config.BulkLimit),
|
|
|
|
RequeueEvery: 3 * time.Minute,
|
|
|
|
HandleActiveInstances: config.HandleActiveInstances,
|
|
|
|
MaxFailureCount: uint8(config.FailureCountUntilSkip),
|
|
|
|
TransactionDuration: config.TransactionDuration,
|
|
|
|
}
|
|
|
|
overwrite, ok := config.Handlers[viewModel]
|
|
|
|
if !ok {
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
if overwrite.MinimumCycleDuration > 0 {
|
|
|
|
c.RequeueEvery = overwrite.MinimumCycleDuration
|
2022-07-22 12:08:39 +02:00
|
|
|
}
|
2023-10-19 12:19:10 +02:00
|
|
|
return c
|
2022-07-22 12:08:39 +02:00
|
|
|
}
|