zitadel/internal/v2/repository/idp/event_config_added.go
2020-11-26 13:14:07 +01:00

57 lines
1.2 KiB
Go

package idp
import (
"encoding/json"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v2"
"github.com/caos/zitadel/internal/eventstore/v2/repository"
)
type ConfigAddedEvent struct {
eventstore.BaseEvent `json:"-"`
ConfigID string `json:"idpConfigId"`
Name string `json:"name"`
Typ ConfigType `json:"idpType,omitempty"`
StylingType StylingType `json:"stylingType,omitempty"`
}
func NewConfigAddedEvent(
base *eventstore.BaseEvent,
configID string,
name string,
configType ConfigType,
stylingType StylingType,
) *ConfigAddedEvent {
return &ConfigAddedEvent{
BaseEvent: *base,
ConfigID: configID,
Name: name,
StylingType: stylingType,
Typ: configType,
}
}
func (e *ConfigAddedEvent) CheckPrevious() bool {
return true
}
func (e *ConfigAddedEvent) Data() interface{} {
return e
}
func ConfigAddedEventMapper(event *repository.Event) (*ConfigAddedEvent, error) {
e := &ConfigAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
}
return e, nil
}