2022-03-24 16:21:34 +00:00
|
|
|
package instance
|
2021-09-14 13:15:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2021-09-14 13:15:01 +00:00
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
2021-09-14 13:15:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
IDPJWTConfigAddedEventType eventstore.EventType = "iam.idp." + idpconfig.JWTConfigAddedEventType
|
|
|
|
IDPJWTConfigChangedEventType eventstore.EventType = "iam.idp." + idpconfig.JWTConfigChangedEventType
|
|
|
|
)
|
|
|
|
|
|
|
|
type IDPJWTConfigAddedEvent struct {
|
|
|
|
idpconfig.JWTConfigAddedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPJWTConfigAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
idpConfigID,
|
|
|
|
jwtEndpoint,
|
|
|
|
issuer,
|
|
|
|
keysEndpoint,
|
|
|
|
headerName string,
|
|
|
|
) *IDPJWTConfigAddedEvent {
|
|
|
|
return &IDPJWTConfigAddedEvent{
|
|
|
|
JWTConfigAddedEvent: *idpconfig.NewJWTConfigAddedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
IDPJWTConfigAddedEventType,
|
|
|
|
),
|
|
|
|
idpConfigID,
|
|
|
|
jwtEndpoint,
|
|
|
|
issuer,
|
|
|
|
keysEndpoint,
|
|
|
|
headerName,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func IDPJWTConfigAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-09-14 13:15:01 +00:00
|
|
|
e, err := idpconfig.JWTConfigAddedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &IDPJWTConfigAddedEvent{JWTConfigAddedEvent: *e.(*idpconfig.JWTConfigAddedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPJWTConfigChangedEvent struct {
|
|
|
|
idpconfig.JWTConfigChangedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIDPJWTConfigChangedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
idpConfigID string,
|
|
|
|
changes []idpconfig.JWTConfigChanges,
|
|
|
|
) (*IDPJWTConfigChangedEvent, error) {
|
|
|
|
changeEvent, err := idpconfig.NewJWTConfigChangedEvent(
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
IDPJWTConfigChangedEventType),
|
|
|
|
idpConfigID,
|
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &IDPJWTConfigChangedEvent{JWTConfigChangedEvent: *changeEvent}, nil
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func IDPJWTConfigChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-09-14 13:15:01 +00:00
|
|
|
e, err := idpconfig.JWTConfigChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &IDPJWTConfigChangedEvent{JWTConfigChangedEvent: *e.(*idpconfig.JWTConfigChangedEvent)}, nil
|
|
|
|
}
|