2021-01-04 14:52:13 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
2021-01-04 14:52:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type IdentityProviderWriteModel struct {
|
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
IDPConfigID string
|
|
|
|
IDPProviderType domain.IdentityProviderType
|
2021-01-07 16:06:45 +01:00
|
|
|
State domain.IdentityProviderState
|
2021-01-04 14:52:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *IdentityProviderWriteModel) Reduce() error {
|
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *policy.IdentityProviderAddedEvent:
|
|
|
|
wm.IDPConfigID = e.IDPConfigID
|
|
|
|
wm.IDPProviderType = e.IDPProviderType
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.IdentityProviderStateActive
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.IdentityProviderRemovedEvent:
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.IdentityProviderStateRemoved
|
2021-08-24 09:22:21 +02:00
|
|
|
case *policy.LoginPolicyRemovedEvent:
|
|
|
|
wm.State = domain.IdentityProviderStateRemoved
|
2021-01-04 14:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|