2022-03-24 16:21:34 +00:00
|
|
|
package instance
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-03-28 08:05:09 +00:00
|
|
|
DomainPolicyAddedEventType = instanceEventTypePrefix + policy.DomainPolicyAddedEventType
|
|
|
|
DomainPolicyChangedEventType = instanceEventTypePrefix + policy.DomainPolicyChangedEventType
|
2022-03-24 16:21:34 +00:00
|
|
|
)
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
type DomainPolicyAddedEvent struct {
|
2022-03-24 16:21:34 +00:00
|
|
|
policy.DomainPolicyAddedEvent
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
func NewDomainPolicyAddedEvent(
|
2022-03-24 16:21:34 +00:00
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2022-04-13 09:24:03 +00:00
|
|
|
userLoginMustBeDomain,
|
|
|
|
validateOrgDomain bool,
|
2022-03-28 08:05:09 +00:00
|
|
|
) *DomainPolicyAddedEvent {
|
|
|
|
return &DomainPolicyAddedEvent{
|
2022-03-24 16:21:34 +00:00
|
|
|
DomainPolicyAddedEvent: *policy.NewDomainPolicyAddedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
2022-03-28 08:05:09 +00:00
|
|
|
DomainPolicyAddedEventType),
|
2022-03-24 16:21:34 +00:00
|
|
|
userLoginMustBeDomain,
|
2022-04-13 09:24:03 +00:00
|
|
|
validateOrgDomain,
|
2022-03-24 16:21:34 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
func DomainPolicyAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2022-03-24 16:21:34 +00:00
|
|
|
e, err := policy.DomainPolicyAddedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
return &DomainPolicyAddedEvent{DomainPolicyAddedEvent: *e.(*policy.DomainPolicyAddedEvent)}, nil
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
type DomainPolicyChangedEvent struct {
|
2022-03-24 16:21:34 +00:00
|
|
|
policy.DomainPolicyChangedEvent
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
func NewDomainPolicyChangedEvent(
|
2022-03-24 16:21:34 +00:00
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2022-04-13 09:24:03 +00:00
|
|
|
changes []policy.DomainPolicyChanges,
|
2022-03-28 08:05:09 +00:00
|
|
|
) (*DomainPolicyChangedEvent, error) {
|
2022-03-24 16:21:34 +00:00
|
|
|
changedEvent, err := policy.NewDomainPolicyChangedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
2022-03-28 08:05:09 +00:00
|
|
|
DomainPolicyChangedEventType),
|
2022-03-24 16:21:34 +00:00
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-03-28 08:05:09 +00:00
|
|
|
return &DomainPolicyChangedEvent{DomainPolicyChangedEvent: *changedEvent}, nil
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
func DomainPolicyChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2022-03-24 16:21:34 +00:00
|
|
|
e, err := policy.DomainPolicyChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
return &DomainPolicyChangedEvent{DomainPolicyChangedEvent: *e.(*policy.DomainPolicyChangedEvent)}, nil
|
2022-03-24 16:21:34 +00:00
|
|
|
}
|