zitadel/internal/v2/user/machine_secret_set.go
Silvan 12be21a3ff
refactor(v2): init events (#7823)
creates events structures for initial projections and read models
2024-05-23 06:36:08 +02:00

42 lines
1.3 KiB
Go

package user
import (
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/v2/eventstore"
"github.com/zitadel/zitadel/internal/zerrors"
)
type machineSecretSetPayload struct {
// New events only use EncodedHash. However, the ClientSecret field
// is preserved to handle events older than the switch to Passwap.
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
HashedSecret string `json:"hashedSecret,omitempty"`
}
type MachineSecretHashSetEvent eventstore.Event[machineSecretSetPayload]
const MachineSecretHashSetType = machinePrefix + ".secret.set"
var _ eventstore.TypeChecker = (*MachineSecretHashSetEvent)(nil)
// ActionType implements eventstore.Typer.
func (c *MachineSecretHashSetEvent) ActionType() string {
return MachineSecretHashSetType
}
func MachineSecretHashSetEventFromStorage(event *eventstore.StorageEvent) (e *MachineSecretHashSetEvent, _ error) {
if event.Type != e.ActionType() {
return nil, zerrors.ThrowInvalidArgument(nil, "USER-DzycT", "Errors.Invalid.Event.Type")
}
payload, err := eventstore.UnmarshalPayload[machineSecretSetPayload](event.Payload)
if err != nil {
return nil, err
}
return &MachineSecretHashSetEvent{
StorageEvent: event,
Payload: payload,
}, nil
}