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