zitadel/internal/v2/repository/iam/idp_config.go

233 lines
5.5 KiB
Go
Raw Normal View History

2020-11-25 19:04:32 +00:00
package iam
import (
"context"
"github.com/caos/zitadel/internal/eventstore/v2"
2020-11-26 12:14:07 +00:00
"github.com/caos/zitadel/internal/eventstore/v2/repository"
2020-11-25 19:04:32 +00:00
"github.com/caos/zitadel/internal/v2/repository/idp"
)
const (
IDPConfigAddedEventType eventstore.EventType = "iam.idp.config.added"
IDPConfigChangedEventType eventstore.EventType = "iam.idp.config.changed"
IDPConfigRemovedEventType eventstore.EventType = "iam.idp.config.removed"
IDPConfigDeactivatedEventType eventstore.EventType = "iam.idp.config.deactivated"
IDPConfigReactivatedEventType eventstore.EventType = "iam.idp.config.reactivated"
)
type IDPConfigReadModel struct {
idp.ConfigReadModel
}
func (rm *IDPConfigReadModel) AppendEvents(events ...eventstore.EventReader) {
for _, event := range events {
switch e := event.(type) {
case *IDPConfigAddedEvent:
rm.ConfigReadModel.AppendEvents(&e.ConfigAddedEvent)
case *IDPConfigChangedEvent:
rm.ConfigReadModel.AppendEvents(&e.ConfigChangedEvent)
case *IDPConfigDeactivatedEvent:
rm.ConfigReadModel.AppendEvents(&e.ConfigDeactivatedEvent)
case *IDPConfigReactivatedEvent:
rm.ConfigReadModel.AppendEvents(&e.ConfigReactivatedEvent)
case *IDPConfigRemovedEvent:
rm.ConfigReadModel.AppendEvents(&e.ConfigRemovedEvent)
2020-11-26 12:14:07 +00:00
case *IDPOIDCConfigAddedEvent:
rm.ConfigReadModel.AppendEvents(&e.ConfigAddedEvent)
case *IDPOIDCConfigChangedEvent:
rm.ConfigReadModel.AppendEvents(&e.ConfigChangedEvent)
2020-11-25 19:04:32 +00:00
}
}
}
type IDPConfigWriteModel struct {
idp.ConfigWriteModel
}
func (rm *IDPConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
for _, event := range events {
switch e := event.(type) {
case *IDPConfigAddedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigAddedEvent)
case *IDPConfigChangedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigChangedEvent)
case *IDPConfigDeactivatedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigDeactivatedEvent)
case *IDPConfigReactivatedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigReactivatedEvent)
case *IDPConfigRemovedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigRemovedEvent)
case *idp.ConfigAddedEvent,
*idp.ConfigChangedEvent,
*idp.ConfigDeactivatedEvent,
*idp.ConfigReactivatedEvent,
*idp.ConfigRemovedEvent:
rm.ConfigWriteModel.AppendEvents(e)
}
}
}
type IDPConfigAddedEvent struct {
idp.ConfigAddedEvent
}
func NewIDPConfigAddedEvent(
ctx context.Context,
configID string,
name string,
configType idp.ConfigType,
stylingType idp.StylingType,
) *IDPConfigAddedEvent {
return &IDPConfigAddedEvent{
ConfigAddedEvent: *idp.NewConfigAddedEvent(
eventstore.NewBaseEventForPush(
ctx,
IDPConfigAddedEventType,
),
configID,
name,
configType,
stylingType,
),
}
}
2020-11-26 12:14:07 +00:00
func IDPConfigAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idp.ConfigAddedEventMapper(event)
if err != nil {
return nil, err
}
return &IDPConfigAddedEvent{ConfigAddedEvent: *e}, nil
}
2020-11-25 19:04:32 +00:00
type IDPConfigChangedEvent struct {
idp.ConfigChangedEvent
}
func NewIDPConfigChangedEvent(
ctx context.Context,
current *IDPConfigWriteModel,
configID string,
name string,
configType idp.ConfigType,
stylingType idp.StylingType,
) (*IDPConfigChangedEvent, error) {
event, err := idp.NewConfigChangedEvent(
eventstore.NewBaseEventForPush(
ctx,
IDPConfigChangedEventType,
),
&current.ConfigWriteModel,
name,
stylingType,
)
if err != nil {
return nil, err
}
return &IDPConfigChangedEvent{
ConfigChangedEvent: *event,
}, nil
}
2020-11-26 12:14:07 +00:00
func IDPConfigChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idp.ConfigChangedEventMapper(event)
if err != nil {
return nil, err
}
return &IDPConfigChangedEvent{ConfigChangedEvent: *e}, nil
}
2020-11-25 19:04:32 +00:00
type IDPConfigRemovedEvent struct {
idp.ConfigRemovedEvent
}
func NewIDPConfigRemovedEvent(
ctx context.Context,
configID string,
) *IDPConfigRemovedEvent {
return &IDPConfigRemovedEvent{
ConfigRemovedEvent: *idp.NewConfigRemovedEvent(
eventstore.NewBaseEventForPush(
ctx,
IDPConfigRemovedEventType,
),
configID,
),
}
}
2020-11-26 12:14:07 +00:00
func IDPConfigRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idp.ConfigRemovedEventMapper(event)
if err != nil {
return nil, err
}
return &IDPConfigRemovedEvent{ConfigRemovedEvent: *e}, nil
}
2020-11-25 19:04:32 +00:00
type IDPConfigDeactivatedEvent struct {
idp.ConfigDeactivatedEvent
}
func NewIDPConfigDeactivatedEvent(
ctx context.Context,
configID string,
) *IDPConfigDeactivatedEvent {
return &IDPConfigDeactivatedEvent{
ConfigDeactivatedEvent: *idp.NewConfigDeactivatedEvent(
eventstore.NewBaseEventForPush(
ctx,
IDPConfigDeactivatedEventType,
),
configID,
),
}
}
2020-11-26 12:14:07 +00:00
func IDPConfigDeactivatedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idp.ConfigDeactivatedEventMapper(event)
if err != nil {
return nil, err
}
return &IDPConfigDeactivatedEvent{ConfigDeactivatedEvent: *e}, nil
}
2020-11-25 19:04:32 +00:00
type IDPConfigReactivatedEvent struct {
idp.ConfigReactivatedEvent
}
func NewIDPConfigReactivatedEvent(
ctx context.Context,
configID string,
) *IDPConfigReactivatedEvent {
return &IDPConfigReactivatedEvent{
ConfigReactivatedEvent: *idp.NewConfigReactivatedEvent(
eventstore.NewBaseEventForPush(
ctx,
IDPConfigReactivatedEventType,
),
configID,
),
}
}
2020-11-26 12:14:07 +00:00
func IDPConfigReactivatedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idp.ConfigReactivatedEventMapper(event)
if err != nil {
return nil, err
}
return &IDPConfigReactivatedEvent{ConfigReactivatedEvent: *e}, nil
}