2022-03-24 17:21:34 +01:00
|
|
|
package instance
|
2020-11-25 20:04:32 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-03 09:19:07 +01:00
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-10-19 12:19:10 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
2020-11-25 20:04:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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 IDPConfigAddedEvent struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
idpconfig.IDPConfigAddedEvent
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPConfigAddedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-21 10:49:38 +01:00
|
|
|
configID,
|
2020-11-25 20:04:32 +01:00
|
|
|
name string,
|
2021-01-04 14:52:13 +01:00
|
|
|
configType domain.IDPConfigType,
|
|
|
|
stylingType domain.IDPConfigStylingType,
|
2021-09-10 09:49:49 +02:00
|
|
|
autoRegister bool,
|
2020-11-25 20:04:32 +01:00
|
|
|
) *IDPConfigAddedEvent {
|
|
|
|
|
|
|
|
return &IDPConfigAddedEvent{
|
2021-01-04 14:52:13 +01:00
|
|
|
IDPConfigAddedEvent: *idpconfig.NewIDPConfigAddedEvent(
|
2021-02-18 14:48:27 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
2020-11-25 20:04:32 +01:00
|
|
|
ctx,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate,
|
2020-11-25 20:04:32 +01:00
|
|
|
IDPConfigAddedEventType,
|
|
|
|
),
|
|
|
|
configID,
|
|
|
|
name,
|
|
|
|
configType,
|
|
|
|
stylingType,
|
2021-09-10 09:49:49 +02:00
|
|
|
autoRegister,
|
2020-11-25 20:04:32 +01:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func IDPConfigAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 14:52:13 +01:00
|
|
|
e, err := idpconfig.IDPConfigAddedEventMapper(event)
|
2020-11-26 13:14:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
return &IDPConfigAddedEvent{IDPConfigAddedEvent: *e.(*idpconfig.IDPConfigAddedEvent)}, nil
|
2020-11-26 13:14:07 +01:00
|
|
|
}
|
|
|
|
|
2020-11-25 20:04:32 +01:00
|
|
|
type IDPConfigChangedEvent struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
idpconfig.IDPConfigChangedEvent
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPConfigChangedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-02-15 13:31:24 +01:00
|
|
|
configID,
|
|
|
|
oldName string,
|
2021-01-20 11:06:52 +01:00
|
|
|
changes []idpconfig.IDPConfigChanges,
|
|
|
|
) (*IDPConfigChangedEvent, error) {
|
|
|
|
changeEvent, err := idpconfig.NewIDPConfigChangedEvent(
|
2021-02-18 14:48:27 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
IDPConfigChangedEventType),
|
2021-01-20 11:06:52 +01:00
|
|
|
configID,
|
2021-02-15 13:31:24 +01:00
|
|
|
oldName,
|
2021-01-20 11:06:52 +01:00
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
2021-01-20 11:06:52 +01:00
|
|
|
return &IDPConfigChangedEvent{IDPConfigChangedEvent: *changeEvent}, nil
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func IDPConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 14:52:13 +01:00
|
|
|
e, err := idpconfig.IDPConfigChangedEventMapper(event)
|
2020-11-26 13:14:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
return &IDPConfigChangedEvent{IDPConfigChangedEvent: *e.(*idpconfig.IDPConfigChangedEvent)}, nil
|
2020-11-26 13:14:07 +01:00
|
|
|
}
|
|
|
|
|
2020-11-25 20:04:32 +01:00
|
|
|
type IDPConfigRemovedEvent struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
idpconfig.IDPConfigRemovedEvent
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPConfigRemovedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-21 10:49:38 +01:00
|
|
|
configID,
|
|
|
|
name string,
|
2020-11-25 20:04:32 +01:00
|
|
|
) *IDPConfigRemovedEvent {
|
|
|
|
return &IDPConfigRemovedEvent{
|
2021-01-04 14:52:13 +01:00
|
|
|
IDPConfigRemovedEvent: *idpconfig.NewIDPConfigRemovedEvent(
|
2021-02-18 14:48:27 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
2020-11-25 20:04:32 +01:00
|
|
|
ctx,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate,
|
2020-11-25 20:04:32 +01:00
|
|
|
IDPConfigRemovedEventType,
|
|
|
|
),
|
|
|
|
configID,
|
2021-01-21 10:49:38 +01:00
|
|
|
name,
|
2020-11-25 20:04:32 +01:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func IDPConfigRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 14:52:13 +01:00
|
|
|
e, err := idpconfig.IDPConfigRemovedEventMapper(event)
|
2020-11-26 13:14:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
return &IDPConfigRemovedEvent{IDPConfigRemovedEvent: *e.(*idpconfig.IDPConfigRemovedEvent)}, nil
|
2020-11-26 13:14:07 +01:00
|
|
|
}
|
|
|
|
|
2020-11-25 20:04:32 +01:00
|
|
|
type IDPConfigDeactivatedEvent struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
idpconfig.IDPConfigDeactivatedEvent
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPConfigDeactivatedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2020-11-25 20:04:32 +01:00
|
|
|
configID string,
|
|
|
|
) *IDPConfigDeactivatedEvent {
|
|
|
|
|
|
|
|
return &IDPConfigDeactivatedEvent{
|
2021-01-04 14:52:13 +01:00
|
|
|
IDPConfigDeactivatedEvent: *idpconfig.NewIDPConfigDeactivatedEvent(
|
2020-11-25 20:04:32 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate,
|
2020-11-25 20:04:32 +01:00
|
|
|
IDPConfigDeactivatedEventType,
|
|
|
|
),
|
|
|
|
configID,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func IDPConfigDeactivatedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 14:52:13 +01:00
|
|
|
e, err := idpconfig.IDPConfigDeactivatedEventMapper(event)
|
2020-11-26 13:14:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
return &IDPConfigDeactivatedEvent{IDPConfigDeactivatedEvent: *e.(*idpconfig.IDPConfigDeactivatedEvent)}, nil
|
2020-11-26 13:14:07 +01:00
|
|
|
}
|
|
|
|
|
2020-11-25 20:04:32 +01:00
|
|
|
type IDPConfigReactivatedEvent struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
idpconfig.IDPConfigReactivatedEvent
|
2020-11-25 20:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPConfigReactivatedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate *eventstore.Aggregate,
|
2020-11-25 20:04:32 +01:00
|
|
|
configID string,
|
|
|
|
) *IDPConfigReactivatedEvent {
|
|
|
|
|
|
|
|
return &IDPConfigReactivatedEvent{
|
2021-01-04 14:52:13 +01:00
|
|
|
IDPConfigReactivatedEvent: *idpconfig.NewIDPConfigReactivatedEvent(
|
2020-11-25 20:04:32 +01:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate,
|
2020-11-25 20:04:32 +01:00
|
|
|
IDPConfigReactivatedEventType,
|
|
|
|
),
|
|
|
|
configID,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 13:14:07 +01:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func IDPConfigReactivatedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-01-04 14:52:13 +01:00
|
|
|
e, err := idpconfig.IDPConfigReactivatedEventMapper(event)
|
2020-11-26 13:14:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
return &IDPConfigReactivatedEvent{IDPConfigReactivatedEvent: *e.(*idpconfig.IDPConfigReactivatedEvent)}, nil
|
2020-11-26 13:14:07 +01:00
|
|
|
}
|