2022-09-12 17:18:08 +01:00
|
|
|
package keypair
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2022-09-12 17:18:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
AddedCertificateEventType = eventTypePrefix + "certificate.added"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AddedCertificateEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Certificate *Key `json:"certificate"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *AddedCertificateEvent) Payload() interface{} {
|
2022-09-12 17:18:08 +01:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *AddedCertificateEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2022-09-12 17:18:08 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAddedCertificateEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
certificateCrypto *crypto.CryptoValue,
|
|
|
|
certificateExpiration time.Time) *AddedCertificateEvent {
|
|
|
|
return &AddedCertificateEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
AddedCertificateEventType,
|
|
|
|
),
|
|
|
|
Certificate: &Key{
|
|
|
|
Key: certificateCrypto,
|
|
|
|
Expiry: certificateExpiration,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func AddedCertificateEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2022-09-12 17:18:08 +01:00
|
|
|
e := &AddedCertificateEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
err := event.Unmarshal(e)
|
2022-09-12 17:18:08 +01:00
|
|
|
if err != nil {
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowInternal(err, "KEY-4n9vs", "unable to unmarshal certificate added")
|
2022-09-12 17:18:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|