2022-09-12 16:18:08 +00:00
|
|
|
package keypair
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
AddedCertificateEventType = eventTypePrefix + "certificate.added"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AddedCertificateEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Certificate *Key `json:"certificate"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AddedCertificateEvent) Payload() interface{} {
|
2022-09-12 16:18:08 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AddedCertificateEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2022-09-12 16:18:08 +00: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 10:19:10 +00:00
|
|
|
func AddedCertificateEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2022-09-12 16:18:08 +00:00
|
|
|
e := &AddedCertificateEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2022-09-12 16:18:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "KEY-4n9vs", "unable to unmarshal certificate added")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|