mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
b5564572bc
This implementation increases parallel write capabilities of the eventstore. Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and [06](https://zitadel.com/docs/support/advisory/a10006). The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`. If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
129 lines
3.7 KiB
Go
129 lines
3.7 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
|
)
|
|
|
|
type InstanceIDPConfigWriteModel struct {
|
|
IDPConfigWriteModel
|
|
}
|
|
|
|
func NewInstanceIDPConfigWriteModel(ctx context.Context, configID string) *InstanceIDPConfigWriteModel {
|
|
return &InstanceIDPConfigWriteModel{
|
|
IDPConfigWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: authz.GetInstance(ctx).InstanceID(),
|
|
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
|
|
InstanceID: authz.GetInstance(ctx).InstanceID(),
|
|
},
|
|
ConfigID: configID,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *InstanceIDPConfigWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
ResourceOwner(wm.ResourceOwner).
|
|
AddQuery().
|
|
AggregateTypes(instance.AggregateType).
|
|
AggregateIDs(wm.AggregateID).
|
|
EventTypes(
|
|
instance.IDPConfigAddedEventType,
|
|
instance.IDPConfigChangedEventType,
|
|
instance.IDPConfigDeactivatedEventType,
|
|
instance.IDPConfigReactivatedEventType,
|
|
instance.IDPConfigRemovedEventType,
|
|
instance.IDPOIDCConfigAddedEventType,
|
|
instance.IDPOIDCConfigChangedEventType).
|
|
Builder()
|
|
}
|
|
|
|
func (wm *InstanceIDPConfigWriteModel) AppendEvents(events ...eventstore.Event) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *instance.IDPConfigAddedEvent:
|
|
if wm.ConfigID != e.ConfigID {
|
|
continue
|
|
}
|
|
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigAddedEvent)
|
|
case *instance.IDPConfigChangedEvent:
|
|
if wm.ConfigID != e.ConfigID {
|
|
continue
|
|
}
|
|
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigChangedEvent)
|
|
case *instance.IDPConfigDeactivatedEvent:
|
|
if wm.ConfigID != e.ConfigID {
|
|
continue
|
|
}
|
|
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigDeactivatedEvent)
|
|
case *instance.IDPConfigReactivatedEvent:
|
|
if wm.ConfigID != e.ConfigID {
|
|
continue
|
|
}
|
|
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigReactivatedEvent)
|
|
case *instance.IDPConfigRemovedEvent:
|
|
if wm.ConfigID != e.ConfigID {
|
|
continue
|
|
}
|
|
wm.IDPConfigWriteModel.AppendEvents(&e.IDPConfigRemovedEvent)
|
|
case *instance.IDPOIDCConfigAddedEvent:
|
|
if wm.ConfigID != e.IDPConfigID {
|
|
continue
|
|
}
|
|
wm.IDPConfigWriteModel.AppendEvents(&e.OIDCConfigAddedEvent)
|
|
case *instance.IDPOIDCConfigChangedEvent:
|
|
if wm.ConfigID != e.IDPConfigID {
|
|
continue
|
|
}
|
|
wm.IDPConfigWriteModel.AppendEvents(&e.OIDCConfigChangedEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *InstanceIDPConfigWriteModel) Reduce() error {
|
|
return wm.IDPConfigWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *InstanceIDPConfigWriteModel) AppendAndReduce(events ...eventstore.Event) error {
|
|
wm.AppendEvents(events...)
|
|
return wm.Reduce()
|
|
}
|
|
|
|
func (wm *InstanceIDPConfigWriteModel) NewChangedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
configID,
|
|
name string,
|
|
stylingType domain.IDPConfigStylingType,
|
|
autoRegister bool,
|
|
) (*instance.IDPConfigChangedEvent, bool) {
|
|
|
|
changes := make([]idpconfig.IDPConfigChanges, 0)
|
|
oldName := ""
|
|
if wm.Name != name {
|
|
oldName = wm.Name
|
|
changes = append(changes, idpconfig.ChangeName(name))
|
|
}
|
|
if stylingType.Valid() && wm.StylingType != stylingType {
|
|
changes = append(changes, idpconfig.ChangeStyleType(stylingType))
|
|
}
|
|
if wm.AutoRegister != autoRegister {
|
|
changes = append(changes, idpconfig.ChangeAutoRegister(autoRegister))
|
|
}
|
|
if len(changes) == 0 {
|
|
return nil, false
|
|
}
|
|
changeEvent, err := instance.NewIDPConfigChangedEvent(ctx, aggregate, configID, oldName, changes)
|
|
if err != nil {
|
|
return nil, false
|
|
}
|
|
return changeEvent, true
|
|
}
|