mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 13:19:21 +00:00
changed idp repo interface to use a pointer for orgID
This commit is contained in:
@@ -101,10 +101,10 @@ type IDProviderRepository interface {
|
||||
idProviderConditions
|
||||
idProviderChanges
|
||||
|
||||
Get(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID string) (*IdentityProvider, error)
|
||||
Get(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID *string) (*IdentityProvider, error)
|
||||
List(ctx context.Context, conditions ...database.Condition) ([]*IdentityProvider, error)
|
||||
|
||||
Create(ctx context.Context, idp *IdentityProvider) error
|
||||
Update(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID string, changes ...database.Change) (int64, error)
|
||||
Delete(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID string) (int64, error)
|
||||
Update(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID *string, changes ...database.Change) (int64, error)
|
||||
Delete(ctx context.Context, id IDPIdentifierCondition, instnaceID string, orgID *string) (int64, error)
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
CREATE TYPE idp_state AS ENUM (
|
||||
CREATE TYPE zitadel.idp_state AS ENUM (
|
||||
'active',
|
||||
'inactive'
|
||||
);
|
||||
|
||||
CREATE TYPE idp_type AS ENUM (
|
||||
CREATE TYPE zitadel.idp_type AS ENUM (
|
||||
'oidc',
|
||||
'oauth',
|
||||
'saml',
|
||||
@@ -18,9 +18,9 @@ CREATE TABLE zitadel.identity_providers (
|
||||
instance_id TEXT NOT NULL
|
||||
, org_id TEXT
|
||||
, id TEXT NOT NULL CHECK (id <> '')
|
||||
, state idp_state NOT NULL DEFAULT 'active'
|
||||
, state zitadel.idp_state NOT NULL DEFAULT 'active'
|
||||
, name TEXT NOT NULL CHECK (name <> '')
|
||||
, type idp_type NOT NULL
|
||||
, type zitadel.idp_type NOT NULL
|
||||
, allow_creation BOOLEAN NOT NULL DEFAULT TRUE
|
||||
, allow_auto_creation BOOLEAN NOT NULL DEFAULT TRUE
|
||||
, allow_auto_update BOOLEAN NOT NULL DEFAULT TRUE
|
||||
|
@@ -26,12 +26,12 @@ const queryIDProviderStmt = `SELECT instance_id, org_id, id, state, name, type,
|
||||
` allow_auto_update, allow_linking, styling_type, payload, created_at, updated_at` +
|
||||
` FROM zitadel.identity_providers`
|
||||
|
||||
func (i *idProvider) Get(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID string) (*domain.IdentityProvider, error) {
|
||||
func (i *idProvider) Get(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID *string) (*domain.IdentityProvider, error) {
|
||||
builder := database.StatementBuilder{}
|
||||
|
||||
builder.WriteString(queryIDProviderStmt)
|
||||
|
||||
conditions := []database.Condition{id, i.InstanceIDCondition(instnaceID), i.OrgIDCondition(orgID)}
|
||||
conditions := []database.Condition{id, i.InstanceIDCondition(instnaceID), i.OrgIDCondition(*orgID)}
|
||||
|
||||
writeCondition(&builder, database.And(conditions...))
|
||||
|
||||
@@ -83,7 +83,7 @@ func (i *idProvider) Create(ctx context.Context, idp *domain.IdentityProvider) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *idProvider) Update(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID string, changes ...database.Change) (int64, error) {
|
||||
func (i *idProvider) Update(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID *string, changes ...database.Change) (int64, error) {
|
||||
if changes == nil {
|
||||
return 0, errors.New("Update must contain at least one change")
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (i *idProvider) Update(ctx context.Context, id domain.IDPIdentifierConditio
|
||||
conditions := []database.Condition{
|
||||
id,
|
||||
i.InstanceIDCondition(instnaceID),
|
||||
i.OrgIDCondition(orgID),
|
||||
i.OrgIDCondition(*orgID),
|
||||
}
|
||||
database.Changes(changes).Write(&builder)
|
||||
writeCondition(&builder, database.And(conditions...))
|
||||
@@ -103,7 +103,7 @@ func (i *idProvider) Update(ctx context.Context, id domain.IDPIdentifierConditio
|
||||
return i.client.Exec(ctx, stmt, builder.Args()...)
|
||||
}
|
||||
|
||||
func (i *idProvider) Delete(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID string) (int64, error) {
|
||||
func (i *idProvider) Delete(ctx context.Context, id domain.IDPIdentifierCondition, instnaceID string, orgID *string) (int64, error) {
|
||||
builder := database.StatementBuilder{}
|
||||
|
||||
builder.WriteString(`DELETE FROM zitadel.identity_providers`)
|
||||
@@ -111,7 +111,7 @@ func (i *idProvider) Delete(ctx context.Context, id domain.IDPIdentifierConditio
|
||||
conditions := []database.Condition{
|
||||
id,
|
||||
i.InstanceIDCondition(instnaceID),
|
||||
i.OrgIDCondition(orgID),
|
||||
i.OrgIDCondition(*orgID),
|
||||
}
|
||||
writeCondition(&builder, database.And(conditions...))
|
||||
|
||||
|
@@ -330,7 +330,7 @@ func TestCreateIDProvider(t *testing.T) {
|
||||
idp, err = idpRepo.Get(ctx,
|
||||
idpRepo.IDCondition(idp.ID),
|
||||
idp.InstanceID,
|
||||
idp.OrgID,
|
||||
&idp.OrgID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -585,7 +585,7 @@ func TestUpdateIDProvider(t *testing.T) {
|
||||
rowsAffected, err := idpRepo.Update(ctx,
|
||||
idpRepo.IDCondition(createdIDP.ID),
|
||||
createdIDP.InstanceID,
|
||||
createdIDP.OrgID,
|
||||
&createdIDP.OrgID,
|
||||
tt.update...,
|
||||
)
|
||||
afterUpdate := time.Now()
|
||||
@@ -601,7 +601,7 @@ func TestUpdateIDProvider(t *testing.T) {
|
||||
idp, err := idpRepo.Get(ctx,
|
||||
organizationRepo.IDCondition(createdIDP.ID),
|
||||
createdIDP.InstanceID,
|
||||
createdIDP.OrgID,
|
||||
&createdIDP.OrgID,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -848,7 +848,7 @@ func TestGetIDProvider(t *testing.T) {
|
||||
returnedIDP, err := idpRepo.Get(ctx,
|
||||
tt.idpIdentifierCondition,
|
||||
idp.InstanceID,
|
||||
idp.OrgID,
|
||||
&idp.OrgID,
|
||||
)
|
||||
if err != nil {
|
||||
require.ErrorIs(t, tt.err, err)
|
||||
@@ -1830,7 +1830,7 @@ func TestDeleteIDProvider(t *testing.T) {
|
||||
affectedRows, err := idpRepo.Delete(ctx,
|
||||
idpRepo.NameCondition(name),
|
||||
instanceId,
|
||||
orgId,
|
||||
&orgId,
|
||||
)
|
||||
assert.Equal(t, int64(1), affectedRows)
|
||||
require.NoError(t, err)
|
||||
@@ -1853,7 +1853,7 @@ func TestDeleteIDProvider(t *testing.T) {
|
||||
noOfDeletedRows, err := idpRepo.Delete(ctx,
|
||||
tt.idpIdentifierCondition,
|
||||
instanceId,
|
||||
orgId,
|
||||
&orgId,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, noOfDeletedRows, tt.noOfDeletedRows)
|
||||
@@ -1862,7 +1862,7 @@ func TestDeleteIDProvider(t *testing.T) {
|
||||
organization, err := idpRepo.Get(ctx,
|
||||
tt.idpIdentifierCondition,
|
||||
instanceId,
|
||||
orgId,
|
||||
&orgId,
|
||||
)
|
||||
require.ErrorIs(t, err, new(database.NoRowFoundError))
|
||||
assert.Nil(t, organization)
|
||||
|
Reference in New Issue
Block a user