2022-03-24 17:21:34 +01:00
|
|
|
package instance
|
2020-11-06 17:25:07 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2020-11-06 17:25:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-03-29 11:53:19 +02:00
|
|
|
ProjectSetEventType eventstore.EventType = "instance.iam.project.set"
|
|
|
|
ConsoleSetEventType eventstore.EventType = "instance.iam.console.set"
|
2020-11-06 17:25:07 +01:00
|
|
|
)
|
|
|
|
|
2020-11-06 22:09:19 +01:00
|
|
|
type ProjectSetEvent struct {
|
2020-11-06 17:25:07 +01:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ProjectID string `json:"iamProjectId"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *ProjectSetEvent) Payload() interface{} {
|
2020-11-06 17:25:07 +01:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *ProjectSetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-01-21 10:49:38 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:48:27 +01:00
|
|
|
func NewIAMProjectSetEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
projectID string,
|
|
|
|
) *ProjectSetEvent {
|
2020-11-06 22:09:19 +01:00
|
|
|
return &ProjectSetEvent{
|
2020-11-06 17:25:07 +01:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2021-02-18 14:48:27 +01:00
|
|
|
aggregate,
|
2021-01-15 09:32:59 +01:00
|
|
|
ProjectSetEventType,
|
2020-11-06 17:25:07 +01:00
|
|
|
),
|
|
|
|
ProjectID: projectID,
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 22:50:01 +01:00
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func ProjectSetMapper(event eventstore.Event) (eventstore.Event, error) {
|
2020-11-12 22:50:01 +01:00
|
|
|
e := &ProjectSetEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 12:19:10 +02:00
|
|
|
err := event.Unmarshal(e)
|
2020-11-12 22:50:01 +01:00
|
|
|
if err != nil {
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowInternal(err, "IAM-cdFZH", "unable to unmarshal global org set")
|
2020-11-12 22:50:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
2022-03-29 11:53:19 +02:00
|
|
|
|
|
|
|
type ConsoleSetEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ClientID string `json:"clientId"`
|
2022-04-14 14:19:18 +02:00
|
|
|
AppID string `json:"appId"`
|
2022-03-29 11:53:19 +02:00
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *ConsoleSetEvent) Payload() interface{} {
|
2022-03-29 11:53:19 +02:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *ConsoleSetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2022-03-29 11:53:19 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIAMConsoleSetEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2022-04-14 14:19:18 +02:00
|
|
|
clientID,
|
|
|
|
appID *string,
|
2022-03-29 11:53:19 +02:00
|
|
|
) *ConsoleSetEvent {
|
|
|
|
return &ConsoleSetEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
ConsoleSetEventType,
|
|
|
|
),
|
2022-04-12 16:20:17 +02:00
|
|
|
ClientID: *clientID,
|
2022-04-14 14:19:18 +02:00
|
|
|
AppID: *appID,
|
2022-03-29 11:53:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func ConsoleSetMapper(event eventstore.Event) (eventstore.Event, error) {
|
2022-03-29 11:53:19 +02:00
|
|
|
e := &ConsoleSetEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 12:19:10 +02:00
|
|
|
err := event.Unmarshal(e)
|
2022-03-29 11:53:19 +02:00
|
|
|
if err != nil {
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowInternal(err, "IAM-cdFZH", "unable to unmarshal console set")
|
2022-03-29 11:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|