mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-06 19:08:49 +00:00
policy, idp, member.
member not working atm
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
AddedEventType = "idpprovider.added"
|
||||
)
|
||||
|
||||
type AddedEvent struct {
|
||||
eventstore.BaseEvent
|
||||
|
||||
IDPConfigID string `json:"idpConfigId"`
|
||||
IDPProviderType Type `json:"idpProviderType"`
|
||||
}
|
||||
|
||||
func (e *AddedEvent) CheckPrevious() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *AddedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func NewAddedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
idpConfigID string,
|
||||
idpProviderType Type,
|
||||
) *AddedEvent {
|
||||
|
||||
return &AddedEvent{
|
||||
BaseEvent: *base,
|
||||
IDPConfigID: idpConfigID,
|
||||
IDPProviderType: idpProviderType,
|
||||
}
|
||||
}
|
||||
|
||||
func AddedEventEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e := &AddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "PROVI-bfNnp", "Errors.Internal")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2"
|
||||
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
RemovedEventType = "idpprovider.removed"
|
||||
)
|
||||
|
||||
type RemovedEvent struct {
|
||||
eventstore.BaseEvent
|
||||
|
||||
IDPConfigID string `json:"idpConfigId"`
|
||||
}
|
||||
|
||||
func (e *RemovedEvent) CheckPrevious() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *RemovedEvent) Data() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func NewRemovedEvent(
|
||||
base *eventstore.BaseEvent,
|
||||
idpConfigID string,
|
||||
) *RemovedEvent {
|
||||
|
||||
return &RemovedEvent{
|
||||
BaseEvent: *base,
|
||||
IDPConfigID: idpConfigID,
|
||||
}
|
||||
}
|
||||
|
||||
func RemovedEventEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
||||
e := &RemovedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "PROVI-6H0KQ", "Errors.Internal")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package provider
|
||||
|
||||
type Type int8
|
||||
|
||||
const (
|
||||
TypeSystem Type = iota
|
||||
TypeOrg
|
||||
|
||||
typeCount
|
||||
)
|
||||
|
||||
func (f Type) Valid() bool {
|
||||
return f >= 0 && f < typeCount
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package provider
|
||||
|
||||
import "github.com/caos/zitadel/internal/eventstore/v2"
|
||||
|
||||
type WriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
IDPConfigID string
|
||||
IDPProviderType Type
|
||||
}
|
||||
|
||||
func (wm *WriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
switch e := event.(type) {
|
||||
case *AddedEvent:
|
||||
wm.IDPConfigID = e.IDPConfigID
|
||||
wm.IDPProviderType = e.IDPProviderType
|
||||
}
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
Reference in New Issue
Block a user