1
0
mirror of https://github.com/zitadel/zitadel.git synced 2024-12-26 09:37:47 +00:00

81 lines
2.3 KiB
Go
Raw Normal View History

package command
2020-11-25 20:04:32 +01:00
import (
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/repository/idpconfig"
2020-11-25 20:04:32 +01:00
)
type OIDCConfigWriteModel struct {
2020-11-25 20:04:32 +01:00
eventstore.WriteModel
IDPConfigID string
ClientID string
ClientSecret *crypto.CryptoValue
Issuer string
AuthorizationEndpoint string
TokenEndpoint string
Scopes []string
2020-11-25 20:04:32 +01:00
IDPDisplayNameMapping domain.OIDCMappingField
UserNameMapping domain.OIDCMappingField
State domain.IDPConfigState
2020-11-25 20:04:32 +01:00
}
func (wm *OIDCConfigWriteModel) Reduce() error {
2020-11-25 20:04:32 +01:00
for _, event := range wm.Events {
switch e := event.(type) {
case *idpconfig.OIDCConfigAddedEvent:
2020-11-27 11:30:56 +01:00
wm.reduceConfigAddedEvent(e)
case *idpconfig.OIDCConfigChangedEvent:
2020-11-27 11:30:56 +01:00
wm.reduceConfigChangedEvent(e)
case *idpconfig.IDPConfigDeactivatedEvent:
wm.State = domain.IDPConfigStateInactive
case *idpconfig.IDPConfigReactivatedEvent:
wm.State = domain.IDPConfigStateActive
case *idpconfig.IDPConfigRemovedEvent:
wm.State = domain.IDPConfigStateRemoved
2020-11-25 20:04:32 +01:00
}
}
return wm.WriteModel.Reduce()
}
2020-11-27 11:30:56 +01:00
func (wm *OIDCConfigWriteModel) reduceConfigAddedEvent(e *idpconfig.OIDCConfigAddedEvent) {
2020-11-27 11:30:56 +01:00
wm.IDPConfigID = e.IDPConfigID
wm.ClientID = e.ClientID
wm.ClientSecret = e.ClientSecret
wm.Issuer = e.Issuer
wm.AuthorizationEndpoint = e.AuthorizationEndpoint
wm.TokenEndpoint = e.TokenEndpoint
2020-11-27 11:30:56 +01:00
wm.Scopes = e.Scopes
wm.IDPDisplayNameMapping = e.IDPDisplayNameMapping
wm.UserNameMapping = e.UserNameMapping
wm.State = domain.IDPConfigStateActive
2020-11-27 11:30:56 +01:00
}
func (wm *OIDCConfigWriteModel) reduceConfigChangedEvent(e *idpconfig.OIDCConfigChangedEvent) {
if e.ClientID != nil {
wm.ClientID = *e.ClientID
2020-11-27 11:30:56 +01:00
}
if e.Issuer != nil {
wm.Issuer = *e.Issuer
2020-11-27 11:30:56 +01:00
}
if e.AuthorizationEndpoint != nil {
wm.AuthorizationEndpoint = *e.AuthorizationEndpoint
}
if e.TokenEndpoint != nil {
wm.TokenEndpoint = *e.TokenEndpoint
}
2020-11-27 11:30:56 +01:00
if len(e.Scopes) > 0 {
wm.Scopes = e.Scopes
}
if e.IDPDisplayNameMapping != nil && e.IDPDisplayNameMapping.Valid() {
wm.IDPDisplayNameMapping = *e.IDPDisplayNameMapping
2020-11-27 11:30:56 +01:00
}
if e.UserNameMapping != nil && e.UserNameMapping.Valid() {
wm.UserNameMapping = *e.UserNameMapping
2020-11-27 11:30:56 +01:00
}
}