2023-01-31 19:52:47 +00:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
machineSecretPrefix = machineEventPrefix + "secret."
|
|
|
|
MachineSecretSetType = machineSecretPrefix + "set"
|
|
|
|
MachineSecretRemovedType = machineSecretPrefix + "removed"
|
|
|
|
MachineSecretCheckSucceededType = machineSecretPrefix + "check.succeeded"
|
|
|
|
MachineSecretCheckFailedType = machineSecretPrefix + "check.failed"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MachineSecretSetEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MachineSecretSetEvent) Payload() interface{} {
|
2023-01-31 19:52:47 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MachineSecretSetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-01-31 19:52:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMachineSecretSetEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
clientSecret *crypto.CryptoValue,
|
|
|
|
) *MachineSecretSetEvent {
|
|
|
|
return &MachineSecretSetEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
MachineSecretSetType,
|
|
|
|
),
|
|
|
|
ClientSecret: clientSecret,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MachineSecretSetEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-01-31 19:52:47 +00:00
|
|
|
credentialsSet := &MachineSecretSetEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(credentialsSet)
|
2023-01-31 19:52:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-lopbqu", "unable to unmarshal machine secret set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return credentialsSet, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type MachineSecretRemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MachineSecretRemovedEvent) Payload() interface{} {
|
2023-01-31 19:52:47 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MachineSecretRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-01-31 19:52:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMachineSecretRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *MachineSecretRemovedEvent {
|
|
|
|
return &MachineSecretRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
MachineSecretRemovedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MachineSecretRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-01-31 19:52:47 +00:00
|
|
|
credentialsRemoved := &MachineSecretRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(credentialsRemoved)
|
2023-01-31 19:52:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-quox9j2", "unable to unmarshal machine secret removed")
|
|
|
|
}
|
|
|
|
|
|
|
|
return credentialsRemoved, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type MachineSecretCheckSucceededEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MachineSecretCheckSucceededEvent) Payload() interface{} {
|
2023-01-31 19:52:47 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MachineSecretCheckSucceededEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-01-31 19:52:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMachineSecretCheckSucceededEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *MachineSecretCheckSucceededEvent {
|
|
|
|
return &MachineSecretCheckSucceededEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
MachineSecretCheckSucceededType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MachineSecretCheckSucceededEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-01-31 19:52:47 +00:00
|
|
|
check := &MachineSecretCheckSucceededEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(check)
|
2023-01-31 19:52:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-x002n1p", "unable to unmarshal machine secret check succeeded")
|
|
|
|
}
|
|
|
|
|
|
|
|
return check, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type MachineSecretCheckFailedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MachineSecretCheckFailedEvent) Payload() interface{} {
|
2023-01-31 19:52:47 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MachineSecretCheckFailedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-01-31 19:52:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMachineSecretCheckFailedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *MachineSecretCheckFailedEvent {
|
|
|
|
return &MachineSecretCheckFailedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
MachineSecretCheckFailedType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MachineSecretCheckFailedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-01-31 19:52:47 +00:00
|
|
|
check := &MachineSecretCheckFailedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(check)
|
2023-01-31 19:52:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "USER-x7901b1l", "unable to unmarshal machine secret check failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
return check, nil
|
|
|
|
}
|