Files
zitadel/internal/repository/idp/zitadel.go
T
653a968d91 feat: implement instance-level UpdateZitadelProvider (#12378)
# Which Problems Are Solved

This PR implements the instance-level `UpdateZitadelProvider` endpoint,
enabling updates to existing instance Zitadel IdP templates.

# How the Problems Are Solved

- Added `AdminService.UpdateZitadelProvider` handler, converter
- Added the command-layer implementation to update a ZitadelProvider and
push `instance.idp.zitadel.changed` event
- Added projection-layer implementation to persist Zitadel provider
updates into `projections.idp_templates6_zitadel`
- Added unit and integration tests


# Additional Changes
N/A

# Additional Context
Related to https://github.com/zitadel/zitadel/issues/11922
Follow-up for PRs:
- https://github.com/zitadel/zitadel/pull/12018
- https://github.com/zitadel/zitadel/pull/12020
- https://github.com/zitadel/zitadel/pull/12055
- https://github.com/zitadel/zitadel/pull/12056
- https://github.com/zitadel/zitadel/pull/12371

---------

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
2026-07-06 10:18:35 +02:00

145 lines
3.7 KiB
Go

package idp
import (
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/eventstore"
)
type RolesInfo struct {
OrganizationID string `json:"organizationId"`
OrganizationDomain string `json:"organizationDomain"`
}
type ZitadelIDPAddedEvent struct {
eventstore.BaseEvent `json:"-"`
ID string `json:"id"`
Name string `json:"name"`
Issuer string `json:"issuer"`
ClientID string `json:"clientId"`
ClientSecret *crypto.CryptoValue `json:"clientSecret"`
Scopes []string `json:"scopes,omitempty"`
InstanceRolesInfo []RolesInfo `json:"instanceRolesInfo,omitempty"`
Options
}
func NewZitadelIDPAddedEvent(
base *eventstore.BaseEvent,
id,
name,
issuer,
clientID string,
clientSecret *crypto.CryptoValue,
scopes []string,
options Options,
instanceRolesInfo []RolesInfo,
) *ZitadelIDPAddedEvent {
return &ZitadelIDPAddedEvent{
BaseEvent: *base,
ID: id,
Name: name,
Issuer: issuer,
ClientID: clientID,
ClientSecret: clientSecret,
Scopes: scopes,
Options: options,
InstanceRolesInfo: instanceRolesInfo,
}
}
func (e *ZitadelIDPAddedEvent) Payload() interface{} {
return e
}
func (e *ZitadelIDPAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
type ZitadelIDPChangedEvent struct {
eventstore.BaseEvent `json:"-"`
ID string `json:"id"`
Name *string `json:"name,omitempty"`
Issuer *string `json:"issuer,omitempty"`
ClientID *string `json:"clientId,omitempty"`
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
Scopes *[]string `json:"scopes,omitempty"`
InstanceRolesInfo *[]RolesInfo `json:"instanceRolesInfo,omitempty"`
OptionChanges
}
func NewZitadelIDPChangedEvent(
base *eventstore.BaseEvent,
id string,
changes []ZitadelIDPChanges,
) *ZitadelIDPChangedEvent {
e := &ZitadelIDPChangedEvent{
BaseEvent: *base,
ID: id,
}
for _, change := range changes {
change(e)
}
return e
}
type ZitadelIDPChanges func(*ZitadelIDPChangedEvent)
func ChangeZitadelIDPName(name string) ZitadelIDPChanges {
return func(e *ZitadelIDPChangedEvent) {
e.Name = &name
}
}
func ChangeZitadelIDPIssuer(issuer string) ZitadelIDPChanges {
return func(e *ZitadelIDPChangedEvent) {
e.Issuer = &issuer
}
}
func ChangeZitadelIDPClientID(clientID string) ZitadelIDPChanges {
return func(e *ZitadelIDPChangedEvent) {
e.ClientID = &clientID
}
}
func ChangeZitadelIDPClientSecret(clientSecret *crypto.CryptoValue) ZitadelIDPChanges {
return func(e *ZitadelIDPChangedEvent) {
e.ClientSecret = clientSecret
}
}
func ChangeZitadelIDPScopes(scopes []string) ZitadelIDPChanges {
return func(e *ZitadelIDPChangedEvent) {
// explicitly set them to empty in case the scopes are unset
if scopes == nil {
scopes = make([]string, 0)
}
e.Scopes = &scopes
}
}
func ChangeZitadelIDPInstanceRolesInfo(instanceRolesInfo []RolesInfo) ZitadelIDPChanges {
return func(e *ZitadelIDPChangedEvent) {
// explicitly set them to empty in case the instance roles are unset
if instanceRolesInfo == nil {
instanceRolesInfo = make([]RolesInfo, 0)
}
e.InstanceRolesInfo = &instanceRolesInfo
}
}
func ChangeZitadelIDPOptions(options OptionChanges) ZitadelIDPChanges {
return func(e *ZitadelIDPChangedEvent) {
e.OptionChanges = options
}
}
func (e *ZitadelIDPChangedEvent) Payload() interface{} {
return e
}
func (e *ZitadelIDPChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}