zitadel/internal/repository/idp/apple.go
Tim Möhlmann f680dd934d
refactor: rename package errors to zerrors (#7039)
* chore: rename package errors to zerrors

* rename package errors to gerrors

* fix error related linting issues

* fix zitadel error assertion

* fix gosimple linting issues

* fix deprecated linting issues

* resolve gci linting issues

* fix import structure

---------

Co-authored-by: Elio Bischof <elio@zitadel.com>
2023-12-08 15:30:55 +01:00

162 lines
3.8 KiB
Go

package idp
import (
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/zerrors"
)
type AppleIDPAddedEvent struct {
eventstore.BaseEvent `json:"-"`
ID string `json:"id"`
Name string `json:"name,omitempty"`
ClientID string `json:"clientId"`
TeamID string `json:"teamId"`
KeyID string `json:"keyId"`
PrivateKey *crypto.CryptoValue `json:"privateKey"`
Scopes []string `json:"scopes,omitempty"`
Options
}
func NewAppleIDPAddedEvent(
base *eventstore.BaseEvent,
id,
name,
clientID,
teamID,
keyID string,
privateKey *crypto.CryptoValue,
scopes []string,
options Options,
) *AppleIDPAddedEvent {
return &AppleIDPAddedEvent{
BaseEvent: *base,
ID: id,
Name: name,
ClientID: clientID,
TeamID: teamID,
KeyID: keyID,
PrivateKey: privateKey,
Scopes: scopes,
Options: options,
}
}
func (e *AppleIDPAddedEvent) Payload() interface{} {
return e
}
func (e *AppleIDPAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func AppleIDPAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &AppleIDPAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := event.Unmarshal(e)
if err != nil {
return nil, zerrors.ThrowInternal(err, "IDP-Beqss", "unable to unmarshal event")
}
return e, nil
}
type AppleIDPChangedEvent struct {
eventstore.BaseEvent `json:"-"`
ID string `json:"id"`
Name *string `json:"name,omitempty"`
ClientID *string `json:"clientId,omitempty"`
TeamID *string `json:"teamId,omitempty"`
KeyID *string `json:"keyId,omitempty"`
PrivateKey *crypto.CryptoValue `json:"privateKey,omitempty"`
Scopes []string `json:"scopes,omitempty"`
OptionChanges
}
func NewAppleIDPChangedEvent(
base *eventstore.BaseEvent,
id string,
changes []AppleIDPChanges,
) (*AppleIDPChangedEvent, error) {
if len(changes) == 0 {
return nil, zerrors.ThrowPreconditionFailed(nil, "IDP-SF3h2", "Errors.NoChangesFound")
}
changedEvent := &AppleIDPChangedEvent{
BaseEvent: *base,
ID: id,
}
for _, change := range changes {
change(changedEvent)
}
return changedEvent, nil
}
type AppleIDPChanges func(*AppleIDPChangedEvent)
func ChangeAppleName(name string) func(*AppleIDPChangedEvent) {
return func(e *AppleIDPChangedEvent) {
e.Name = &name
}
}
func ChangeAppleClientID(clientID string) func(*AppleIDPChangedEvent) {
return func(e *AppleIDPChangedEvent) {
e.ClientID = &clientID
}
}
func ChangeAppleTeamID(teamID string) func(*AppleIDPChangedEvent) {
return func(e *AppleIDPChangedEvent) {
e.TeamID = &teamID
}
}
func ChangeAppleKeyID(keyID string) func(*AppleIDPChangedEvent) {
return func(e *AppleIDPChangedEvent) {
e.KeyID = &keyID
}
}
func ChangeApplePrivateKey(privateKey *crypto.CryptoValue) func(*AppleIDPChangedEvent) {
return func(e *AppleIDPChangedEvent) {
e.PrivateKey = privateKey
}
}
func ChangeAppleScopes(scopes []string) func(*AppleIDPChangedEvent) {
return func(e *AppleIDPChangedEvent) {
e.Scopes = scopes
}
}
func ChangeAppleOptions(options OptionChanges) func(*AppleIDPChangedEvent) {
return func(e *AppleIDPChangedEvent) {
e.OptionChanges = options
}
}
func (e *AppleIDPChangedEvent) Payload() interface{} {
return e
}
func (e *AppleIDPChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func AppleIDPChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &AppleIDPChangedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := event.Unmarshal(e)
if err != nil {
return nil, zerrors.ThrowInternal(err, "IDP-NBe1s", "unable to unmarshal event")
}
return e, nil
}