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