zitadel/internal/repository/idp/jwt.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

151 lines
3.4 KiB
Go

package idp
import (
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/zerrors"
)
type JWTIDPAddedEvent struct {
eventstore.BaseEvent `json:"-"`
ID string `json:"id"`
Name string `json:"name,omitempty"`
Issuer string `json:"issuer,omitempty"`
JWTEndpoint string `json:"jwtEndpoint,omitempty"`
KeysEndpoint string `json:"keysEndpoint,omitempty"`
HeaderName string `json:"headerName,omitempty"`
Options
}
func NewJWTIDPAddedEvent(
base *eventstore.BaseEvent,
id,
name,
issuer,
jwtEndpoint,
keysEndpoint,
headerName string,
options Options,
) *JWTIDPAddedEvent {
return &JWTIDPAddedEvent{
BaseEvent: *base,
ID: id,
Name: name,
Issuer: issuer,
JWTEndpoint: jwtEndpoint,
KeysEndpoint: keysEndpoint,
HeaderName: headerName,
Options: options,
}
}
func (e *JWTIDPAddedEvent) Payload() interface{} {
return e
}
func (e *JWTIDPAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func JWTIDPAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &JWTIDPAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := event.Unmarshal(e)
if err != nil {
return nil, zerrors.ThrowInternal(err, "IDP-Et1dq", "unable to unmarshal event")
}
return e, nil
}
type JWTIDPChangedEvent struct {
eventstore.BaseEvent `json:"-"`
ID string `json:"id"`
Name *string `json:"name,omitempty"`
Issuer *string `json:"issuer,omitempty"`
JWTEndpoint *string `json:"jwtEndpoint,omitempty"`
KeysEndpoint *string `json:"keysEndpoint,omitempty"`
HeaderName *string `json:"headerName,omitempty"`
OptionChanges
}
func NewJWTIDPChangedEvent(
base *eventstore.BaseEvent,
id string,
changes []JWTIDPChanges,
) (*JWTIDPChangedEvent, error) {
if len(changes) == 0 {
return nil, zerrors.ThrowPreconditionFailed(nil, "IDP-BH3dl", "Errors.NoChangesFound")
}
changedEvent := &JWTIDPChangedEvent{
BaseEvent: *base,
ID: id,
}
for _, change := range changes {
change(changedEvent)
}
return changedEvent, nil
}
type JWTIDPChanges func(*JWTIDPChangedEvent)
func ChangeJWTName(name string) func(*JWTIDPChangedEvent) {
return func(e *JWTIDPChangedEvent) {
e.Name = &name
}
}
func ChangeJWTIssuer(issuer string) func(*JWTIDPChangedEvent) {
return func(e *JWTIDPChangedEvent) {
e.Issuer = &issuer
}
}
func ChangeJWTEndpoint(jwtEndpoint string) func(*JWTIDPChangedEvent) {
return func(e *JWTIDPChangedEvent) {
e.JWTEndpoint = &jwtEndpoint
}
}
func ChangeJWTKeysEndpoint(keysEndpoint string) func(*JWTIDPChangedEvent) {
return func(e *JWTIDPChangedEvent) {
e.KeysEndpoint = &keysEndpoint
}
}
func ChangeJWTHeaderName(headerName string) func(*JWTIDPChangedEvent) {
return func(e *JWTIDPChangedEvent) {
e.HeaderName = &headerName
}
}
func ChangeJWTOptions(options OptionChanges) func(*JWTIDPChangedEvent) {
return func(e *JWTIDPChangedEvent) {
e.OptionChanges = options
}
}
func (e *JWTIDPChangedEvent) Payload() interface{} {
return e
}
func (e *JWTIDPChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
func JWTIDPChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &JWTIDPChangedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := event.Unmarshal(e)
if err != nil {
return nil, zerrors.ThrowInternal(err, "IDP-D3gjzh", "unable to unmarshal event")
}
return e, nil
}