mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:37:30 +00:00
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! added first event
This commit is contained in:
@@ -18,7 +18,7 @@ const (
|
|||||||
IDPTypeOAuth
|
IDPTypeOAuth
|
||||||
IDPTypeLDAP
|
IDPTypeLDAP
|
||||||
IDPTypeAzure
|
IDPTypeAzure
|
||||||
IDPTypeGitHub
|
IDPTypeGithub
|
||||||
IDPTypeGitHubEnterprise
|
IDPTypeGitHubEnterprise
|
||||||
IDPTypeGitLab
|
IDPTypeGitLab
|
||||||
IDPTypeGitLabSelfHosted
|
IDPTypeGitLabSelfHosted
|
||||||
@@ -93,7 +93,6 @@ type IDPOIDC struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type JWT struct {
|
type JWT struct {
|
||||||
IDPConfigID string `json:"idpConfigId"`
|
|
||||||
JWTEndpoint string `json:"jwtEndpoint,omitempty"`
|
JWTEndpoint string `json:"jwtEndpoint,omitempty"`
|
||||||
Issuer string `json:"issuer,omitempty"`
|
Issuer string `json:"issuer,omitempty"`
|
||||||
KeysEndpoint string `json:"keysEndpoint,omitempty"`
|
KeysEndpoint string `json:"keysEndpoint,omitempty"`
|
||||||
@@ -106,8 +105,6 @@ type IDPJWT struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OAuth struct {
|
type OAuth struct {
|
||||||
ID string `json:"id"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
ClientID string `json:"clientId,omitempty"`
|
ClientID string `json:"clientId,omitempty"`
|
||||||
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
ClientSecret *crypto.CryptoValue `json:"clientSecret,omitempty"`
|
||||||
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
|
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
|
||||||
@@ -133,8 +130,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Azure struct {
|
type Azure struct {
|
||||||
ID string `json:"id,omitempty"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
ClientID string `json:"client_id,omitempty"`
|
ClientID string `json:"client_id,omitempty"`
|
||||||
ClientSecret *crypto.CryptoValue `json:"client_secret,omitempty"`
|
ClientSecret *crypto.CryptoValue `json:"client_secret,omitempty"`
|
||||||
Scopes []string `json:"scopes,omitempty"`
|
Scopes []string `json:"scopes,omitempty"`
|
||||||
@@ -148,8 +143,6 @@ type IDPOAzureAD struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Google struct {
|
type Google struct {
|
||||||
ID string `json:"id"`
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
ClientID string `json:"clientId"`
|
ClientID string `json:"clientId"`
|
||||||
ClientSecret *crypto.CryptoValue `json:"clientSecret"`
|
ClientSecret *crypto.CryptoValue `json:"clientSecret"`
|
||||||
Scopes []string `json:"scopes,omitempty"`
|
Scopes []string `json:"scopes,omitempty"`
|
||||||
@@ -160,6 +153,17 @@ type IDPGoogle struct {
|
|||||||
Google
|
Google
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Github struct {
|
||||||
|
ClientID string `json:"clientId"`
|
||||||
|
ClientSecret *crypto.CryptoValue `json:"clientSecret"`
|
||||||
|
Scopes []string `json:"scopes,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type IDPGithub struct {
|
||||||
|
*IdentityProvider
|
||||||
|
Github
|
||||||
|
}
|
||||||
|
|
||||||
// IDPIdentifierCondition is used to help specify a single identity_provider,
|
// IDPIdentifierCondition is used to help specify a single identity_provider,
|
||||||
// it will either be used as the identity_provider ID or identity_provider name,
|
// it will either be used as the identity_provider ID or identity_provider name,
|
||||||
// as identity_provider can be identified either using (instanceID + OrgID + ID) OR (instanceID + OrgID + name)
|
// as identity_provider can be identified either using (instanceID + OrgID + ID) OR (instanceID + OrgID + name)
|
||||||
@@ -235,4 +239,5 @@ type IDProviderRepository interface {
|
|||||||
|
|
||||||
GetOAzureAD(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPOAzureAD, error)
|
GetOAzureAD(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPOAzureAD, error)
|
||||||
GetGoogle(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPGoogle, error)
|
GetGoogle(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPGoogle, error)
|
||||||
|
GetGithub(ctx context.Context, id IDPIdentifierCondition, instanceID string, orgID *string) (*IDPGithub, error)
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ func _IDPTypeNoOp() {
|
|||||||
_ = x[IDPTypeOAuth-(3)]
|
_ = x[IDPTypeOAuth-(3)]
|
||||||
_ = x[IDPTypeLDAP-(4)]
|
_ = x[IDPTypeLDAP-(4)]
|
||||||
_ = x[IDPTypeAzure-(5)]
|
_ = x[IDPTypeAzure-(5)]
|
||||||
_ = x[IDPTypeGitHub-(6)]
|
_ = x[IDPTypeGithub-(6)]
|
||||||
_ = x[IDPTypeGitHubEnterprise-(7)]
|
_ = x[IDPTypeGitHubEnterprise-(7)]
|
||||||
_ = x[IDPTypeGitLab-(8)]
|
_ = x[IDPTypeGitLab-(8)]
|
||||||
_ = x[IDPTypeGitLabSelfHosted-(9)]
|
_ = x[IDPTypeGitLabSelfHosted-(9)]
|
||||||
@@ -39,7 +39,7 @@ func _IDPTypeNoOp() {
|
|||||||
_ = x[IDPTypeSAML-(12)]
|
_ = x[IDPTypeSAML-(12)]
|
||||||
}
|
}
|
||||||
|
|
||||||
var _IDPTypeValues = []IDPType{IDPTypeUnspecified, IDPTypeOIDC, IDPTypeJWT, IDPTypeOAuth, IDPTypeLDAP, IDPTypeAzure, IDPTypeGitHub, IDPTypeGitHubEnterprise, IDPTypeGitLab, IDPTypeGitLabSelfHosted, IDPTypeGoogle, IDPTypeApple, IDPTypeSAML}
|
var _IDPTypeValues = []IDPType{IDPTypeUnspecified, IDPTypeOIDC, IDPTypeJWT, IDPTypeOAuth, IDPTypeLDAP, IDPTypeAzure, IDPTypeGithub, IDPTypeGitHubEnterprise, IDPTypeGitLab, IDPTypeGitLabSelfHosted, IDPTypeGoogle, IDPTypeApple, IDPTypeSAML}
|
||||||
|
|
||||||
var _IDPTypeNameToValueMap = map[string]IDPType{
|
var _IDPTypeNameToValueMap = map[string]IDPType{
|
||||||
_IDPTypeName[0:11]: IDPTypeUnspecified,
|
_IDPTypeName[0:11]: IDPTypeUnspecified,
|
||||||
@@ -54,8 +54,8 @@ var _IDPTypeNameToValueMap = map[string]IDPType{
|
|||||||
_IDPTypeLowerName[23:27]: IDPTypeLDAP,
|
_IDPTypeLowerName[23:27]: IDPTypeLDAP,
|
||||||
_IDPTypeName[27:32]: IDPTypeAzure,
|
_IDPTypeName[27:32]: IDPTypeAzure,
|
||||||
_IDPTypeLowerName[27:32]: IDPTypeAzure,
|
_IDPTypeLowerName[27:32]: IDPTypeAzure,
|
||||||
_IDPTypeName[32:38]: IDPTypeGitHub,
|
_IDPTypeName[32:38]: IDPTypeGithub,
|
||||||
_IDPTypeLowerName[32:38]: IDPTypeGitHub,
|
_IDPTypeLowerName[32:38]: IDPTypeGithub,
|
||||||
_IDPTypeName[38:54]: IDPTypeGitHubEnterprise,
|
_IDPTypeName[38:54]: IDPTypeGitHubEnterprise,
|
||||||
_IDPTypeLowerName[38:54]: IDPTypeGitHubEnterprise,
|
_IDPTypeLowerName[38:54]: IDPTypeGitHubEnterprise,
|
||||||
_IDPTypeName[54:60]: IDPTypeGitLab,
|
_IDPTypeName[54:60]: IDPTypeGitLab,
|
||||||
|
@@ -405,7 +405,6 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
|
|||||||
assert.Equal(t, domain.IDPTypeJWT.String(), jwt.Type)
|
assert.Equal(t, domain.IDPTypeJWT.String(), jwt.Type)
|
||||||
|
|
||||||
// jwt
|
// jwt
|
||||||
assert.Equal(t, addJWT.IdpId, jwt.IDPConfigID)
|
|
||||||
assert.Equal(t, "jwtEndpoint", jwt.JWTEndpoint)
|
assert.Equal(t, "jwtEndpoint", jwt.JWTEndpoint)
|
||||||
assert.Equal(t, "issuer", jwt.Issuer)
|
assert.Equal(t, "issuer", jwt.Issuer)
|
||||||
assert.Equal(t, "keyEndpoint", jwt.KeysEndpoint)
|
assert.Equal(t, "keyEndpoint", jwt.KeysEndpoint)
|
||||||
@@ -443,7 +442,6 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
|
|||||||
assert.Equal(t, domain.IDPTypeJWT.String(), jwt.Type)
|
assert.Equal(t, domain.IDPTypeJWT.String(), jwt.Type)
|
||||||
|
|
||||||
// jwt
|
// jwt
|
||||||
assert.Equal(t, addJWT.IdpId, jwt.IDPConfigID)
|
|
||||||
assert.Equal(t, "jwtEndpoint", jwt.JWTEndpoint)
|
assert.Equal(t, "jwtEndpoint", jwt.JWTEndpoint)
|
||||||
assert.Equal(t, "issuer", jwt.Issuer)
|
assert.Equal(t, "issuer", jwt.Issuer)
|
||||||
assert.Equal(t, "keyEndpoint", jwt.KeysEndpoint)
|
assert.Equal(t, "keyEndpoint", jwt.KeysEndpoint)
|
||||||
@@ -476,7 +474,6 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
|
|||||||
assert.WithinRange(t, updateJWT.UpdatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, updateJWT.UpdatedAt, beforeCreate, afterCreate)
|
||||||
|
|
||||||
// jwt
|
// jwt
|
||||||
assert.Equal(t, addJWT.IdpId, updateJWT.IDPConfigID)
|
|
||||||
assert.Equal(t, "new_jwtEndpoint", updateJWT.JWTEndpoint)
|
assert.Equal(t, "new_jwtEndpoint", updateJWT.JWTEndpoint)
|
||||||
assert.Equal(t, "new_issuer", updateJWT.Issuer)
|
assert.Equal(t, "new_issuer", updateJWT.Issuer)
|
||||||
assert.Equal(t, "new_keyEndpoint", updateJWT.KeysEndpoint)
|
assert.Equal(t, "new_keyEndpoint", updateJWT.KeysEndpoint)
|
||||||
@@ -1095,8 +1092,8 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
|
|||||||
|
|
||||||
// event instance.idp.azure.added
|
// event instance.idp.azure.added
|
||||||
// idp
|
// idp
|
||||||
assert.Equal(t, addAzure.Id, azure.IdentityProvider.ID)
|
assert.Equal(t, addAzure.Id, azure.ID)
|
||||||
assert.Equal(t, name, azure.IdentityProvider.Name)
|
assert.Equal(t, name, azure.Name)
|
||||||
|
|
||||||
assert.Equal(t, "clientId", azure.ClientID)
|
assert.Equal(t, "clientId", azure.ClientID)
|
||||||
assert.NotNil(t, azure.ClientSecret)
|
assert.NotNil(t, azure.ClientSecret)
|
||||||
@@ -1147,6 +1144,7 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
|
|||||||
assert.Equal(t, addAzure.Id, azure.IdentityProvider.ID)
|
assert.Equal(t, addAzure.Id, azure.IdentityProvider.ID)
|
||||||
}, retryDuration, tick)
|
}, retryDuration, tick)
|
||||||
|
|
||||||
|
name = "new_" + name
|
||||||
// change azure
|
// change azure
|
||||||
beforeCreate := time.Now().Add(-1 * time.Second)
|
beforeCreate := time.Now().Add(-1 * time.Second)
|
||||||
_, err = AdminClient.UpdateAzureADProvider(CTX, &admin.UpdateAzureADProviderRequest{
|
_, err = AdminClient.UpdateAzureADProvider(CTX, &admin.UpdateAzureADProviderRequest{
|
||||||
@@ -1196,4 +1194,122 @@ func TestServer_TestIDProviderReduces(t *testing.T) {
|
|||||||
assert.WithinRange(t, updateAzure.UpdatedAt, beforeCreate, afterCreate)
|
assert.WithinRange(t, updateAzure.UpdatedAt, beforeCreate, afterCreate)
|
||||||
}, retryDuration, tick)
|
}, retryDuration, tick)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("test instance idp github added reduces", func(t *testing.T) {
|
||||||
|
name := gofakeit.Name()
|
||||||
|
|
||||||
|
// add github
|
||||||
|
beforeCreate := time.Now()
|
||||||
|
addGithub, err := AdminClient.AddGitHubProvider(CTX, &admin.AddGitHubProviderRequest{
|
||||||
|
Name: name,
|
||||||
|
ClientId: "clientId",
|
||||||
|
ClientSecret: "clientSecret",
|
||||||
|
Scopes: []string{"scope"},
|
||||||
|
ProviderOptions: &idp_grpc.Options{
|
||||||
|
IsLinkingAllowed: false,
|
||||||
|
IsCreationAllowed: false,
|
||||||
|
IsAutoCreation: false,
|
||||||
|
IsAutoUpdate: false,
|
||||||
|
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
afterCreate := time.Now()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
idpRepo := repository.IDProviderRepository(pool)
|
||||||
|
|
||||||
|
// check values for github
|
||||||
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Second*5)
|
||||||
|
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||||
|
github, err := idpRepo.GetGithub(CTX, idpRepo.IDCondition(addGithub.Id), instanceID, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// event instance.idp.github.added
|
||||||
|
// idp
|
||||||
|
assert.Equal(t, addGithub.Id, github.ID)
|
||||||
|
assert.Equal(t, name, github.Name)
|
||||||
|
|
||||||
|
assert.Equal(t, "clientId", github.ClientID)
|
||||||
|
assert.NotNil(t, github.ClientSecret)
|
||||||
|
assert.Equal(t, domain.IDPTypeGithub.String(), github.Type)
|
||||||
|
assert.Equal(t, []string{"scope"}, github.Scopes)
|
||||||
|
assert.Equal(t, false, github.AllowLinking)
|
||||||
|
assert.Equal(t, false, github.AllowCreation)
|
||||||
|
assert.Equal(t, false, github.AllowAutoUpdate)
|
||||||
|
assert.Equal(t, domain.IDPAutoLinkingOptionUserName.String(), github.AllowAutoLinking)
|
||||||
|
assert.WithinRange(t, github.UpdatedAt, beforeCreate, afterCreate)
|
||||||
|
}, retryDuration, tick)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("test instance idp github changed reduces", func(t *testing.T) {
|
||||||
|
name := gofakeit.Name()
|
||||||
|
|
||||||
|
// add github
|
||||||
|
addGithub, err := AdminClient.AddGitHubProvider(CTX, &admin.AddGitHubProviderRequest{
|
||||||
|
Name: name,
|
||||||
|
ClientId: "clientId",
|
||||||
|
ClientSecret: "clientSecret",
|
||||||
|
Scopes: []string{"scope"},
|
||||||
|
ProviderOptions: &idp_grpc.Options{
|
||||||
|
IsLinkingAllowed: false,
|
||||||
|
IsCreationAllowed: false,
|
||||||
|
IsAutoCreation: false,
|
||||||
|
IsAutoUpdate: false,
|
||||||
|
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
idpRepo := repository.IDProviderRepository(pool)
|
||||||
|
|
||||||
|
var github *domain.IDPGithub
|
||||||
|
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Second*5)
|
||||||
|
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||||
|
github, err = idpRepo.GetGithub(CTX, idpRepo.IDCondition(addGithub.Id), instanceID, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, addGithub.Id, github.ID)
|
||||||
|
}, retryDuration, tick)
|
||||||
|
|
||||||
|
name = "new_" + name
|
||||||
|
// change github
|
||||||
|
beforeCreate := time.Now()
|
||||||
|
_, err = AdminClient.UpdateGitHubProvider(CTX, &admin.UpdateGitHubProviderRequest{
|
||||||
|
Id: addGithub.Id,
|
||||||
|
Name: name,
|
||||||
|
ClientId: "new_clientId",
|
||||||
|
ClientSecret: "new_clientSecret",
|
||||||
|
Scopes: []string{"new_scope"},
|
||||||
|
ProviderOptions: &idp_grpc.Options{
|
||||||
|
IsLinkingAllowed: true,
|
||||||
|
IsCreationAllowed: true,
|
||||||
|
IsAutoCreation: true,
|
||||||
|
IsAutoUpdate: true,
|
||||||
|
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
afterCreate := time.Now()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// check values for azure
|
||||||
|
retryDuration, tick = integration.WaitForAndTickWithMaxDuration(CTX, time.Second*5)
|
||||||
|
assert.EventuallyWithT(t, func(t *assert.CollectT) {
|
||||||
|
updateGithub, err := idpRepo.GetGithub(CTX, idpRepo.IDCondition(addGithub.Id), instanceID, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// event instance.idp.github.changed
|
||||||
|
// idp
|
||||||
|
assert.Equal(t, addGithub.Id, updateGithub.ID)
|
||||||
|
assert.Equal(t, name, updateGithub.Name)
|
||||||
|
|
||||||
|
assert.Equal(t, "new_clientId", updateGithub.ClientID)
|
||||||
|
assert.NotEqual(t, github.ClientSecret, updateGithub.ClientSecret)
|
||||||
|
assert.Equal(t, domain.IDPTypeGithub.String(), updateGithub.Type)
|
||||||
|
assert.Equal(t, []string{"new_scope"}, updateGithub.Scopes)
|
||||||
|
assert.Equal(t, true, updateGithub.AllowLinking)
|
||||||
|
assert.Equal(t, true, updateGithub.AllowCreation)
|
||||||
|
assert.Equal(t, true, updateGithub.AllowAutoUpdate)
|
||||||
|
assert.Equal(t, domain.IDPAutoLinkingOptionUserName.String(), updateGithub.AllowAutoLinking)
|
||||||
|
assert.WithinRange(t, updateGithub.UpdatedAt, beforeCreate, afterCreate)
|
||||||
|
}, retryDuration, tick)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@@ -229,6 +229,28 @@ func (i *idProvider) GetGoogle(ctx context.Context, id domain.IDPIdentifierCondi
|
|||||||
return idpGoogle, nil
|
return idpGoogle, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *idProvider) GetGithub(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID *string) (*domain.IDPGithub, error) {
|
||||||
|
idpGithub := &domain.IDPGithub{}
|
||||||
|
var err error
|
||||||
|
|
||||||
|
idpGithub.IdentityProvider, err = i.Get(ctx, id, instnaceID, orgID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if idpGithub.Type != domain.IDPTypeGithub.String() {
|
||||||
|
// TODO
|
||||||
|
return nil, errors.New("WRONG TYPE")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(*idpGithub.Payload), idpGithub)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return idpGithub, nil
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// columns
|
// columns
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
@@ -3,6 +3,7 @@ package projection
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/backend/v3/storage/database/dialect/postgres"
|
"github.com/zitadel/zitadel/backend/v3/storage/database/dialect/postgres"
|
||||||
"github.com/zitadel/zitadel/backend/v3/storage/database/repository"
|
"github.com/zitadel/zitadel/backend/v3/storage/database/repository"
|
||||||
@@ -115,14 +116,14 @@ func (p *idpTemplateRelationalProjection) Reducers() []handler.AggregateReducer
|
|||||||
Event: instance.AzureADIDPChangedEventType,
|
Event: instance.AzureADIDPChangedEventType,
|
||||||
Reduce: p.reduceAzureADIDPRelationalChanged,
|
Reduce: p.reduceAzureADIDPRelationalChanged,
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// Event: instance.GitHubIDPAddedEventType,
|
Event: instance.GitHubIDPAddedEventType,
|
||||||
// Reduce: p.reduceGitHubIDPAdded,
|
Reduce: p.reduceGitHubIDPRelationalAdded,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Event: instance.GitHubIDPChangedEventType,
|
Event: instance.GitHubIDPChangedEventType,
|
||||||
// Reduce: p.reduceGitHubIDPChanged,
|
Reduce: p.reduceGitHubIDPRelationalChanged,
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// Event: instance.GitHubEnterpriseIDPAddedEventType,
|
// Event: instance.GitHubEnterpriseIDPAddedEventType,
|
||||||
// Reduce: p.reduceGitHubEnterpriseIDPAdded,
|
// Reduce: p.reduceGitHubEnterpriseIDPAdded,
|
||||||
@@ -360,8 +361,6 @@ func (p *idpTemplateRelationalProjection) reduceOAuthIDPRelationalAdded(event ev
|
|||||||
}
|
}
|
||||||
|
|
||||||
oauth := domain.OAuth{
|
oauth := domain.OAuth{
|
||||||
ID: e.ID,
|
|
||||||
Name: e.Name,
|
|
||||||
ClientID: e.ClientID,
|
ClientID: e.ClientID,
|
||||||
ClientSecret: e.ClientSecret,
|
ClientSecret: e.ClientSecret,
|
||||||
AuthorizationEndpoint: e.AuthorizationEndpoint,
|
AuthorizationEndpoint: e.AuthorizationEndpoint,
|
||||||
@@ -425,7 +424,7 @@ func (p *idpTemplateRelationalProjection) reduceOAuthIDPRelationalChanged(event
|
|||||||
payload := &oauth.OAuth
|
payload := &oauth.OAuth
|
||||||
payloadChanged := reduceOAuthIDPRelationalChangedColumns(payload, &e.OAuthIDPChangedEvent)
|
payloadChanged := reduceOAuthIDPRelationalChangedColumns(payload, &e.OAuthIDPChangedEvent)
|
||||||
if payloadChanged {
|
if payloadChanged {
|
||||||
payload, err := json.Marshal(e)
|
payload, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -530,7 +529,7 @@ func (p *idpTemplateRelationalProjection) reduceOIDCIDPRelationalChanged(event e
|
|||||||
payload := &oidc.OIDC
|
payload := &oidc.OIDC
|
||||||
payloadChanged := reduceOIDCIDPRelationalChangedColumns(payload, &e.OIDCIDPChangedEvent)
|
payloadChanged := reduceOIDCIDPRelationalChangedColumns(payload, &e.OIDCIDPChangedEvent)
|
||||||
if payloadChanged {
|
if payloadChanged {
|
||||||
payload, err := json.Marshal(e)
|
payload, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -730,7 +729,7 @@ func (p *idpTemplateRelationalProjection) reduceJWTIDPRelationalChanged(event ev
|
|||||||
payload := &jwt.JWT
|
payload := &jwt.JWT
|
||||||
payloadChanged := reduceJWTIDPRelationalChangedColumns(payload, &e.JWTIDPChangedEvent)
|
payloadChanged := reduceJWTIDPRelationalChangedColumns(payload, &e.JWTIDPChangedEvent)
|
||||||
if payloadChanged {
|
if payloadChanged {
|
||||||
payload, err := json.Marshal(e)
|
payload, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1088,7 +1087,7 @@ func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(even
|
|||||||
payload := &oauth.Azure
|
payload := &oauth.Azure
|
||||||
payloadChanged := reduceAzureADIDPRelationalChangedColumns(payload, &e.AzureADIDPChangedEvent)
|
payloadChanged := reduceAzureADIDPRelationalChangedColumns(payload, &e.AzureADIDPChangedEvent)
|
||||||
if payloadChanged {
|
if payloadChanged {
|
||||||
payload, err := json.Marshal(e)
|
payload, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1105,37 +1104,9 @@ func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(even
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
), nil
|
), nil
|
||||||
|
|
||||||
// ops := make([]func(eventstore.Event) handler.Exec, 0, 2)
|
|
||||||
// ops = append(ops,
|
|
||||||
// handler.AddUpdateStatement(
|
|
||||||
// reduceIDPChangedTemplateColumns(idpEvent.Name, idpEvent.CreationDate(), idpEvent.Sequence(), idpEvent.OptionChanges),
|
|
||||||
// []handler.Condition{
|
|
||||||
// handler.NewCond(IDPTemplateIDCol, idpEvent.ID),
|
|
||||||
// handler.NewCond(IDPTemplateInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
// )
|
|
||||||
// if len(githubCols) > 0 {
|
|
||||||
// ops = append(ops,
|
|
||||||
// handler.AddUpdateStatement(
|
|
||||||
// githubCols,
|
|
||||||
// []handler.Condition{
|
|
||||||
// handler.NewCond(AzureADIDCol, idpEvent.ID),
|
|
||||||
// handler.NewCond(AzureADInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
|
||||||
// },
|
|
||||||
// handler.WithTableSuffix(IDPTemplateAzureADSuffix),
|
|
||||||
// ),
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return handler.NewMultiStatement(
|
|
||||||
// &idpEvent,
|
|
||||||
// ops...,
|
|
||||||
// ), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (p *idpTemplateProjection) reduceGitHubIDPAdded(event eventstore.Event) (*handler.Statement, error) {
|
func (p *idpTemplateRelationalProjection) reduceGitHubIDPRelationalAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// var idpEvent idp.GitHubIDPAddedEvent
|
// var idpEvent idp.GitHubIDPAddedEvent
|
||||||
// var idpOwnerType domain.IdentityProviderType
|
// var idpOwnerType domain.IdentityProviderType
|
||||||
// switch e := event.(type) {
|
// switch e := event.(type) {
|
||||||
@@ -1149,6 +1120,42 @@ func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(even
|
|||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPAddedEventType, instance.GitHubIDPAddedEventType})
|
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPAddedEventType, instance.GitHubIDPAddedEventType})
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
e, ok := event.(*instance.GitHubIDPAddedEvent)
|
||||||
|
if !ok {
|
||||||
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-x9a022b", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPAddedEventType, instance.GitHubIDPAddedEventType})
|
||||||
|
}
|
||||||
|
|
||||||
|
github := domain.Github{
|
||||||
|
ClientID: e.ClientID,
|
||||||
|
ClientSecret: e.ClientSecret,
|
||||||
|
Scopes: e.Scopes,
|
||||||
|
}
|
||||||
|
|
||||||
|
payload, err := json.Marshal(github)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return handler.NewMultiStatement(
|
||||||
|
e,
|
||||||
|
handler.AddCreateStatement(
|
||||||
|
[]handler.Column{
|
||||||
|
handler.NewCol(IDPTemplateIDCol, e.ID),
|
||||||
|
handler.NewCol(IDPTemplateInstanceIDCol, e.Aggregate().InstanceID),
|
||||||
|
handler.NewCol(IDPTemplateNameCol, e.Name),
|
||||||
|
handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeGithub.String()),
|
||||||
|
handler.NewCol(IDPTemplateStateCol, domain.IDPStateActive.String()),
|
||||||
|
handler.NewCol(IDPRelationalAllowCreationCol, e.IsCreationAllowed),
|
||||||
|
handler.NewCol(IDPRelationalAllowLinkingCol, e.IsLinkingAllowed),
|
||||||
|
handler.NewCol(IDPRelationalAllowAutoCreationCol, e.IsAutoCreation),
|
||||||
|
handler.NewCol(IDPRelationalAllowAutoUpdateCol, e.IsAutoUpdate),
|
||||||
|
handler.NewCol(IDPRelationalAllowAutoLinkingCol, domain.IDPAutoLinkingOption(e.AutoLinkingOption).String()),
|
||||||
|
handler.NewCol(CreatedAt, e.CreationDate()),
|
||||||
|
handler.NewCol(IDPRelationalPayloadCol, payload),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
), nil
|
||||||
|
|
||||||
// return handler.NewMultiStatement(
|
// return handler.NewMultiStatement(
|
||||||
// &idpEvent,
|
// &idpEvent,
|
||||||
// handler.AddCreateStatement(
|
// handler.AddCreateStatement(
|
||||||
@@ -1162,7 +1169,7 @@ func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(even
|
|||||||
// handler.NewCol(IDPTemplateStateCol, domain.IDPStateActive),
|
// handler.NewCol(IDPTemplateStateCol, domain.IDPStateActive),
|
||||||
// handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
|
// handler.NewCol(IDPTemplateNameCol, idpEvent.Name),
|
||||||
// handler.NewCol(IDPTemplateOwnerTypeCol, idpOwnerType),
|
// handler.NewCol(IDPTemplateOwnerTypeCol, idpOwnerType),
|
||||||
// handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeGitHub),
|
// handler.NewCol(IDPTemplateTypeCol, domain.IDPTypeGithub),
|
||||||
// handler.NewCol(IDPTemplateIsCreationAllowedCol, idpEvent.IsCreationAllowed),
|
// handler.NewCol(IDPTemplateIsCreationAllowedCol, idpEvent.IsCreationAllowed),
|
||||||
// handler.NewCol(IDPTemplateIsLinkingAllowedCol, idpEvent.IsLinkingAllowed),
|
// handler.NewCol(IDPTemplateIsLinkingAllowedCol, idpEvent.IsLinkingAllowed),
|
||||||
// handler.NewCol(IDPTemplateIsAutoCreationCol, idpEvent.IsAutoCreation),
|
// handler.NewCol(IDPTemplateIsAutoCreationCol, idpEvent.IsAutoCreation),
|
||||||
@@ -1181,7 +1188,7 @@ func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(even
|
|||||||
// handler.WithTableSuffix(IDPTemplateGitHubSuffix),
|
// handler.WithTableSuffix(IDPTemplateGitHubSuffix),
|
||||||
// ),
|
// ),
|
||||||
// ), nil
|
// ), nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (p *idpTemplateProjection) reduceGitHubEnterpriseIDPAdded(event eventstore.Event) (*handler.Statement, error) {
|
// func (p *idpTemplateProjection) reduceGitHubEnterpriseIDPAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// var idpEvent idp.GitHubEnterpriseIDPAddedEvent
|
// var idpEvent idp.GitHubEnterpriseIDPAddedEvent
|
||||||
@@ -1234,7 +1241,7 @@ func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(even
|
|||||||
// ), nil
|
// ), nil
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// func (p *idpTemplateProjection) reduceGitHubIDPChanged(event eventstore.Event) (*handler.Statement, error) {
|
func (p *idpTemplateRelationalProjection) reduceGitHubIDPRelationalChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// var idpEvent idp.GitHubIDPChangedEvent
|
// var idpEvent idp.GitHubIDPChangedEvent
|
||||||
// switch e := event.(type) {
|
// switch e := event.(type) {
|
||||||
// case *org.GitHubIDPChangedEvent:
|
// case *org.GitHubIDPChangedEvent:
|
||||||
@@ -1245,6 +1252,43 @@ func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(even
|
|||||||
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPChangedEventType, instance.GitHubIDPChangedEventType})
|
// return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPChangedEventType, instance.GitHubIDPChangedEventType})
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
e, ok := event.(*instance.GitHubIDPChangedEvent)
|
||||||
|
if !ok {
|
||||||
|
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-p1582ks", "reduce.wrong.event.type %v", []eventstore.EventType{org.GitHubIDPChangedEventType, instance.GitHubIDPChangedEventType})
|
||||||
|
}
|
||||||
|
|
||||||
|
github, err := p.idpRepo.GetGithub(context.Background(), p.idpRepo.IDCondition(e.ID), e.Agg.InstanceID, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
columns := make([]handler.Column, 0, 7)
|
||||||
|
reduceIDPRelationalChangedTemplateColumns(e.Name, e.OptionChanges, &columns)
|
||||||
|
|
||||||
|
payload := &github.Github
|
||||||
|
payloadChanged := reduceGitHubIDPRelationalChangedColumns(payload, &e.GitHubIDPChangedEvent)
|
||||||
|
if payloadChanged {
|
||||||
|
payload, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
columns = append(columns, handler.NewCol(IDPRelationalPayloadCol, payload))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("@@ >>>>>>>>>>>>>>>>>>>>>>>>>>>> *e.Name = %+v\n", *e.Name)
|
||||||
|
fmt.Println("@@ >>>>>>>>>>>>>>>>>>>>>>>>>>>> UPDATE GITHUB")
|
||||||
|
|
||||||
|
return handler.NewMultiStatement(
|
||||||
|
e,
|
||||||
|
handler.AddUpdateStatement(
|
||||||
|
columns,
|
||||||
|
[]handler.Condition{
|
||||||
|
handler.NewCond(IDPTemplateIDCol, e.ID),
|
||||||
|
handler.NewCond(IDPTemplateInstanceIDCol, e.Aggregate().InstanceID),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
), nil
|
||||||
|
|
||||||
// ops := make([]func(eventstore.Event) handler.Exec, 0, 2)
|
// ops := make([]func(eventstore.Event) handler.Exec, 0, 2)
|
||||||
// ops = append(ops,
|
// ops = append(ops,
|
||||||
// handler.AddUpdateStatement(
|
// handler.AddUpdateStatement(
|
||||||
@@ -1273,7 +1317,7 @@ func (p *idpTemplateRelationalProjection) reduceAzureADIDPRelationalChanged(even
|
|||||||
// &idpEvent,
|
// &idpEvent,
|
||||||
// ops...,
|
// ops...,
|
||||||
// ), nil
|
// ), nil
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (p *idpTemplateProjection) reduceGitHubEnterpriseIDPChanged(event eventstore.Event) (*handler.Statement, error) {
|
// func (p *idpTemplateProjection) reduceGitHubEnterpriseIDPChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||||
// var idpEvent idp.GitHubEnterpriseIDPChangedEvent
|
// var idpEvent idp.GitHubEnterpriseIDPChangedEvent
|
||||||
@@ -2391,3 +2435,20 @@ func reduceAzureADIDPRelationalChangedColumns(payload *domain.Azure, idpEvent *i
|
|||||||
}
|
}
|
||||||
return payloadChange
|
return payloadChange
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reduceGitHubIDPRelationalChangedColumns(payload *domain.Github, idpEvent *idp.GitHubIDPChangedEvent) bool {
|
||||||
|
payloadChange := false
|
||||||
|
if idpEvent.ClientID != nil {
|
||||||
|
payloadChange = true
|
||||||
|
payload.ClientID = *idpEvent.ClientID
|
||||||
|
}
|
||||||
|
if idpEvent.ClientSecret != nil {
|
||||||
|
payloadChange = true
|
||||||
|
payload.ClientSecret = idpEvent.ClientSecret
|
||||||
|
}
|
||||||
|
if idpEvent.Scopes != nil {
|
||||||
|
payloadChange = true
|
||||||
|
payload.Scopes = idpEvent.Scopes
|
||||||
|
}
|
||||||
|
return payloadChange
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user