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"
|
|
|
|
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
|
|
|
"github.com/zitadel/zitadel/internal/iam/repository/view"
|
|
|
|
iam_es_model "github.com/zitadel/zitadel/internal/iam/repository/view/model"
|
|
|
|
global_view "github.com/zitadel/zitadel/internal/view/repository"
|
2020-09-18 11:26:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
idpConfigTable = "auth.idp_configs"
|
|
|
|
)
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) IDPConfigByID(idpID, instanceID string) (*iam_es_model.IDPConfigView, error) {
|
|
|
|
return view.IDPByID(v.Db, idpConfigTable, idpID, instanceID)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetIDPConfigsByAggregateID(aggregateID, instanceID string) ([]*iam_es_model.IDPConfigView, error) {
|
|
|
|
return view.GetIDPConfigsByAggregateID(v.Db, idpConfigTable, aggregateID, instanceID)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) SearchIDPConfigs(request *iam_model.IDPConfigSearchRequest) ([]*iam_es_model.IDPConfigView, uint64, error) {
|
|
|
|
return view.SearchIDPs(v.Db, idpConfigTable, request)
|
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutIDPConfig(idp *iam_es_model.IDPConfigView, event *models.Event) error {
|
2020-09-18 11:26:28 +00:00
|
|
|
err := view.PutIDP(v.Db, idpConfigTable, idp)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedIDPConfigSequence(event)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) DeleteIDPConfig(idpID string, event *models.Event) error {
|
2022-04-19 06:26:12 +00:00
|
|
|
err := view.DeleteIDP(v.Db, idpConfigTable, idpID, event.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.ProcessedIDPConfigSequence(event)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 13:06:48 +00:00
|
|
|
func (v *View) DeleteInstanceIDPs(event *models.Event) error {
|
|
|
|
err := view.DeleteInstanceIDPs(v.Db, idpConfigTable, event.InstanceID)
|
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedIDPConfigSequence(event)
|
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetLatestIDPConfigSequence(instanceID string) (*global_view.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(idpConfigTable, instanceID)
|
|
|
|
}
|
|
|
|
|
2022-11-22 06:36:48 +00:00
|
|
|
func (v *View) GetLatestIDPConfigSequences(instanceIDs []string) ([]*global_view.CurrentSequence, error) {
|
|
|
|
return v.latestSequences(idpConfigTable, instanceIDs)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) ProcessedIDPConfigSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(idpConfigTable, event)
|
2020-12-02 07:50:59 +00:00
|
|
|
}
|
|
|
|
|
2022-11-22 06:36:48 +00:00
|
|
|
func (v *View) UpdateIDPConfigSpoolerRunTimestamp(instanceIDs []string) error {
|
|
|
|
return v.updateSpoolerRunSequence(idpConfigTable, instanceIDs)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetLatestIDPConfigFailedEvent(sequence uint64, instanceID string) (*global_view.FailedEvent, error) {
|
|
|
|
return v.latestFailedEvent(idpConfigTable, instanceID, sequence)
|
2020-09-18 11:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) ProcessedIDPConfigFailedEvent(failedEvent *global_view.FailedEvent) error {
|
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|