zitadel/internal/iam/repository/view/model/idp_provider.go
Fabi 0bd27bc8e4
fix: add prompt on oidc rp, fix idp and login policy in console (#769)
* fix: add prompt on oidc rp

* fix: add prompt on oidc rp

* fix: translation

* fix: translation

* fix: not existing login policy

* fix: login policy

* fix: identity provider detail

* fix: idp update

* fix: idps in login policy

* fix: lint

* fix: scss

* fix: external idps on auth user detail

* fix: idp create mapping fields

* fix: remove idp provider

* fix: angular lint

* fix: login policy view

* fix: translations
2020-09-23 16:52:19 +02:00

96 lines
3.1 KiB
Go

package model
import (
"encoding/json"
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
"time"
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
"github.com/caos/logging"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/models"
"github.com/caos/zitadel/internal/iam/model"
)
const (
IDPProviderKeyAggregateID = "aggregate_id"
IDPProviderKeyIdpConfigID = "idp_config_id"
IDPProviderKeyState = "idp_state"
)
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"`
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"`
}
func IDPProviderViewFromModel(provider *model.IDPProviderView) *IDPProviderView {
return &IDPProviderView{
AggregateID: provider.AggregateID,
Sequence: provider.Sequence,
CreationDate: provider.CreationDate,
ChangeDate: provider.ChangeDate,
Name: provider.Name,
IDPConfigID: provider.IDPConfigID,
IDPConfigType: int32(provider.IDPConfigType),
IDPProviderType: int32(provider.IDPProviderType),
IDPState: int32(provider.IDPState),
}
}
func IDPProviderViewToModel(provider *IDPProviderView) *model.IDPProviderView {
return &model.IDPProviderView{
AggregateID: provider.AggregateID,
Sequence: provider.Sequence,
CreationDate: provider.CreationDate,
ChangeDate: provider.ChangeDate,
Name: provider.Name,
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 *models.Event) (err error) {
i.Sequence = event.Sequence
i.ChangeDate = event.CreationDate
switch event.Type {
case es_model.LoginPolicyIDPProviderAdded, org_es_model.LoginPolicyIDPProviderAdded:
i.setRootData(event)
i.CreationDate = event.CreationDate
err = i.SetData(event)
}
return err
}
func (r *IDPProviderView) setRootData(event *models.Event) {
r.AggregateID = event.AggregateID
}
func (r *IDPProviderView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-Lso0d").WithError(err).Error("could not unmarshal event data")
return caos_errs.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
}
return nil
}