2020-11-06 16:25:07 +00:00
|
|
|
package iam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-12 21:50:01 +00:00
|
|
|
"encoding/json"
|
2020-11-06 16:25:07 +00:00
|
|
|
|
2020-11-12 21:50:01 +00:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2020-11-06 16:25:07 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
2020-11-12 21:50:01 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
2020-11-06 16:25:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-11-06 21:09:19 +00:00
|
|
|
ProjectSetEventType eventstore.EventType = "iam.project.iam.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-12 11:59:51 +00:00
|
|
|
func NewIAMProjectSetEvent(ctx context.Context, 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-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
|
|
|
|
|
|
|
func ProjectSetMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
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
|
|
|
|
}
|