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

170 lines
4.2 KiB
Go
Raw Normal View History

2020-11-25 19:04:32 +00:00
package iam
import (
"context"
2020-11-25 19:04:32 +00:00
"github.com/caos/zitadel/internal/eventstore/v2"
2020-11-26 12:14:07 +00:00
"github.com/caos/zitadel/internal/eventstore/v2/repository"
"github.com/caos/zitadel/internal/v2/domain"
"github.com/caos/zitadel/internal/v2/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 {
idpconfig.IDPConfigAddedEvent
2020-11-25 19:04:32 +00:00
}
func NewIDPConfigAddedEvent(
ctx context.Context,
configID string,
name string,
configType domain.IDPConfigType,
stylingType domain.IDPConfigStylingType,
2020-11-25 19:04:32 +00:00
) *IDPConfigAddedEvent {
return &IDPConfigAddedEvent{
IDPConfigAddedEvent: *idpconfig.NewIDPConfigAddedEvent(
2020-11-25 19:04:32 +00:00
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 := idpconfig.IDPConfigAddedEventMapper(event)
2020-11-26 12:14:07 +00:00
if err != nil {
return nil, err
}
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 {
idpconfig.IDPConfigChangedEvent
2020-11-25 19:04:32 +00:00
}
func NewIDPConfigChangedEvent(
ctx context.Context,
configID string,
changes []idpconfig.IDPConfigChanges,
) (*IDPConfigChangedEvent, error) {
changeEvent, err := idpconfig.NewIDPConfigChangedEvent(
eventstore.NewBaseEventForPush(ctx, IDPConfigChangedEventType),
configID,
changes,
)
if err != nil {
return nil, err
2020-11-25 19:04:32 +00:00
}
return &IDPConfigChangedEvent{IDPConfigChangedEvent: *changeEvent}, nil
2020-11-25 19:04:32 +00:00
}
2020-11-26 12:14:07 +00:00
func IDPConfigChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idpconfig.IDPConfigChangedEventMapper(event)
2020-11-26 12:14:07 +00:00
if err != nil {
return nil, err
}
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 {
idpconfig.IDPConfigRemovedEvent
2020-11-25 19:04:32 +00:00
}
func NewIDPConfigRemovedEvent(
ctx context.Context,
configID string,
) *IDPConfigRemovedEvent {
return &IDPConfigRemovedEvent{
IDPConfigRemovedEvent: *idpconfig.NewIDPConfigRemovedEvent(
2020-11-25 19:04:32 +00:00
eventstore.NewBaseEventForPush(
ctx,
IDPConfigRemovedEventType,
),
configID,
),
}
}
2020-11-26 12:14:07 +00:00
func IDPConfigRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idpconfig.IDPConfigRemovedEventMapper(event)
2020-11-26 12:14:07 +00:00
if err != nil {
return nil, err
}
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 {
idpconfig.IDPConfigDeactivatedEvent
2020-11-25 19:04:32 +00:00
}
func NewIDPConfigDeactivatedEvent(
ctx context.Context,
configID string,
) *IDPConfigDeactivatedEvent {
return &IDPConfigDeactivatedEvent{
IDPConfigDeactivatedEvent: *idpconfig.NewIDPConfigDeactivatedEvent(
2020-11-25 19:04:32 +00:00
eventstore.NewBaseEventForPush(
ctx,
IDPConfigDeactivatedEventType,
),
configID,
),
}
}
2020-11-26 12:14:07 +00:00
func IDPConfigDeactivatedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idpconfig.IDPConfigDeactivatedEventMapper(event)
2020-11-26 12:14:07 +00:00
if err != nil {
return nil, err
}
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 {
idpconfig.IDPConfigReactivatedEvent
2020-11-25 19:04:32 +00:00
}
func NewIDPConfigReactivatedEvent(
ctx context.Context,
configID string,
) *IDPConfigReactivatedEvent {
return &IDPConfigReactivatedEvent{
IDPConfigReactivatedEvent: *idpconfig.NewIDPConfigReactivatedEvent(
2020-11-25 19:04:32 +00:00
eventstore.NewBaseEventForPush(
ctx,
IDPConfigReactivatedEventType,
),
configID,
),
}
}
2020-11-26 12:14:07 +00:00
func IDPConfigReactivatedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := idpconfig.IDPConfigReactivatedEventMapper(event)
2020-11-26 12:14:07 +00:00
if err != nil {
return nil, err
}
return &IDPConfigReactivatedEvent{IDPConfigReactivatedEvent: *e.(*idpconfig.IDPConfigReactivatedEvent)}, nil
2020-11-26 12:14:07 +00:00
}