2021-01-04 14:52:13 +01:00
|
|
|
package policy
|
2020-12-11 15:49:19 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
OrgIAMPolicyAddedEventType = "policy.org.iam.added"
|
|
|
|
OrgIAMPolicyChangedEventType = "policy.org.iam.changed"
|
|
|
|
)
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
type OrgIAMPolicyAddedEvent struct {
|
2020-12-11 15:49:19 +01:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-06 10:47:55 +01:00
|
|
|
UserLoginMustBeDomain bool `json:"userLoginMustBeDomain,omitempty"`
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func (e *OrgIAMPolicyAddedEvent) Data() interface{} {
|
2020-12-11 15:49:19 +01:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func NewOrgIAMPolicyAddedEvent(
|
2020-12-11 15:49:19 +01:00
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
userLoginMustBeDomain bool,
|
2021-01-04 14:52:13 +01:00
|
|
|
) *OrgIAMPolicyAddedEvent {
|
2020-12-11 15:49:19 +01:00
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
return &OrgIAMPolicyAddedEvent{
|
2020-12-11 15:49:19 +01:00
|
|
|
BaseEvent: *base,
|
|
|
|
UserLoginMustBeDomain: userLoginMustBeDomain,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func OrgIAMPolicyAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e := &OrgIAMPolicyAddedEvent{
|
2020-12-11 15:49:19 +01:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "POLIC-TvSmA", "unable to unmarshal policy")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
type OrgIAMPolicyChangedEvent struct {
|
2020-12-11 15:49:19 +01:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-06 11:12:56 +01:00
|
|
|
UserLoginMustBeDomain *bool `json:"userLoginMustBeDomain,omitempty"`
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func (e *OrgIAMPolicyChangedEvent) Data() interface{} {
|
2020-12-11 15:49:19 +01:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func NewOrgIAMPolicyChangedEvent(
|
2020-12-11 15:49:19 +01:00
|
|
|
base *eventstore.BaseEvent,
|
2021-01-04 14:52:13 +01:00
|
|
|
) *OrgIAMPolicyChangedEvent {
|
|
|
|
return &OrgIAMPolicyChangedEvent{
|
2020-12-11 15:49:19 +01:00
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func OrgIAMPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e := &OrgIAMPolicyChangedEvent{
|
2020-12-11 15:49:19 +01:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "POLIC-0Pl9d", "unable to unmarshal policy")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|