2021-01-04 13:52:13 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/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()
|
|
|
|
}
|