mirror of
https://github.com/zitadel/zitadel.git
synced 2025-10-15 06:51:18 +00:00
idp
This commit is contained in:
@@ -17,9 +17,6 @@ const (
|
||||
|
||||
type Aggregate struct {
|
||||
eventstore.Aggregate
|
||||
|
||||
// SetUpStarted Step
|
||||
// SetUpDone Step
|
||||
}
|
||||
|
||||
func NewAggregate(
|
||||
@@ -54,8 +51,6 @@ func AggregateFromReadModel(rm *ReadModel) *Aggregate {
|
||||
AggregateVersion,
|
||||
rm.ProcessedSequence,
|
||||
),
|
||||
// SetUpDone: rm.SetUpDone,
|
||||
// SetUpStarted: rm.SetUpStarted,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,3 +77,13 @@ func (a *Aggregate) PushMemberRemoved(ctx context.Context, userID string) *Aggre
|
||||
a.Aggregate = *a.PushEvents(NewMemberRemovedEvent(ctx, userID))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Aggregate) PushStepStarted(ctx context.Context, step Step) *Aggregate {
|
||||
a.Aggregate = *a.PushEvents(NewSetupStepStartedEvent(ctx, step))
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *Aggregate) PushStepDone(ctx context.Context, step Step) *Aggregate {
|
||||
a.Aggregate = *a.PushEvents(NewSetupStepDoneEvent(ctx, step))
|
||||
return a
|
||||
}
|
||||
|
192
internal/v2/repository/iam/idp_config.go
Normal file
192
internal/v2/repository/iam/idp_config.go
Normal file
@@ -0,0 +1,192 @@
|
||||
package iam
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/v2/repository/idp"
|
||||
"github.com/caos/zitadel/internal/v2/repository/idp/oidc"
|
||||
)
|
||||
|
||||
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)
|
||||
case *idp.ConfigAddedEvent,
|
||||
*idp.ConfigChangedEvent,
|
||||
*idp.ConfigDeactivatedEvent,
|
||||
*idp.ConfigReactivatedEvent,
|
||||
*idp.ConfigRemovedEvent,
|
||||
*oidc.ConfigAddedEvent,
|
||||
*oidc.ConfigChangedEvent:
|
||||
|
||||
rm.ConfigReadModel.AppendEvents(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
),
|
||||
¤t.ConfigWriteModel,
|
||||
name,
|
||||
stylingType,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPConfigChangedEvent{
|
||||
ConfigChangedEvent: *event,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type IDPConfigRemovedEvent struct {
|
||||
idp.ConfigRemovedEvent
|
||||
}
|
||||
|
||||
func NewIDPConfigRemovedEvent(
|
||||
ctx context.Context,
|
||||
configID string,
|
||||
) *IDPConfigRemovedEvent {
|
||||
|
||||
return &IDPConfigRemovedEvent{
|
||||
ConfigRemovedEvent: *idp.NewConfigRemovedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPConfigRemovedEventType,
|
||||
),
|
||||
configID,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
type IDPConfigDeactivatedEvent struct {
|
||||
idp.ConfigDeactivatedEvent
|
||||
}
|
||||
|
||||
func NewIDPConfigDeactivatedEvent(
|
||||
ctx context.Context,
|
||||
configID string,
|
||||
) *IDPConfigDeactivatedEvent {
|
||||
|
||||
return &IDPConfigDeactivatedEvent{
|
||||
ConfigDeactivatedEvent: *idp.NewConfigDeactivatedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPConfigDeactivatedEventType,
|
||||
),
|
||||
configID,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
type IDPConfigReactivatedEvent struct {
|
||||
idp.ConfigReactivatedEvent
|
||||
}
|
||||
|
||||
func NewIDPConfigReactivatedEvent(
|
||||
ctx context.Context,
|
||||
configID string,
|
||||
) *IDPConfigReactivatedEvent {
|
||||
|
||||
return &IDPConfigReactivatedEvent{
|
||||
ConfigReactivatedEvent: *idp.NewConfigReactivatedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPConfigReactivatedEventType,
|
||||
),
|
||||
configID,
|
||||
),
|
||||
}
|
||||
}
|
104
internal/v2/repository/iam/idp_oidc_config.go
Normal file
104
internal/v2/repository/iam/idp_oidc_config.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package iam
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/v2/repository/idp/oidc"
|
||||
)
|
||||
|
||||
const (
|
||||
IDPOIDCConfigAddedEventType eventstore.EventType = "iam.idp.oidc.config.added"
|
||||
IDPOIDCConfigChangedEventType eventstore.EventType = "iam.idp.oidc.config.changed"
|
||||
)
|
||||
|
||||
type IDPOIDCConfigWriteModel struct {
|
||||
oidc.ConfigWriteModel
|
||||
}
|
||||
|
||||
func (rm *IDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *IDPOIDCConfigAddedEvent:
|
||||
rm.ConfigWriteModel.AppendEvents(&e.ConfigAddedEvent)
|
||||
case *IDPOIDCConfigChangedEvent:
|
||||
rm.ConfigWriteModel.AppendEvents(&e.ConfigChangedEvent)
|
||||
case *oidc.ConfigAddedEvent,
|
||||
*oidc.ConfigChangedEvent:
|
||||
|
||||
rm.ConfigWriteModel.AppendEvents(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type IDPOIDCConfigAddedEvent struct {
|
||||
oidc.ConfigAddedEvent
|
||||
}
|
||||
|
||||
func NewIDPOIDCConfigAddedEvent(
|
||||
ctx context.Context,
|
||||
clientID,
|
||||
idpConfigID,
|
||||
issuer string,
|
||||
clientSecret *crypto.CryptoValue,
|
||||
idpDisplayNameMapping,
|
||||
userNameMapping oidc.MappingField,
|
||||
scopes ...string,
|
||||
) *IDPOIDCConfigAddedEvent {
|
||||
|
||||
return &IDPOIDCConfigAddedEvent{
|
||||
ConfigAddedEvent: *oidc.NewConfigAddedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPOIDCConfigAddedEventType,
|
||||
),
|
||||
clientID,
|
||||
idpConfigID,
|
||||
issuer,
|
||||
clientSecret,
|
||||
idpDisplayNameMapping,
|
||||
userNameMapping,
|
||||
scopes...,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
type IDPOIDCConfigChangedEvent struct {
|
||||
oidc.ConfigChangedEvent
|
||||
}
|
||||
|
||||
func NewIDPOIDCConfigChangedEvent(
|
||||
ctx context.Context,
|
||||
current *IDPOIDCConfigWriteModel,
|
||||
clientID,
|
||||
idpConfigID,
|
||||
issuer string,
|
||||
clientSecret *crypto.CryptoValue,
|
||||
idpDisplayNameMapping,
|
||||
userNameMapping oidc.MappingField,
|
||||
scopes ...string,
|
||||
) (*IDPOIDCConfigChangedEvent, error) {
|
||||
|
||||
event, err := oidc.NewConfigChangedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
IDPOIDCConfigAddedEventType,
|
||||
),
|
||||
¤t.ConfigWriteModel,
|
||||
clientID,
|
||||
issuer,
|
||||
clientSecret,
|
||||
idpDisplayNameMapping,
|
||||
userNameMapping,
|
||||
scopes...,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IDPOIDCConfigChangedEvent{
|
||||
ConfigChangedEvent: *event,
|
||||
}, nil
|
||||
}
|
@@ -87,7 +87,7 @@ func MemberChangedEventFromExisting(
|
||||
roles ...string,
|
||||
) (*MemberChangedEvent, error) {
|
||||
|
||||
m, err := member.ChangeEventFromExisting(
|
||||
event, err := member.ChangeEventFromExisting(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
MemberChangedEventType,
|
||||
@@ -100,7 +100,7 @@ func MemberChangedEventFromExisting(
|
||||
}
|
||||
|
||||
return &MemberChangedEvent{
|
||||
ChangedEvent: *m,
|
||||
ChangedEvent: *event,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@@ -89,9 +89,7 @@ func (rm *ReadModel) Reduce() (err error) {
|
||||
}
|
||||
|
||||
func (rm *ReadModel) AppendAndReduce(events ...eventstore.EventReader) error {
|
||||
if err := rm.AppendEvents(events...); err != nil {
|
||||
return err
|
||||
}
|
||||
rm.AppendEvents(events...)
|
||||
return rm.Reduce()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user