2022-03-24 16:21:34 +00:00
|
|
|
package instance
|
2020-11-06 16:25:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-12 21:50:01 +00:00
|
|
|
"encoding/json"
|
2022-01-03 08:19:07 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2020-11-06 16:25:07 +00:00
|
|
|
|
2020-11-12 21:50:01 +00:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
2020-11-06 16:25:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
GlobalOrgSetEventType eventstore.EventType = "iam.global.org.set"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GlobalOrgSetEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
OrgID string `json:"globalOrgId"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *GlobalOrgSetEvent) Data() interface{} {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func (e *GlobalOrgSetEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func NewGlobalOrgSetEventEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
orgID string,
|
|
|
|
) *GlobalOrgSetEvent {
|
2020-11-06 16:25:07 +00:00
|
|
|
return &GlobalOrgSetEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate,
|
2020-11-06 16:25:07 +00:00
|
|
|
GlobalOrgSetEventType,
|
|
|
|
),
|
|
|
|
OrgID: orgID,
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 21:50:01 +00:00
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func GlobalOrgSetMapper(event *repository.Event) (eventstore.Event, error) {
|
2020-11-12 21:50:01 +00:00
|
|
|
e := &GlobalOrgSetEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "IAM-cdFZH", "unable to unmarshal global org set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|