2023-03-08 10:17:28 +00:00
|
|
|
package idp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2023-03-08 10:17:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type GitHubIDPAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
ClientID string `json:"clientId,omitempty"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
Options
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGitHubIDPAddedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
clientID string,
|
|
|
|
clientSecret *crypto.CryptoValue,
|
|
|
|
scopes []string,
|
|
|
|
options Options,
|
|
|
|
) *GitHubIDPAddedEvent {
|
|
|
|
return &GitHubIDPAddedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
ID: id,
|
|
|
|
Name: name,
|
|
|
|
ClientID: clientID,
|
|
|
|
ClientSecret: clientSecret,
|
|
|
|
Scopes: scopes,
|
|
|
|
Options: options,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *GitHubIDPAddedEvent) Payload() interface{} {
|
2023-03-08 10:17:28 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *GitHubIDPAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-03-08 10:17:28 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func GitHubIDPAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-03-08 10:17:28 +00:00
|
|
|
e := &GitHubIDPAddedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2023-03-08 10:17:28 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "IDP-sdfs3", "unable to unmarshal event")
|
2023-03-08 10:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitHubIDPChangedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name *string `json:"name,omitempty"`
|
|
|
|
ClientID *string `json:"clientId,omitempty"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
OptionChanges
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGitHubIDPChangedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
id string,
|
|
|
|
changes []GitHubIDPChanges,
|
|
|
|
) (*GitHubIDPChangedEvent, error) {
|
|
|
|
if len(changes) == 0 {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "IDP-BH3dl", "Errors.NoChangesFound")
|
2023-03-08 10:17:28 +00:00
|
|
|
}
|
|
|
|
changedEvent := &GitHubIDPChangedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
ID: id,
|
|
|
|
}
|
|
|
|
for _, change := range changes {
|
|
|
|
change(changedEvent)
|
|
|
|
}
|
|
|
|
return changedEvent, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitHubIDPChanges func(*GitHubIDPChangedEvent)
|
|
|
|
|
|
|
|
func ChangeGitHubName(name string) func(*GitHubIDPChangedEvent) {
|
|
|
|
return func(e *GitHubIDPChangedEvent) {
|
|
|
|
e.Name = &name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func ChangeGitHubClientID(clientID string) func(*GitHubIDPChangedEvent) {
|
|
|
|
return func(e *GitHubIDPChangedEvent) {
|
|
|
|
e.ClientID = &clientID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubClientSecret(clientSecret *crypto.CryptoValue) func(*GitHubIDPChangedEvent) {
|
|
|
|
return func(e *GitHubIDPChangedEvent) {
|
|
|
|
e.ClientSecret = clientSecret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubOptions(options OptionChanges) func(*GitHubIDPChangedEvent) {
|
|
|
|
return func(e *GitHubIDPChangedEvent) {
|
|
|
|
e.OptionChanges = options
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubScopes(scopes []string) func(*GitHubIDPChangedEvent) {
|
|
|
|
return func(e *GitHubIDPChangedEvent) {
|
|
|
|
e.Scopes = scopes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *GitHubIDPChangedEvent) Payload() interface{} {
|
2023-03-08 10:17:28 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *GitHubIDPChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-03-08 10:17:28 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func GitHubIDPChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-03-08 10:17:28 +00:00
|
|
|
e := &GitHubIDPChangedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2023-03-08 10:17:28 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "IDP-Sfrth", "unable to unmarshal event")
|
2023-03-08 10:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitHubEnterpriseIDPAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
ClientID string `json:"clientId,omitempty"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
|
|
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
|
|
|
|
TokenEndpoint string `json:"tokenEndpoint,omitempty"`
|
|
|
|
UserEndpoint string `json:"userEndpoint,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
Options
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGitHubEnterpriseIDPAddedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
clientID string,
|
|
|
|
clientSecret *crypto.CryptoValue,
|
|
|
|
authorizationEndpoint,
|
|
|
|
tokenEndpoint,
|
|
|
|
userEndpoint string,
|
|
|
|
scopes []string,
|
|
|
|
options Options,
|
|
|
|
) *GitHubEnterpriseIDPAddedEvent {
|
|
|
|
return &GitHubEnterpriseIDPAddedEvent{
|
|
|
|
*base,
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
clientID,
|
|
|
|
clientSecret,
|
|
|
|
authorizationEndpoint,
|
|
|
|
tokenEndpoint,
|
|
|
|
userEndpoint,
|
|
|
|
scopes,
|
|
|
|
options,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *GitHubEnterpriseIDPAddedEvent) Payload() interface{} {
|
2023-03-08 10:17:28 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *GitHubEnterpriseIDPAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-03-08 10:17:28 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func GitHubEnterpriseIDPAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-03-08 10:17:28 +00:00
|
|
|
e := &GitHubEnterpriseIDPAddedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2023-03-08 10:17:28 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "IDP-sdfs3", "unable to unmarshal event")
|
2023-03-08 10:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitHubEnterpriseIDPChangedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name *string `json:"name,omitempty"`
|
|
|
|
ClientID *string `json:"clientId,omitempty"`
|
|
|
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
|
|
|
AuthorizationEndpoint *string `json:"authorizationEndpoint,omitempty"`
|
|
|
|
TokenEndpoint *string `json:"tokenEndpoint,omitempty"`
|
|
|
|
UserEndpoint *string `json:"userEndpoint,omitempty"`
|
|
|
|
Scopes []string `json:"scopes,omitempty"`
|
|
|
|
OptionChanges
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGitHubEnterpriseIDPChangedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
id string,
|
|
|
|
changes []GitHubEnterpriseIDPChanges,
|
|
|
|
) (*GitHubEnterpriseIDPChangedEvent, error) {
|
|
|
|
if len(changes) == 0 {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "IDP-JHKs9", "Errors.NoChangesFound")
|
2023-03-08 10:17:28 +00:00
|
|
|
}
|
|
|
|
changedEvent := &GitHubEnterpriseIDPChangedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
ID: id,
|
|
|
|
}
|
|
|
|
for _, change := range changes {
|
|
|
|
change(changedEvent)
|
|
|
|
}
|
|
|
|
return changedEvent, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitHubEnterpriseIDPChanges func(*GitHubEnterpriseIDPChangedEvent)
|
|
|
|
|
|
|
|
func ChangeGitHubEnterpriseName(name string) func(*GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
return func(e *GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
e.Name = &name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func ChangeGitHubEnterpriseClientID(clientID string) func(*GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
return func(e *GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
e.ClientID = &clientID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubEnterpriseClientSecret(clientSecret *crypto.CryptoValue) func(*GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
return func(e *GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
e.ClientSecret = clientSecret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubEnterpriseOptions(options OptionChanges) func(*GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
return func(e *GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
e.OptionChanges = options
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubEnterpriseAuthorizationEndpoint(authorizationEndpoint string) func(*GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
return func(e *GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
e.AuthorizationEndpoint = &authorizationEndpoint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubEnterpriseTokenEndpoint(tokenEndpoint string) func(*GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
return func(e *GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
e.TokenEndpoint = &tokenEndpoint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubEnterpriseUserEndpoint(userEndpoint string) func(*GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
return func(e *GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
e.UserEndpoint = &userEndpoint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangeGitHubEnterpriseScopes(scopes []string) func(*GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
return func(e *GitHubEnterpriseIDPChangedEvent) {
|
|
|
|
e.Scopes = scopes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *GitHubEnterpriseIDPChangedEvent) Payload() interface{} {
|
2023-03-08 10:17:28 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *GitHubEnterpriseIDPChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-03-08 10:17:28 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func GitHubEnterpriseIDPChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-03-08 10:17:28 +00:00
|
|
|
e := &GitHubEnterpriseIDPChangedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2023-03-08 10:17:28 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "IDP-ASf3r", "unable to unmarshal event")
|
2023-03-08 10:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|