2020-11-06 17:25:07 +01:00
|
|
|
package iam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-12 22:50:01 +01:00
|
|
|
"encoding/json"
|
2022-01-03 09:19:07 +01:00
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2020-11-06 17:25:07 +01:00
|
|
|
|
2020-11-12 22:50:01 +01:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
2020-11-06 17:25:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-11-06 22:09:19 +01:00
|
|
|
ProjectSetEventType eventstore.EventType = "iam.project.iam.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"`
|
|
|
|
}
|
|
|
|
|
2020-11-06 22:09:19 +01:00
|
|
|
func (e *ProjectSetEvent) Data() interface{} {
|
2020-11-06 17:25:07 +01:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-21 10:49:38 +01:00
|
|
|
func (e *ProjectSetEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
|
|
|
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
|
|
|
|
2022-01-03 09:19:07 +01:00
|
|
|
func ProjectSetMapper(event *repository.Event) (eventstore.Event, error) {
|
2020-11-12 22:50:01 +01: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
|
|
|
|
}
|