2021-08-09 06:01:20 +00:00
|
|
|
package metadata
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2021-08-09 06:01:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-08-12 14:10:01 +00:00
|
|
|
SetEventType = "metadata.set"
|
|
|
|
RemovedEventType = "metadata.removed"
|
|
|
|
RemovedAllEventType = "metadata.removed.all"
|
2021-08-09 06:01:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type SetEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Key string `json:"key"`
|
|
|
|
Value []byte `json:"value"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *SetEvent) Payload() interface{} {
|
2021-08-09 06:01:20 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *SetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-08-09 06:01:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSetEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
key string,
|
|
|
|
value []byte,
|
|
|
|
) *SetEvent {
|
|
|
|
return &SetEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
Key: key,
|
|
|
|
Value: value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func SetEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-08-09 06:01:20 +00:00
|
|
|
e := &SetEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2021-08-09 06:01:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "META-3n9fs", "unable to unmarshal metadata set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type RemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Key string `json:"key"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RemovedEvent) Payload() interface{} {
|
2021-08-09 06:01:20 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-08-09 06:01:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRemovedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
key string,
|
|
|
|
) *RemovedEvent {
|
|
|
|
|
|
|
|
return &RemovedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
Key: key,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func RemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-08-09 06:01:20 +00:00
|
|
|
e := &RemovedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2021-08-09 06:01:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "META-2m99f", "unable to unmarshal metadata removed")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
2021-08-12 14:10:01 +00:00
|
|
|
|
|
|
|
type RemovedAllEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RemovedAllEvent) Payload() interface{} {
|
2021-08-12 14:10:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *RemovedAllEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-08-12 14:10:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRemovedAllEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
) *RemovedAllEvent {
|
|
|
|
|
|
|
|
return &RemovedAllEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func RemovedAllEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-08-12 14:10:01 +00:00
|
|
|
return &RemovedAllEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|