mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-22 21:08:47 +00:00
feat: command layer implementation for AddZitadelProvider (#12020)
# Which Problems Are Solved This PR contains the command-layer implementation to add an instance IDP of the type `ZitadelProvider` # How the Problems Are Solved - Implementing `AddZitadelProvider` in AdminService - Adding the command-layer to create a `ZitadelProvider` and push `ZitadelIDPAddedEvent` # Additional Changes N/A # Additional Context - Related to https://github.com/zitadel/zitadel/issues/11823 - Follow-up for PR https://github.com/zitadel/zitadel/pull/12018 --------- Co-authored-by: Copilot <[email protected]>
This commit is contained in:
co-authored by
Copilot
parent
01fe34a526
commit
bb3b52dda3
@@ -0,0 +1,61 @@
|
||||
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:"-"`
|
||||
// todo (@grvijayan): will be added along with UpdateZitadelProvider changes
|
||||
}
|
||||
@@ -105,6 +105,7 @@ func init() {
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SAMLIDPAddedEventType, SAMLIDPAddedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SAMLIDPChangedEventType, SAMLIDPChangedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, IDPRemovedEventType, IDPRemovedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, ZitadelIDPAddedEventType, eventstore.GenericEventMapper[ZitadelIDPAddedEvent])
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, LoginPolicyIDPProviderAddedEventType, IdentityProviderAddedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, LoginPolicyIDPProviderRemovedEventType, IdentityProviderRemovedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, LoginPolicyIDPProviderCascadeRemovedEventType, IdentityProviderCascadeRemovedEventMapper)
|
||||
|
||||
@@ -38,6 +38,7 @@ const (
|
||||
SAMLIDPAddedEventType eventstore.EventType = "instance.idp.saml.added"
|
||||
SAMLIDPChangedEventType eventstore.EventType = "instance.idp.saml.changed"
|
||||
IDPRemovedEventType eventstore.EventType = "instance.idp.removed"
|
||||
ZitadelIDPAddedEventType eventstore.EventType = "instance.idp.zitadel.added"
|
||||
)
|
||||
|
||||
type OAuthIDPAddedEvent struct {
|
||||
@@ -1128,3 +1129,43 @@ func IDPRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
|
||||
return &IDPRemovedEvent{RemovedEvent: *e.(*idp.RemovedEvent)}, nil
|
||||
}
|
||||
|
||||
type ZitadelIDPAddedEvent struct {
|
||||
idp.ZitadelIDPAddedEvent
|
||||
}
|
||||
|
||||
func NewZitadelIDPAddedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
id,
|
||||
name,
|
||||
issuer,
|
||||
clientID string,
|
||||
clientSecret *crypto.CryptoValue,
|
||||
scopes []string,
|
||||
options idp.Options,
|
||||
instanceRolesInfo []idp.RolesInfo,
|
||||
) *ZitadelIDPAddedEvent {
|
||||
|
||||
return &ZitadelIDPAddedEvent{
|
||||
ZitadelIDPAddedEvent: *idp.NewZitadelIDPAddedEvent(
|
||||
eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
ZitadelIDPAddedEventType,
|
||||
),
|
||||
id,
|
||||
name,
|
||||
issuer,
|
||||
clientID,
|
||||
clientSecret,
|
||||
scopes,
|
||||
options,
|
||||
instanceRolesInfo,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ZitadelIDPAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
||||
e.BaseEvent = *event
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user