2021-01-04 13:52:13 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
|
|
|
"github.com/caos/zitadel/internal/v2/repository/policy"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|