mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
88 lines
2.9 KiB
Go
88 lines
2.9 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/iam/model"
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
const (
|
|
IDPProviderKeyAggregateID = "aggregate_id"
|
|
IDPProviderKeyIdpConfigID = "idp_config_id"
|
|
IDPProviderKeyState = "idp_state"
|
|
IDPProviderKeyInstanceID = "instance_id"
|
|
IDPProviderKeyOwnerRemoved = "owner_removed"
|
|
)
|
|
|
|
type IDPProviderView struct {
|
|
AggregateID string `json:"-" gorm:"column:aggregate_id;primary_key"`
|
|
IDPConfigID string `json:"idpConfigID" gorm:"column:idp_config_id;primary_key"`
|
|
|
|
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
|
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
|
|
|
Name string `json:"-" gorm:"column:name"`
|
|
StylingType int32 `json:"-" gorm:"column:styling_type"`
|
|
IDPConfigType int32 `json:"-" gorm:"column:idp_config_type"`
|
|
IDPProviderType int32 `json:"idpProviderType" gorm:"column:idp_provider_type"`
|
|
IDPState int32 `json:"-" gorm:"column:idp_state"`
|
|
|
|
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
|
InstanceID string `json:"instanceID" gorm:"column:instance_id;primary_key"`
|
|
}
|
|
|
|
func IDPProviderViewToModel(provider *IDPProviderView) *model.IDPProviderView {
|
|
return &model.IDPProviderView{
|
|
AggregateID: provider.AggregateID,
|
|
Sequence: provider.Sequence,
|
|
CreationDate: provider.CreationDate,
|
|
ChangeDate: provider.ChangeDate,
|
|
Name: provider.Name,
|
|
StylingType: model.IDPStylingType(provider.StylingType),
|
|
IDPConfigID: provider.IDPConfigID,
|
|
IDPConfigType: model.IdpConfigType(provider.IDPConfigType),
|
|
IDPProviderType: model.IDPProviderType(provider.IDPProviderType),
|
|
IDPState: model.IDPConfigState(provider.IDPState),
|
|
}
|
|
}
|
|
|
|
func IDPProviderViewsToModel(providers []*IDPProviderView) []*model.IDPProviderView {
|
|
result := make([]*model.IDPProviderView, len(providers))
|
|
for i, r := range providers {
|
|
result[i] = IDPProviderViewToModel(r)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (i *IDPProviderView) AppendEvent(event eventstore.Event) (err error) {
|
|
i.Sequence = event.Sequence()
|
|
i.ChangeDate = event.CreatedAt()
|
|
switch event.Type() {
|
|
case instance.LoginPolicyIDPProviderAddedEventType,
|
|
org.LoginPolicyIDPProviderAddedEventType:
|
|
i.setRootData(event)
|
|
i.CreationDate = event.CreatedAt()
|
|
err = i.SetData(event)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (r *IDPProviderView) setRootData(event eventstore.Event) {
|
|
r.AggregateID = event.Aggregate().ID
|
|
r.InstanceID = event.Aggregate().InstanceID
|
|
}
|
|
|
|
func (r *IDPProviderView) SetData(event eventstore.Event) error {
|
|
if err := event.Unmarshal(r); err != nil {
|
|
logging.New().WithError(err).Error("could not unmarshal event data")
|
|
return zerrors.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
|
}
|
|
return nil
|
|
}
|