91 lines
2.0 KiB
Go
Raw Normal View History

package authenticator
import (
"context"
"time"
"github.com/zitadel/zitadel/internal/api/http"
"github.com/zitadel/zitadel/internal/eventstore"
)
const (
2024-09-26 09:25:31 +02:00
publicKeyPrefix = eventPrefix + "pk."
PublicKeyCreatedType = publicKeyPrefix + "created"
PublicKeyDeletedType = publicKeyPrefix + "deleted"
)
2024-09-26 09:25:31 +02:00
type PublicKeyCreatedEvent struct {
*eventstore.BaseEvent `json:"-"`
UserID string `json:"userID"`
2024-09-24 14:26:48 +02:00
ExpirationDate time.Time `json:"expirationDate,omitempty"`
PublicKey []byte `json:"publicKey,omitempty"`
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
}
2024-09-26 09:25:31 +02:00
func (e *PublicKeyCreatedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
e.BaseEvent = event
}
2024-09-26 09:25:31 +02:00
func (e *PublicKeyCreatedEvent) Payload() interface{} {
return e
}
2024-09-26 09:25:31 +02:00
func (e *PublicKeyCreatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
2024-09-26 09:25:31 +02:00
func (e *PublicKeyCreatedEvent) TriggerOrigin() string {
2024-09-24 14:26:48 +02:00
return e.TriggeredAtOrigin
}
2024-09-26 09:25:31 +02:00
func NewPublicKeyCreatedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
userID string,
expirationDate time.Time,
publicKey []byte,
2024-09-26 09:25:31 +02:00
) *PublicKeyCreatedEvent {
return &PublicKeyCreatedEvent{
BaseEvent: eventstore.NewBaseEventForPush(
ctx,
aggregate,
2024-09-26 09:25:31 +02:00
PublicKeyCreatedType,
),
2024-09-24 14:26:48 +02:00
UserID: userID,
ExpirationDate: expirationDate,
PublicKey: publicKey,
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
}
}
2024-09-26 09:25:31 +02:00
type PublicKeyDeletedEvent struct {
*eventstore.BaseEvent `json:"-"`
}
2024-09-26 09:25:31 +02:00
func (e *PublicKeyDeletedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
e.BaseEvent = event
}
2024-09-26 09:25:31 +02:00
func (e *PublicKeyDeletedEvent) Payload() interface{} {
return e
}
2024-09-26 09:25:31 +02:00
func (e *PublicKeyDeletedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
2024-09-26 09:25:31 +02:00
func NewPublicKeyDeletedEvent(
ctx context.Context,
aggregate *eventstore.Aggregate,
2024-09-26 09:25:31 +02:00
) *PublicKeyDeletedEvent {
return &PublicKeyDeletedEvent{
BaseEvent: eventstore.NewBaseEventForPush(
ctx,
aggregate,
2024-09-26 09:25:31 +02:00
PublicKeyDeletedType,
),
}
}