This commit is contained in:
adlerhurst
2020-11-27 11:30:56 +01:00
parent 3bd4d3a8e3
commit 9487e8bdeb
20 changed files with 424 additions and 183 deletions

View File

@@ -153,14 +153,13 @@ func (a *Aggregate) PushIDPOIDCConfigChanged(
ctx context.Context,
current *IDPOIDCConfigWriteModel,
clientID,
idpConfigID,
issuer string,
clientSecret *crypto.CryptoValue,
idpDisplayNameMapping,
userNameMapping oidc.MappingField,
scopes ...string,
) *Aggregate {
event, err := NewIDPOIDCConfigChangedEvent(ctx, current, clientID, idpConfigID, issuer, clientSecret, idpDisplayNameMapping, userNameMapping, scopes...)
event, err := NewIDPOIDCConfigChangedEvent(ctx, current, clientID, issuer, clientSecret, idpDisplayNameMapping, userNameMapping, scopes...)
if err != nil {
return a
}

View File

@@ -18,6 +18,16 @@ const (
type IDPConfigReadModel struct {
idp.ConfigReadModel
iamID string
configID string
}
func NewIDPConfigReadModel(iamID, configID string) *IDPConfigReadModel {
return &IDPConfigReadModel{
iamID: iamID,
configID: configID,
}
}
func (rm *IDPConfigReadModel) AppendEvents(events ...eventstore.EventReader) {
@@ -41,34 +51,89 @@ func (rm *IDPConfigReadModel) AppendEvents(events ...eventstore.EventReader) {
}
}
type IDPConfigWriteModel struct {
idp.ConfigWriteModel
func (rm *IDPConfigReadModel) Query() *eventstore.SearchQueryFactory {
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
AggregateIDs(rm.iamID).
EventData(map[string]interface{}{
"idpConfigId": rm.configID,
})
}
func (rm *IDPConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
type IDPConfigWriteModel struct {
eventstore.WriteModel
idp.ConfigWriteModel
iamID string
configID string
}
func NewIDPConfigWriteModel(iamID, configID string) *IDPConfigWriteModel {
return &IDPConfigWriteModel{
iamID: iamID,
configID: configID,
}
}
func (wm *IDPConfigWriteModel) Query() *eventstore.SearchQueryFactory {
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
AggregateIDs(wm.iamID)
}
func (wm *IDPConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
wm.WriteModel.AppendEvents(events...)
for _, event := range events {
switch e := event.(type) {
case *IDPConfigAddedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigAddedEvent)
if wm.configID != e.ConfigID {
continue
}
wm.ConfigWriteModel.AppendEvents(&e.ConfigAddedEvent)
case *IDPConfigChangedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigChangedEvent)
if wm.configID != e.ConfigID {
continue
}
wm.ConfigWriteModel.AppendEvents(&e.ConfigChangedEvent)
case *IDPConfigDeactivatedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigDeactivatedEvent)
if wm.configID != e.ConfigID {
continue
}
wm.ConfigWriteModel.AppendEvents(&e.ConfigDeactivatedEvent)
case *IDPConfigReactivatedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigReactivatedEvent)
if wm.configID != e.ConfigID {
continue
}
wm.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)
if wm.configID != e.ConfigID {
continue
}
wm.ConfigWriteModel.AppendEvents(&e.ConfigRemovedEvent)
case *IDPOIDCConfigAddedEvent:
if wm.configID != e.IDPConfigID {
continue
}
wm.ConfigWriteModel.AppendEvents(&e.ConfigAddedEvent)
case *IDPOIDCConfigChangedEvent:
if wm.configID != e.IDPConfigID {
continue
}
wm.ConfigWriteModel.AppendEvents(&e.ConfigChangedEvent)
}
}
}
func (wm *IDPConfigWriteModel) Reduce() error {
if err := wm.ConfigWriteModel.Reduce(); err != nil {
return err
}
return wm.WriteModel.Reduce()
}
func (wm *IDPConfigWriteModel) AppendAndReduce(events ...eventstore.EventReader) error {
wm.AppendEvents(events...)
return wm.Reduce()
}
type IDPConfigAddedEvent struct {
idp.ConfigAddedEvent
}

View File

@@ -16,19 +16,38 @@ const (
type IDPOIDCConfigWriteModel struct {
oidc.ConfigWriteModel
iamID string
idpConfigID string
}
func (rm *IDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
func NewIDPOIDCConfigWriteModel(iamID, idpConfigID string) *IDPOIDCConfigWriteModel {
return &IDPOIDCConfigWriteModel{
iamID: iamID,
idpConfigID: idpConfigID,
}
}
func (wm *IDPOIDCConfigWriteModel) Query() *eventstore.SearchQueryFactory {
return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType).
AggregateIDs(wm.iamID)
}
func (wm *IDPOIDCConfigWriteModel) AppendEvents(events ...eventstore.EventReader) {
for _, event := range events {
switch e := event.(type) {
case *IDPOIDCConfigAddedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigAddedEvent)
if wm.idpConfigID != e.IDPConfigID {
continue
}
wm.ConfigWriteModel.AppendEvents(&e.ConfigAddedEvent)
case *IDPOIDCConfigChangedEvent:
rm.ConfigWriteModel.AppendEvents(&e.ConfigChangedEvent)
case *oidc.ConfigAddedEvent,
*oidc.ConfigChangedEvent:
rm.ConfigWriteModel.AppendEvents(e)
if wm.idpConfigID != e.IDPConfigID {
continue
}
wm.ConfigWriteModel.AppendEvents(&e.ConfigChangedEvent)
default:
wm.ConfigWriteModel.AppendEvents(e)
}
}
}
@@ -82,7 +101,6 @@ func NewIDPOIDCConfigChangedEvent(
ctx context.Context,
current *IDPOIDCConfigWriteModel,
clientID,
idpConfigID,
issuer string,
clientSecret *crypto.CryptoValue,
idpDisplayNameMapping,
@@ -93,7 +111,7 @@ func NewIDPOIDCConfigChangedEvent(
event, err := oidc.NewConfigChangedEvent(
eventstore.NewBaseEventForPush(
ctx,
IDPOIDCConfigAddedEventType,
IDPOIDCConfigChangedEventType,
),
&current.ConfigWriteModel,
clientID,