2021-02-22 12:27:47 +01:00
|
|
|
package project
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
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"
|
2021-02-22 12:27:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
applicationKeyEventPrefix = applicationEventTypePrefix + "oidc.key."
|
|
|
|
ApplicationKeyAddedEventType = applicationKeyEventPrefix + "added"
|
|
|
|
ApplicationKeyRemovedEventType = applicationKeyEventPrefix + "removed"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ApplicationKeyAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
AppID string `json:"applicationId"`
|
|
|
|
ClientID string `json:"clientId,omitempty"`
|
|
|
|
KeyID string `json:"keyId,omitempty"`
|
|
|
|
KeyType domain.AuthNKeyType `json:"type,omitempty"`
|
|
|
|
ExpirationDate time.Time `json:"expirationDate,omitempty"`
|
|
|
|
PublicKey []byte `json:"publicKey,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *ApplicationKeyAddedEvent) Payload() interface{} {
|
2021-02-22 12:27:47 +01:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *ApplicationKeyAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-02-22 12:27:47 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewApplicationKeyAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
appID,
|
|
|
|
clientID,
|
|
|
|
keyID string,
|
|
|
|
keyType domain.AuthNKeyType,
|
|
|
|
expirationDate time.Time,
|
|
|
|
publicKey []byte,
|
|
|
|
) *ApplicationKeyAddedEvent {
|
|
|
|
return &ApplicationKeyAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
ApplicationKeyAddedEventType,
|
|
|
|
),
|
|
|
|
AppID: appID,
|
|
|
|
ClientID: clientID,
|
|
|
|
KeyID: keyID,
|
|
|
|
KeyType: keyType,
|
|
|
|
ExpirationDate: expirationDate,
|
|
|
|
PublicKey: publicKey,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func ApplicationKeyAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-02-22 12:27:47 +01:00
|
|
|
e := &ApplicationKeyAddedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
err := event.Unmarshal(e)
|
2021-02-22 12:27:47 +01:00
|
|
|
if err != nil {
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowInternal(err, "API-BFd15", "unable to unmarshal api config")
|
2021-02-22 12:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ApplicationKeyRemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
KeyID string `json:"keyId,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *ApplicationKeyRemovedEvent) Payload() interface{} {
|
2021-02-22 12:27:47 +01:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *ApplicationKeyRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-02-22 12:27:47 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewApplicationKeyRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
keyID string,
|
|
|
|
) *ApplicationKeyRemovedEvent {
|
|
|
|
return &ApplicationKeyRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
ApplicationKeyRemovedEventType,
|
|
|
|
),
|
|
|
|
KeyID: keyID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func ApplicationKeyRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-02-22 12:27:47 +01:00
|
|
|
applicationKeyRemoved := &ApplicationKeyRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 12:19:10 +02:00
|
|
|
err := event.Unmarshal(applicationKeyRemoved)
|
2021-02-22 12:27:47 +01:00
|
|
|
if err != nil {
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowInternal(err, "USER-cjLeA", "unable to unmarshal application key removed")
|
2021-02-22 12:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return applicationKeyRemoved, nil
|
|
|
|
}
|