2021-01-04 13:52:13 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type IdentityProviderWriteModel struct {
|
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
IDPConfigID string
|
|
|
|
IDPProviderType domain.IdentityProviderType
|
2021-01-07 15:06:45 +00:00
|
|
|
State domain.IdentityProviderState
|
2021-01-04 13:52:13 +00: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 15:06:45 +00:00
|
|
|
wm.State = domain.IdentityProviderStateActive
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.IdentityProviderRemovedEvent:
|
2021-01-07 15:06:45 +00:00
|
|
|
wm.State = domain.IdentityProviderStateRemoved
|
2021-08-24 07:22:21 +00:00
|
|
|
case *policy.LoginPolicyRemovedEvent:
|
|
|
|
wm.State = domain.IdentityProviderStateRemoved
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|