zitadel/internal/v2/repository/idp/event_config_added.go

57 lines
1.2 KiB
Go
Raw Normal View History

2020-11-17 12:44:37 +00:00
package idp
2020-11-25 19:04:32 +00: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"
)
2020-11-17 12:44:37 +00:00
2020-11-18 20:22:15 +00:00
type ConfigAddedEvent struct {
2020-11-25 19:04:32 +00:00
eventstore.BaseEvent `json:"-"`
2020-11-17 12:44:37 +00:00
2020-11-25 19:04:32 +00:00
ConfigID string `json:"idpConfigId"`
2020-11-27 10:30:56 +00:00
Name string `json:"name,omitempty"`
2020-11-25 19:04:32 +00:00
Typ ConfigType `json:"idpType,omitempty"`
2020-11-18 20:22:15 +00:00
StylingType StylingType `json:"stylingType,omitempty"`
2020-11-17 12:44:37 +00:00
}
2020-11-25 19:04:32 +00:00
func NewConfigAddedEvent(
2020-11-17 12:44:37 +00:00
base *eventstore.BaseEvent,
configID string,
name string,
2020-11-18 20:22:15 +00:00
configType ConfigType,
stylingType StylingType,
) *ConfigAddedEvent {
2020-11-17 12:44:37 +00:00
2020-11-18 20:22:15 +00:00
return &ConfigAddedEvent{
BaseEvent: *base,
2020-11-25 19:04:32 +00:00
ConfigID: configID,
2020-11-18 20:22:15 +00:00
Name: name,
StylingType: stylingType,
2020-11-25 19:04:32 +00:00
Typ: configType,
2020-11-17 12:44:37 +00:00
}
}
2020-11-18 20:22:15 +00:00
func (e *ConfigAddedEvent) CheckPrevious() bool {
2020-11-17 12:44:37 +00:00
return true
}
2020-11-18 20:22:15 +00:00
func (e *ConfigAddedEvent) Data() interface{} {
2020-11-17 12:44:37 +00:00
return e
}
2020-11-18 20:22:15 +00:00
func ConfigAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
2020-11-25 19:04:32 +00:00
e := &ConfigAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
2020-11-18 20:22:15 +00:00
2020-11-25 19:04:32 +00:00
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
}
return e, nil
}