2020-09-18 11:26:28 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
|
|
"github.com/zitadel/zitadel/internal/user/repository/view"
|
|
|
|
"github.com/zitadel/zitadel/internal/user/repository/view/model"
|
|
|
|
global_view "github.com/zitadel/zitadel/internal/view/repository"
|
2020-09-18 11:26:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
externalIDPTable = "auth.user_external_idps"
|
|
|
|
)
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) ExternalIDPByExternalUserIDAndIDPConfigID(externalUserID, idpConfigID, instanceID string) (*model.ExternalIDPView, error) {
|
|
|
|
return view.ExternalIDPByExternalUserIDAndIDPConfigID(v.Db, externalIDPTable, externalUserID, idpConfigID, instanceID)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) ExternalIDPByExternalUserIDAndIDPConfigIDAndResourceOwner(externalUserID, idpConfigID, resourceOwner, instanceID string) (*model.ExternalIDPView, error) {
|
|
|
|
return view.ExternalIDPByExternalUserIDAndIDPConfigIDAndResourceOwner(v.Db, externalIDPTable, externalUserID, idpConfigID, resourceOwner, instanceID)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) ExternalIDPsByIDPConfigID(idpConfigID, instanceID string) ([]*model.ExternalIDPView, error) {
|
|
|
|
return view.ExternalIDPsByIDPConfigID(v.Db, externalIDPTable, idpConfigID, instanceID)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutExternalIDP(externalIDP *model.ExternalIDPView, event *models.Event) error {
|
2020-09-18 11:26:28 +00:00
|
|
|
err := view.PutExternalIDP(v.Db, externalIDPTable, externalIDP)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedExternalIDPSequence(event)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutExternalIDPs(event *models.Event, externalIDPs ...*model.ExternalIDPView) error {
|
2020-09-18 11:26:28 +00:00
|
|
|
err := view.PutExternalIDPs(v.Db, externalIDPTable, externalIDPs...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedExternalIDPSequence(event)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) DeleteExternalIDP(externalUserID, idpConfigID, instanceID string, event *models.Event) error {
|
|
|
|
err := view.DeleteExternalIDP(v.Db, externalIDPTable, externalUserID, idpConfigID, instanceID)
|
2020-09-18 11:26:28 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedExternalIDPSequence(event)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) DeleteExternalIDPsByUserID(userID, instanceID string, event *models.Event) error {
|
|
|
|
err := view.DeleteExternalIDPsByUserID(v.Db, externalIDPTable, userID, instanceID)
|
2020-10-07 06:16:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedExternalIDPSequence(event)
|
2020-10-07 06:16:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetLatestExternalIDPSequence(instanceID string) (*global_view.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(externalIDPTable, instanceID)
|
|
|
|
}
|
|
|
|
|
2022-07-22 10:08:39 +00:00
|
|
|
func (v *View) GetLatestExternalIDPSequences(instanceIDs ...string) ([]*global_view.CurrentSequence, error) {
|
|
|
|
return v.latestSequences(externalIDPTable, instanceIDs...)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) ProcessedExternalIDPSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(externalIDPTable, event)
|
2020-12-02 07:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UpdateExternalIDPSpoolerRunTimestamp() error {
|
|
|
|
return v.updateSpoolerRunSequence(externalIDPTable)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetLatestExternalIDPFailedEvent(sequence uint64, instanceID string) (*global_view.FailedEvent, error) {
|
|
|
|
return v.latestFailedEvent(externalIDPTable, instanceID, sequence)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) ProcessedExternalIDPFailedEvent(failedEvent *global_view.FailedEvent) error {
|
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|