2020-05-20 14:28:08 +02:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/command"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v1"
|
2020-12-18 16:47:45 +01:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2020-05-20 14:28:08 +02:00
|
|
|
"github.com/caos/logging"
|
|
|
|
sd "github.com/caos/zitadel/internal/config/systemdefaults"
|
|
|
|
"github.com/caos/zitadel/internal/config/types"
|
|
|
|
"github.com/caos/zitadel/internal/crypto"
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/v1/query"
|
2020-06-09 15:11:42 +02:00
|
|
|
"github.com/caos/zitadel/internal/i18n"
|
2020-05-20 14:28:08 +02:00
|
|
|
"github.com/caos/zitadel/internal/notification/repository/eventsourcing/view"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Configs map[string]*Config
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
MinimumCycleDuration types.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
type handler struct {
|
|
|
|
view *view.View
|
|
|
|
bulkLimit uint64
|
|
|
|
cycleDuration time.Duration
|
|
|
|
errorCountUntilSkip uint64
|
2020-12-18 16:47:45 +01:00
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
es v1.Eventstore
|
2020-12-18 16:47:45 +01:00
|
|
|
}
|
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
func (h *handler) Eventstore() v1.Eventstore {
|
2020-12-18 16:47:45 +01:00
|
|
|
return h.es
|
2020-05-20 14:28:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-24 11:17:39 +01:00
|
|
|
func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es v1.Eventstore, command *command.Commands, systemDefaults sd.SystemDefaults, i18n *i18n.Translator, dir http.FileSystem) []query.Handler {
|
2020-05-20 14:28:08 +02:00
|
|
|
aesCrypto, err := crypto.NewAESCrypto(systemDefaults.UserVerificationKey)
|
|
|
|
if err != nil {
|
|
|
|
logging.Log("HANDL-s90ew").WithError(err).Debug("error create new aes crypto")
|
|
|
|
}
|
2020-07-28 09:42:21 +02:00
|
|
|
return []query.Handler{
|
2020-12-18 16:47:45 +01:00
|
|
|
newNotifyUser(
|
|
|
|
handler{view, bulkLimit, configs.cycleDuration("User"), errorCount, es},
|
|
|
|
systemDefaults.IamID,
|
|
|
|
),
|
|
|
|
newNotification(
|
|
|
|
handler{view, bulkLimit, configs.cycleDuration("Notification"), errorCount, es},
|
2021-02-08 11:30:30 +01:00
|
|
|
command,
|
2020-12-18 16:47:45 +01:00
|
|
|
systemDefaults,
|
|
|
|
aesCrypto,
|
|
|
|
i18n,
|
|
|
|
dir,
|
|
|
|
),
|
2020-05-20 14:28:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (configs Configs) cycleDuration(viewModel string) time.Duration {
|
|
|
|
c, ok := configs[viewModel]
|
|
|
|
if !ok {
|
2020-12-18 16:47:45 +01:00
|
|
|
return 3 * time.Minute
|
2020-05-20 14:28:08 +02:00
|
|
|
}
|
|
|
|
return c.MinimumCycleDuration.Duration
|
|
|
|
}
|
2020-07-28 09:42:21 +02:00
|
|
|
|
|
|
|
func (h *handler) MinimumCycleDuration() time.Duration {
|
|
|
|
return h.cycleDuration
|
|
|
|
}
|
|
|
|
|
2020-12-22 12:27:55 +01:00
|
|
|
func (h *handler) LockDuration() time.Duration {
|
|
|
|
return h.cycleDuration / 3
|
|
|
|
}
|
|
|
|
|
2020-07-28 09:42:21 +02:00
|
|
|
func (h *handler) QueryLimit() uint64 {
|
|
|
|
return h.bulkLimit
|
|
|
|
}
|