mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +00:00
refactor: cleanup unused code (#7130)
* refactor: drop unused code * refactor: drop unused code
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type Step int
|
||||
|
||||
const (
|
||||
Step1 Step = iota + 1
|
||||
Step2
|
||||
Step3
|
||||
Step4
|
||||
Step5
|
||||
Step6
|
||||
Step7
|
||||
Step8
|
||||
Step9
|
||||
Step10
|
||||
//StepCount marks the the length of possible steps (StepCount-1 == last possible step)
|
||||
StepCount
|
||||
)
|
||||
|
||||
type IAM struct {
|
||||
es_models.ObjectRoot
|
||||
DefaultOrgID string
|
||||
IAMProjectID string
|
||||
SetUpDone domain.Step
|
||||
SetUpStarted domain.Step
|
||||
Members []*IAMMember
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
package model
|
||||
|
||||
import es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
|
||||
type IAMMember struct {
|
||||
es_models.ObjectRoot
|
||||
|
||||
UserID string
|
||||
Roles []string
|
||||
}
|
||||
|
||||
func NewIAMMember(iamID, userID string) *IAMMember {
|
||||
return &IAMMember{ObjectRoot: es_models.ObjectRoot{AggregateID: iamID}, UserID: userID}
|
||||
}
|
||||
|
||||
func (i *IAMMember) IsValid() bool {
|
||||
return i.AggregateID != "" && i.UserID != "" && len(i.Roles) != 0
|
||||
}
|
@@ -1,110 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type IDPConfig struct {
|
||||
es_models.ObjectRoot
|
||||
IDPConfigID string
|
||||
Type IdpConfigType
|
||||
Name string
|
||||
StylingType IDPStylingType
|
||||
State IDPConfigState
|
||||
OIDCConfig *OIDCIDPConfig
|
||||
JWTIDPConfig *JWTIDPConfig
|
||||
}
|
||||
|
||||
type OIDCIDPConfig struct {
|
||||
es_models.ObjectRoot
|
||||
IDPConfigID string
|
||||
ClientID string
|
||||
ClientSecret *crypto.CryptoValue
|
||||
ClientSecretString string
|
||||
Issuer string
|
||||
Scopes []string
|
||||
IDPDisplayNameMapping OIDCMappingField
|
||||
UsernameMapping OIDCMappingField
|
||||
}
|
||||
|
||||
type JWTIDPConfig struct {
|
||||
es_models.ObjectRoot
|
||||
IDPConfigID string
|
||||
JWTEndpoint string
|
||||
Issuer string
|
||||
KeysEndpoint string
|
||||
}
|
||||
|
||||
type IdpConfigType int32
|
||||
|
||||
const (
|
||||
IDPConfigTypeOIDC IdpConfigType = iota
|
||||
IDPConfigTypeSAML
|
||||
IDPConfigTypeJWT
|
||||
)
|
||||
|
||||
type IDPConfigState int32
|
||||
|
||||
const (
|
||||
IDPConfigStateActive IDPConfigState = iota
|
||||
IDPConfigStateInactive
|
||||
IDPConfigStateRemoved
|
||||
)
|
||||
|
||||
type IDPStylingType int32
|
||||
|
||||
const (
|
||||
IDPStylingTypeUnspecified IDPStylingType = iota
|
||||
IDPStylingTypeGoogle
|
||||
)
|
||||
|
||||
type OIDCMappingField int32
|
||||
|
||||
const (
|
||||
OIDCMappingFieldUnspecified OIDCMappingField = iota
|
||||
OIDCMappingFieldPreferredLoginName
|
||||
OIDCMappingFieldEmail
|
||||
)
|
||||
|
||||
func NewIDPConfig(iamID, idpID string) *IDPConfig {
|
||||
return &IDPConfig{ObjectRoot: es_models.ObjectRoot{AggregateID: iamID}, IDPConfigID: idpID}
|
||||
}
|
||||
|
||||
func (idp *IDPConfig) IsValid(includeConfig bool) bool {
|
||||
if idp.Name == "" || idp.AggregateID == "" {
|
||||
return false
|
||||
}
|
||||
if !includeConfig {
|
||||
return true
|
||||
}
|
||||
if idp.Type == IDPConfigTypeOIDC && !idp.OIDCConfig.IsValid(true) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (oi *OIDCIDPConfig) IsValid(withSecret bool) bool {
|
||||
if withSecret {
|
||||
return oi.ClientID != "" && oi.Issuer != "" && oi.ClientSecretString != ""
|
||||
}
|
||||
return oi.ClientID != "" && oi.Issuer != ""
|
||||
}
|
||||
|
||||
func (oi *OIDCIDPConfig) CryptSecret(crypt crypto.Crypto) error {
|
||||
cryptedSecret, err := crypto.Crypt([]byte(oi.ClientSecretString), crypt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
oi.ClientSecret = cryptedSecret
|
||||
return nil
|
||||
}
|
||||
|
||||
func (st IDPStylingType) GetCSSClass() string {
|
||||
switch st {
|
||||
case IDPStylingTypeGoogle:
|
||||
return "google"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type IDPConfigView struct {
|
||||
AggregateID string
|
||||
IDPConfigID string
|
||||
Name string
|
||||
StylingType IDPStylingType
|
||||
AutoRegister bool
|
||||
State IDPConfigState
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
IDPProviderType IDPProviderType
|
||||
|
||||
IsOIDC bool
|
||||
OIDCClientID string
|
||||
OIDCClientSecret *crypto.CryptoValue
|
||||
OIDCIssuer string
|
||||
OIDCScopes []string
|
||||
OIDCIDPDisplayNameMapping OIDCMappingField
|
||||
OIDCUsernameMapping OIDCMappingField
|
||||
OAuthAuthorizationEndpoint string
|
||||
OAuthTokenEndpoint string
|
||||
JWTEndpoint string
|
||||
JWTIssuer string
|
||||
JWTKeysEndpoint string
|
||||
JWTHeaderName string
|
||||
}
|
||||
|
||||
type IDPConfigSearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn IDPConfigSearchKey
|
||||
Asc bool
|
||||
Queries []*IDPConfigSearchQuery
|
||||
}
|
||||
|
||||
type IDPConfigSearchKey int32
|
||||
|
||||
const (
|
||||
IDPConfigSearchKeyUnspecified IDPConfigSearchKey = iota
|
||||
IDPConfigSearchKeyName
|
||||
IDPConfigSearchKeyAggregateID
|
||||
IDPConfigSearchKeyIdpConfigID
|
||||
IDPConfigSearchKeyIdpProviderType
|
||||
IDPConfigSearchKeyInstanceID
|
||||
IDPConfigSearchKeyOwnerRemoved
|
||||
)
|
||||
|
||||
type IDPConfigSearchQuery struct {
|
||||
Key IDPConfigSearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type IDPConfigSearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*IDPConfigView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
func (r *IDPConfigSearchRequest) EnsureLimit(limit uint64) error {
|
||||
if r.Limit > limit {
|
||||
return zerrors.ThrowInvalidArgument(nil, "SEARCH-Mv9sd", "Errors.Limit.ExceedsDefault")
|
||||
}
|
||||
if r.Limit == 0 {
|
||||
r.Limit = limit
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *IDPConfigSearchRequest) AppendMyOrgQuery(orgID, iamID string) {
|
||||
r.Queries = append(r.Queries, &IDPConfigSearchQuery{Key: IDPConfigSearchKeyAggregateID, Method: domain.SearchMethodIsOneOf, Value: []string{orgID, iamID}})
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type IDPProviderView struct {
|
||||
AggregateID string
|
||||
IDPConfigID string
|
||||
IDPProviderType IDPProviderType
|
||||
Name string
|
||||
StylingType IDPStylingType
|
||||
IDPConfigType IdpConfigType
|
||||
IDPState IDPConfigState
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type IDPProviderSearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn IDPProviderSearchKey
|
||||
Asc bool
|
||||
Queries []*IDPProviderSearchQuery
|
||||
}
|
||||
|
||||
type IDPProviderSearchKey int32
|
||||
|
||||
const (
|
||||
IDPProviderSearchKeyUnspecified IDPProviderSearchKey = iota
|
||||
IDPProviderSearchKeyAggregateID
|
||||
IDPProviderSearchKeyIdpConfigID
|
||||
IDPProviderSearchKeyState
|
||||
IDPProviderSearchKeyInstanceID
|
||||
IDPProviderSearchKeyOwnerRemoved
|
||||
)
|
||||
|
||||
type IDPProviderSearchQuery struct {
|
||||
Key IDPProviderSearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type IDPProviderSearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*IDPProviderView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
func (r *IDPProviderSearchRequest) EnsureLimit(limit uint64) error {
|
||||
if r.Limit > limit {
|
||||
return zerrors.ThrowInvalidArgument(nil, "SEARCH-3n8fs", "Errors.Limit.ExceedsDefault")
|
||||
}
|
||||
if r.Limit == 0 {
|
||||
r.Limit = limit
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *IDPProviderSearchRequest) AppendAggregateIDQuery(aggregateID string) {
|
||||
r.Queries = append(r.Queries, &IDPProviderSearchQuery{Key: IDPProviderSearchKeyAggregateID, Method: domain.SearchMethodEquals, Value: aggregateID})
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type LabelPolicy struct {
|
||||
models.ObjectRoot
|
||||
|
||||
State PolicyState
|
||||
Default bool
|
||||
PrimaryColor string
|
||||
BackgroundColor string
|
||||
FontColor string
|
||||
WarnColor string
|
||||
PrimaryColorDark string
|
||||
BackgroundColorDark string
|
||||
FontColorDark string
|
||||
WarnColorDark string
|
||||
HideLoginNameSuffix bool
|
||||
}
|
||||
|
||||
func (p *LabelPolicy) IsValid() bool {
|
||||
return p.ObjectRoot.AggregateID != ""
|
||||
}
|
@@ -1,47 +1,9 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type LabelPolicyView struct {
|
||||
AggregateID string
|
||||
PrimaryColor string
|
||||
BackgroundColor string
|
||||
WarnColor string
|
||||
FontColor string
|
||||
LogoURL string
|
||||
IconURL string
|
||||
|
||||
PrimaryColorDark string
|
||||
BackgroundColorDark string
|
||||
WarnColorDark string
|
||||
FontColorDark string
|
||||
LogoDarkURL string
|
||||
IconDarkURL string
|
||||
FontURL string
|
||||
|
||||
HideLoginNameSuffix bool
|
||||
ErrorMsgPopup bool
|
||||
DisableWatermark bool
|
||||
|
||||
Default bool
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type LabelPolicySearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn LabelPolicySearchKey
|
||||
Asc bool
|
||||
Queries []*LabelPolicySearchQuery
|
||||
}
|
||||
|
||||
type LabelPolicySearchKey int32
|
||||
|
||||
const (
|
||||
@@ -57,12 +19,3 @@ type LabelPolicySearchQuery struct {
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type LabelPolicySearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*LabelPolicyView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
@@ -1,90 +1,8 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type LoginPolicy struct {
|
||||
models.ObjectRoot
|
||||
|
||||
State PolicyState
|
||||
Default bool
|
||||
AllowUsernamePassword bool
|
||||
AllowRegister bool
|
||||
AllowExternalIdp bool
|
||||
IDPProviders []*IDPProvider
|
||||
ForceMFA bool
|
||||
SecondFactors []domain.SecondFactorType
|
||||
MultiFactors []domain.MultiFactorType
|
||||
PasswordlessType PasswordlessType
|
||||
}
|
||||
|
||||
type IDPProvider struct {
|
||||
models.ObjectRoot
|
||||
Type IDPProviderType
|
||||
IDPConfigID string
|
||||
}
|
||||
|
||||
type PolicyState int32
|
||||
|
||||
const (
|
||||
PolicyStateActive PolicyState = iota
|
||||
PolicyStateRemoved
|
||||
)
|
||||
|
||||
type IDPProviderType int32
|
||||
|
||||
const (
|
||||
IDPProviderTypeSystem IDPProviderType = iota
|
||||
IDPProviderTypeOrg
|
||||
)
|
||||
|
||||
type MultiFactorType int32
|
||||
|
||||
const (
|
||||
MultiFactorTypeUnspecified MultiFactorType = iota
|
||||
MultiFactorTypeU2FWithPIN
|
||||
)
|
||||
|
||||
type PasswordlessType int32
|
||||
|
||||
const (
|
||||
PasswordlessTypeNotAllowed PasswordlessType = iota
|
||||
PasswordlessTypeAllowed
|
||||
)
|
||||
|
||||
func (p *LoginPolicy) IsValid() bool {
|
||||
return p.ObjectRoot.AggregateID != ""
|
||||
}
|
||||
|
||||
func (p *IDPProvider) IsValid() bool {
|
||||
return p.ObjectRoot.AggregateID != "" && p.IDPConfigID != ""
|
||||
}
|
||||
|
||||
func (p *LoginPolicy) GetIdpProvider(id string) (int, *IDPProvider) {
|
||||
for i, m := range p.IDPProviders {
|
||||
if m.IDPConfigID == id {
|
||||
return i, m
|
||||
}
|
||||
}
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
func (p *LoginPolicy) GetSecondFactor(mfaType domain.SecondFactorType) (int, domain.SecondFactorType) {
|
||||
for i, m := range p.SecondFactors {
|
||||
if m == mfaType {
|
||||
return i, m
|
||||
}
|
||||
}
|
||||
return -1, 0
|
||||
}
|
||||
|
||||
func (p *LoginPolicy) GetMultiFactor(mfaType domain.MultiFactorType) (int, domain.MultiFactorType) {
|
||||
for i, m := range p.MultiFactors {
|
||||
if m == mfaType {
|
||||
return i, m
|
||||
}
|
||||
}
|
||||
return -1, 0
|
||||
}
|
||||
|
@@ -1,129 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type LoginPolicyView struct {
|
||||
AggregateID string
|
||||
AllowUsernamePassword bool
|
||||
AllowRegister bool
|
||||
AllowExternalIDP bool
|
||||
ForceMFA bool
|
||||
HidePasswordReset bool
|
||||
PasswordlessType PasswordlessType
|
||||
SecondFactors []domain.SecondFactorType
|
||||
MultiFactors []domain.MultiFactorType
|
||||
Default bool
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type LoginPolicySearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn LoginPolicySearchKey
|
||||
Asc bool
|
||||
Queries []*LoginPolicySearchQuery
|
||||
}
|
||||
|
||||
type LoginPolicySearchKey int32
|
||||
|
||||
const (
|
||||
LoginPolicySearchKeyUnspecified LoginPolicySearchKey = iota
|
||||
LoginPolicySearchKeyAggregateID
|
||||
LoginPolicySearchKeyDefault
|
||||
)
|
||||
|
||||
type LoginPolicySearchQuery struct {
|
||||
Key LoginPolicySearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type LoginPolicySearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*LoginPolicyView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
func (p *LoginPolicyView) HasSecondFactors() bool {
|
||||
if p.SecondFactors == nil || len(p.SecondFactors) == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *LoginPolicyView) HasMultiFactors() bool {
|
||||
if p.MultiFactors == nil || len(p.MultiFactors) == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *LoginPolicyView) ToLoginPolicyDomain() *domain.LoginPolicy {
|
||||
return &domain.LoginPolicy{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: p.AggregateID,
|
||||
CreationDate: p.CreationDate,
|
||||
ChangeDate: p.ChangeDate,
|
||||
Sequence: p.Sequence,
|
||||
},
|
||||
Default: p.Default,
|
||||
AllowUsernamePassword: p.AllowUsernamePassword,
|
||||
AllowRegister: p.AllowRegister,
|
||||
AllowExternalIDP: p.AllowExternalIDP,
|
||||
ForceMFA: p.ForceMFA,
|
||||
HidePasswordReset: p.HidePasswordReset,
|
||||
PasswordlessType: passwordLessTypeToDomain(p.PasswordlessType),
|
||||
SecondFactors: secondFactorsToDomain(p.SecondFactors),
|
||||
MultiFactors: multiFactorsToDomain(p.MultiFactors),
|
||||
}
|
||||
}
|
||||
|
||||
func passwordLessTypeToDomain(passwordless PasswordlessType) domain.PasswordlessType {
|
||||
switch passwordless {
|
||||
case PasswordlessTypeNotAllowed:
|
||||
return domain.PasswordlessTypeNotAllowed
|
||||
case PasswordlessTypeAllowed:
|
||||
return domain.PasswordlessTypeAllowed
|
||||
default:
|
||||
return domain.PasswordlessTypeNotAllowed
|
||||
}
|
||||
}
|
||||
|
||||
func secondFactorsToDomain(types []domain.SecondFactorType) []domain.SecondFactorType {
|
||||
secondfactors := make([]domain.SecondFactorType, len(types))
|
||||
for i, secondfactorType := range types {
|
||||
switch secondfactorType {
|
||||
case domain.SecondFactorTypeU2F:
|
||||
secondfactors[i] = domain.SecondFactorTypeU2F
|
||||
case domain.SecondFactorTypeTOTP:
|
||||
secondfactors[i] = domain.SecondFactorTypeTOTP
|
||||
case domain.SecondFactorTypeOTPEmail:
|
||||
secondfactors[i] = domain.SecondFactorTypeOTPEmail
|
||||
case domain.SecondFactorTypeOTPSMS:
|
||||
secondfactors[i] = domain.SecondFactorTypeOTPSMS
|
||||
}
|
||||
}
|
||||
return secondfactors
|
||||
}
|
||||
|
||||
func multiFactorsToDomain(types []domain.MultiFactorType) []domain.MultiFactorType {
|
||||
multifactors := make([]domain.MultiFactorType, len(types))
|
||||
for i, multifactorType := range types {
|
||||
switch multifactorType {
|
||||
case domain.MultiFactorTypeU2FWithPIN:
|
||||
multifactors[i] = domain.MultiFactorTypeU2FWithPIN
|
||||
}
|
||||
}
|
||||
return multifactors
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type MailTemplate struct {
|
||||
models.ObjectRoot
|
||||
|
||||
State PolicyState
|
||||
Default bool
|
||||
Template []byte
|
||||
}
|
||||
|
||||
func (p *MailTemplate) IsValid() bool {
|
||||
return p.ObjectRoot.AggregateID != ""
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type MailTexts struct {
|
||||
Texts []*MailText
|
||||
Default bool
|
||||
}
|
||||
type MailText struct {
|
||||
models.ObjectRoot
|
||||
|
||||
State PolicyState
|
||||
Default bool
|
||||
MailTextType string
|
||||
Language string
|
||||
Title string
|
||||
PreHeader string
|
||||
Subject string
|
||||
Greeting string
|
||||
Text string
|
||||
ButtonText string
|
||||
FooterText string
|
||||
}
|
||||
|
||||
func (p *MailText) IsValid() bool {
|
||||
return p.ObjectRoot.AggregateID != ""
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type MessageTextView struct {
|
||||
AggregateID string
|
||||
MessageTextType string
|
||||
Language language.Tag
|
||||
Title string
|
||||
PreHeader string
|
||||
Subject string
|
||||
Greeting string
|
||||
Text string
|
||||
ButtonText string
|
||||
FooterText string
|
||||
Default bool
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type MessageTextSearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn MessageTextSearchKey
|
||||
Asc bool
|
||||
Queries []*MessageTextSearchQuery
|
||||
}
|
||||
|
||||
type MessageTextSearchKey int32
|
||||
|
||||
const (
|
||||
MessageTextSearchKeyUnspecified MessageTextSearchKey = iota
|
||||
MessageTextSearchKeyAggregateID
|
||||
MessageTextSearchKeyMessageTextType
|
||||
MessageTextSearchKeyLanguage
|
||||
)
|
||||
|
||||
type MessageTextSearchQuery struct {
|
||||
Key MessageTextSearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type MessageTextSearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*MessageTextView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type SecondFactorsSearchRequest struct {
|
||||
Queries []*MFASearchQuery
|
||||
}
|
||||
|
||||
type MultiFactorsSearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
Asc bool
|
||||
Queries []*MFASearchQuery
|
||||
}
|
||||
|
||||
type MFASearchQuery struct {
|
||||
Key MFASearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type MFASearchKey int32
|
||||
|
||||
const (
|
||||
MFASearchKeyUnspecified MFASearchKey = iota
|
||||
MFASearchKeyAggregateID
|
||||
)
|
||||
|
||||
type SecondFactorsSearchResponse struct {
|
||||
TotalResult uint64
|
||||
Result []domain.SecondFactorType
|
||||
}
|
||||
|
||||
type MultiFactorsSearchResponse struct {
|
||||
TotalResult uint64
|
||||
Result []domain.MultiFactorType
|
||||
}
|
||||
|
||||
func (r *SecondFactorsSearchRequest) AppendAggregateIDQuery(aggregateID string) {
|
||||
r.Queries = append(r.Queries, &MFASearchQuery{Key: MFASearchKeyAggregateID, Method: domain.SearchMethodEquals, Value: aggregateID})
|
||||
}
|
||||
|
||||
func (r *MultiFactorsSearchRequest) AppendAggregateIDQuery(aggregateID string) {
|
||||
r.Queries = append(r.Queries, &MFASearchQuery{Key: MFASearchKeyAggregateID, Method: domain.SearchMethodEquals, Value: aggregateID})
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type PasswordAgePolicy struct {
|
||||
models.ObjectRoot
|
||||
|
||||
State PolicyState
|
||||
MaxAgeDays uint64
|
||||
ExpireWarnDays uint64
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type PasswordAgePolicyView struct {
|
||||
AggregateID string
|
||||
MaxAgeDays uint64
|
||||
ExpireWarnDays uint64
|
||||
Default bool
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type PasswordAgePolicySearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn PasswordAgePolicySearchKey
|
||||
Asc bool
|
||||
Queries []*PasswordAgePolicySearchQuery
|
||||
}
|
||||
|
||||
type PasswordAgePolicySearchKey int32
|
||||
|
||||
const (
|
||||
PasswordAgePolicySearchKeyUnspecified PasswordAgePolicySearchKey = iota
|
||||
PasswordAgePolicySearchKeyAggregateID
|
||||
)
|
||||
|
||||
type PasswordAgePolicySearchQuery struct {
|
||||
Key PasswordAgePolicySearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type PasswordAgePolicySearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*PasswordAgePolicyView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
var (
|
||||
hasStringLowerCase = regexp.MustCompile(`[a-z]`).MatchString
|
||||
hasStringUpperCase = regexp.MustCompile(`[A-Z]`).MatchString
|
||||
hasNumber = regexp.MustCompile(`[0-9]`).MatchString
|
||||
hasSymbol = regexp.MustCompile(`[^A-Za-z0-9]`).MatchString
|
||||
)
|
||||
|
||||
type PasswordComplexityPolicy struct {
|
||||
models.ObjectRoot
|
||||
|
||||
State PolicyState
|
||||
MinLength uint64
|
||||
HasLowercase bool
|
||||
HasUppercase bool
|
||||
HasNumber bool
|
||||
HasSymbol bool
|
||||
|
||||
Default bool
|
||||
}
|
||||
|
||||
func (p *PasswordComplexityPolicy) IsValid() error {
|
||||
if p.MinLength == 0 || p.MinLength > 72 {
|
||||
return zerrors.ThrowInvalidArgument(nil, "MODEL-Lsp0e", "Errors.User.PasswordComplexityPolicy.MinLengthNotAllowed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PasswordComplexityPolicy) Check(password string) error {
|
||||
if p.MinLength != 0 && uint64(len(password)) < p.MinLength {
|
||||
return zerrors.ThrowInvalidArgument(nil, "MODEL-HuJf6", "Errors.User.PasswordComplexityPolicy.MinLength")
|
||||
}
|
||||
|
||||
if p.HasLowercase && !hasStringLowerCase(password) {
|
||||
return zerrors.ThrowInvalidArgument(nil, "MODEL-co3Xw", "Errors.User.PasswordComplexityPolicy.HasLower")
|
||||
}
|
||||
|
||||
if p.HasUppercase && !hasStringUpperCase(password) {
|
||||
return zerrors.ThrowInvalidArgument(nil, "MODEL-VoaRj", "Errors.User.PasswordComplexityPolicy.HasUpper")
|
||||
}
|
||||
|
||||
if p.HasNumber && !hasNumber(password) {
|
||||
return zerrors.ThrowInvalidArgument(nil, "MODEL-ZBv4H", "Errors.User.PasswordComplexityPolicy.HasNumber")
|
||||
}
|
||||
|
||||
if p.HasSymbol && !hasSymbol(password) {
|
||||
return zerrors.ThrowInvalidArgument(nil, "MODEL-ZDLwA", "Errors.User.PasswordComplexityPolicy.HasSymbol")
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -2,8 +2,6 @@ package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type PasswordComplexityPolicyView struct {
|
||||
@@ -19,33 +17,3 @@ type PasswordComplexityPolicyView struct {
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type PasswordComplexityPolicySearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn PasswordComplexityPolicySearchKey
|
||||
Asc bool
|
||||
Queries []*PasswordComplexityPolicySearchQuery
|
||||
}
|
||||
|
||||
type PasswordComplexityPolicySearchKey int32
|
||||
|
||||
const (
|
||||
PasswordComplexityPolicySearchKeyUnspecified PasswordComplexityPolicySearchKey = iota
|
||||
PasswordComplexityPolicySearchKeyAggregateID
|
||||
)
|
||||
|
||||
type PasswordComplexityPolicySearchQuery struct {
|
||||
Key PasswordComplexityPolicySearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type PasswordComplexityPolicySearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*PasswordComplexityPolicyView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
@@ -1,13 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type LockoutPolicy struct {
|
||||
models.ObjectRoot
|
||||
|
||||
State PolicyState
|
||||
MaxPasswordAttempts uint64
|
||||
ShowLockOutFailures bool
|
||||
}
|
@@ -1,48 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type LockoutPolicyView struct {
|
||||
AggregateID string
|
||||
MaxPasswordAttempts uint64
|
||||
ShowLockOutFailures bool
|
||||
Default bool
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type LockoutPolicySearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn LockoutPolicySearchKey
|
||||
Asc bool
|
||||
Queries []*LockoutPolicySearchQuery
|
||||
}
|
||||
|
||||
type LockoutPolicySearchKey int32
|
||||
|
||||
const (
|
||||
LockoutPolicySearchKeyUnspecified LockoutPolicySearchKey = iota
|
||||
LockoutPolicySearchKeyAggregateID
|
||||
)
|
||||
|
||||
type LockoutPolicySearchQuery struct {
|
||||
Key LockoutPolicySearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type LockoutPolicySearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*LockoutPolicyView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
)
|
||||
|
||||
type PrivacyPolicyView struct {
|
||||
AggregateID string
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
SupportEmail string
|
||||
Default bool
|
||||
|
||||
CreationDate time.Time
|
||||
ChangeDate time.Time
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
type PrivacyPolicySearchRequest struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
SortingColumn PrivacyPolicySearchKey
|
||||
Asc bool
|
||||
Queries []*PrivacyPolicySearchQuery
|
||||
}
|
||||
|
||||
type PrivacyPolicySearchKey int32
|
||||
|
||||
const (
|
||||
PrivacyPolicySearchKeyUnspecified PrivacyPolicySearchKey = iota
|
||||
PrivacyPolicySearchKeyAggregateID
|
||||
)
|
||||
|
||||
type PrivacyPolicySearchQuery struct {
|
||||
Key PrivacyPolicySearchKey
|
||||
Method domain.SearchMethod
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
type PrivacyPolicySearchResponse struct {
|
||||
Offset uint64
|
||||
Limit uint64
|
||||
TotalResult uint64
|
||||
Result []*PrivacyPolicyView
|
||||
Sequence uint64
|
||||
Timestamp time.Time
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
)
|
||||
|
||||
type IAMMember struct {
|
||||
es_models.ObjectRoot
|
||||
UserID string `json:"userId,omitempty"`
|
||||
Roles []string `json:"roles,omitempty"`
|
||||
}
|
||||
|
||||
func (m *IAMMember) SetData(event *es_models.Event) error {
|
||||
m.ObjectRoot.AppendEvent(event)
|
||||
if err := json.Unmarshal(event.Data, m); err != nil {
|
||||
logging.Log("EVEN-e4dkp").WithError(err).Error("could not unmarshal event data")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -22,15 +22,6 @@ func DomainPolicyToModel(policy *DomainPolicy) *iam_model.DomainPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *DomainPolicy) Changes(changed *DomainPolicy) map[string]interface{} {
|
||||
changes := make(map[string]interface{}, 1)
|
||||
|
||||
if p.UserLoginMustBeDomain != changed.UserLoginMustBeDomain {
|
||||
changes["userLoginMustBeDomain"] = changed.UserLoginMustBeDomain
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
func (p *DomainPolicy) SetData(event eventstore.Event) error {
|
||||
err := event.Unmarshal(p)
|
||||
if err != nil {
|
||||
|
@@ -1,49 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOrgIAMPolicyChanges(t *testing.T) {
|
||||
type args struct {
|
||||
existing *DomainPolicy
|
||||
new *DomainPolicy
|
||||
}
|
||||
type res struct {
|
||||
changesLen int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
res res
|
||||
}{
|
||||
{
|
||||
name: "org iam policy all attributes change",
|
||||
args: args{
|
||||
existing: &DomainPolicy{UserLoginMustBeDomain: true},
|
||||
new: &DomainPolicy{UserLoginMustBeDomain: false},
|
||||
},
|
||||
res: res{
|
||||
changesLen: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no changes",
|
||||
args: args{
|
||||
existing: &DomainPolicy{UserLoginMustBeDomain: true},
|
||||
new: &DomainPolicy{UserLoginMustBeDomain: true},
|
||||
},
|
||||
res: res{
|
||||
changesLen: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
changes := tt.args.existing.Changes(tt.args.new)
|
||||
if len(changes) != tt.res.changesLen {
|
||||
t.Errorf("got wrong changes len: expected: %v, actual: %v ", tt.res.changesLen, len(changes))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/iam/repository/view/model"
|
||||
"github.com/zitadel/zitadel/internal/view/repository"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func GetIDPProviderByAggregateIDAndConfigID(db *gorm.DB, table, aggregateID, idpConfigID, instanceID string) (*model.IDPProviderView, error) {
|
||||
policy := new(model.IDPProviderView)
|
||||
aggIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals}
|
||||
idpConfigIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyIdpConfigID, Value: idpConfigID, Method: domain.SearchMethodEquals}
|
||||
instanceIDQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyInstanceID, Value: instanceID, Method: domain.SearchMethodEquals}
|
||||
ownerRemovedQuery := &model.IDPProviderSearchQuery{Key: iam_model.IDPProviderSearchKeyOwnerRemoved, Value: false, Method: domain.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, aggIDQuery, idpConfigIDQuery, instanceIDQuery, ownerRemovedQuery)
|
||||
err := query(db, policy)
|
||||
if zerrors.IsNotFound(err) {
|
||||
return nil, zerrors.ThrowNotFound(nil, "VIEW-Skvi8", "Errors.IAM.LoginPolicy.IDP.NotExisting")
|
||||
}
|
||||
return policy, err
|
||||
}
|
||||
|
||||
func IDPProvidersByIdpConfigID(db *gorm.DB, table, idpConfigID, instanceID string) ([]*model.IDPProviderView, error) {
|
||||
providers := make([]*model.IDPProviderView, 0)
|
||||
queries := []*iam_model.IDPProviderSearchQuery{
|
||||
{
|
||||
Key: iam_model.IDPProviderSearchKeyIdpConfigID,
|
||||
Value: idpConfigID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
{
|
||||
Key: iam_model.IDPProviderSearchKeyInstanceID,
|
||||
Value: instanceID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
{
|
||||
Key: iam_model.IDPProviderSearchKeyOwnerRemoved,
|
||||
Value: false,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, model.IDPProviderSearchRequest{Queries: queries})
|
||||
_, err := query(db, &providers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return providers, nil
|
||||
}
|
||||
|
||||
func IDPProvidersByAggregateIDAndState(db *gorm.DB, table string, aggregateID, instanceID string, idpConfigState iam_model.IDPConfigState) ([]*model.IDPProviderView, error) {
|
||||
providers := make([]*model.IDPProviderView, 0)
|
||||
queries := []*iam_model.IDPProviderSearchQuery{
|
||||
{
|
||||
Key: iam_model.IDPProviderSearchKeyAggregateID,
|
||||
Value: aggregateID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
{
|
||||
Key: iam_model.IDPProviderSearchKeyState,
|
||||
Value: int(idpConfigState),
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
{
|
||||
Key: iam_model.IDPProviderSearchKeyInstanceID,
|
||||
Value: instanceID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
{
|
||||
Key: iam_model.IDPProviderSearchKeyOwnerRemoved,
|
||||
Value: false,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, model.IDPProviderSearchRequest{Queries: queries})
|
||||
_, err := query(db, &providers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return providers, nil
|
||||
}
|
||||
|
||||
func SearchIDPProviders(db *gorm.DB, table string, req *iam_model.IDPProviderSearchRequest) ([]*model.IDPProviderView, uint64, error) {
|
||||
providers := make([]*model.IDPProviderView, 0)
|
||||
query := repository.PrepareSearchQuery(table, model.IDPProviderSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
||||
count, err := query(db, &providers)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return providers, count, nil
|
||||
}
|
||||
|
||||
func PutIDPProvider(db *gorm.DB, table string, provider *model.IDPProviderView) error {
|
||||
save := repository.PrepareSave(table)
|
||||
return save(db, provider)
|
||||
}
|
||||
|
||||
func PutIDPProviders(db *gorm.DB, table string, providers ...*model.IDPProviderView) error {
|
||||
save := repository.PrepareBulkSave(table)
|
||||
p := make([]interface{}, len(providers))
|
||||
for i, provider := range providers {
|
||||
p[i] = provider
|
||||
}
|
||||
return save(db, p...)
|
||||
}
|
||||
|
||||
func DeleteIDPProvider(db *gorm.DB, table, aggregateID, idpConfigID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyAggregateID), Value: aggregateID},
|
||||
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyIdpConfigID), Value: idpConfigID},
|
||||
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyInstanceID), Value: instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteIDPProvidersByAggregateID(db *gorm.DB, table, aggregateID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyAggregateID), Value: aggregateID},
|
||||
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyInstanceID), Value: instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func DeleteInstanceIDPProviders(db *gorm.DB, table, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table,
|
||||
model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyInstanceID),
|
||||
instanceID,
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func UpdateOrgOwnerRemovedIDPProviders(db *gorm.DB, table, instanceID, aggID string) error {
|
||||
update := repository.PrepareUpdateByKeys(table,
|
||||
model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyOwnerRemoved),
|
||||
true,
|
||||
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyInstanceID), Value: instanceID},
|
||||
repository.Key{Key: model.IDPProviderSearchKey(iam_model.IDPProviderSearchKeyAggregateID), Value: aggID},
|
||||
)
|
||||
return update(db)
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/iam/repository/view/model"
|
||||
"github.com/zitadel/zitadel/internal/view/repository"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func IDPByID(db *gorm.DB, table, idpID, instanceID string) (*model.IDPConfigView, error) {
|
||||
idp := new(model.IDPConfigView)
|
||||
idpIDQuery := &model.IDPConfigSearchQuery{Key: iam_model.IDPConfigSearchKeyIdpConfigID, Value: idpID, Method: domain.SearchMethodEquals}
|
||||
instanceIDQuery := &model.IDPConfigSearchQuery{Key: iam_model.IDPConfigSearchKeyInstanceID, Value: instanceID, Method: domain.SearchMethodEquals}
|
||||
ownerRemovedQuery := &model.IDPConfigSearchQuery{Key: iam_model.IDPConfigSearchKeyOwnerRemoved, Value: false, Method: domain.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, idpIDQuery, instanceIDQuery, ownerRemovedQuery)
|
||||
err := query(db, idp)
|
||||
if zerrors.IsNotFound(err) {
|
||||
return nil, zerrors.ThrowNotFound(nil, "VIEW-Ahq2s", "Errors.IDP.NotExisting")
|
||||
}
|
||||
return idp, err
|
||||
}
|
||||
|
||||
func GetIDPConfigsByAggregateID(db *gorm.DB, table string, aggregateID, instanceID string) ([]*model.IDPConfigView, error) {
|
||||
idps := make([]*model.IDPConfigView, 0)
|
||||
queries := []*iam_model.IDPConfigSearchQuery{
|
||||
{
|
||||
Key: iam_model.IDPConfigSearchKeyAggregateID,
|
||||
Value: aggregateID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
}, {
|
||||
Key: iam_model.IDPConfigSearchKeyInstanceID,
|
||||
Value: instanceID,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
{
|
||||
Key: iam_model.IDPConfigSearchKeyOwnerRemoved,
|
||||
Value: false,
|
||||
Method: domain.SearchMethodEquals,
|
||||
},
|
||||
}
|
||||
query := repository.PrepareSearchQuery(table, model.IDPConfigSearchRequest{Queries: queries})
|
||||
_, err := query(db, &idps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return idps, nil
|
||||
}
|
||||
|
||||
func SearchIDPs(db *gorm.DB, table string, req *iam_model.IDPConfigSearchRequest) ([]*model.IDPConfigView, uint64, error) {
|
||||
idps := make([]*model.IDPConfigView, 0)
|
||||
query := repository.PrepareSearchQuery(table, model.IDPConfigSearchRequest{Limit: req.Limit, Offset: req.Offset, Queries: req.Queries})
|
||||
count, err := query(db, &idps)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return idps, count, nil
|
||||
}
|
||||
|
||||
func PutIDP(db *gorm.DB, table string, idp *model.IDPConfigView) error {
|
||||
save := repository.PrepareSave(table)
|
||||
return save(db, idp)
|
||||
}
|
||||
|
||||
func DeleteIDP(db *gorm.DB, table, idpID, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKeys(table,
|
||||
repository.Key{model.IDPConfigSearchKey(iam_model.IDPConfigSearchKeyIdpConfigID), idpID},
|
||||
repository.Key{model.IDPConfigSearchKey(iam_model.IDPConfigSearchKeyInstanceID), instanceID},
|
||||
)
|
||||
return delete(db)
|
||||
}
|
||||
|
||||
func UpdateOrgOwnerRemovedIDPs(db *gorm.DB, table, instanceID, aggID string) error {
|
||||
update := repository.PrepareUpdateByKeys(table,
|
||||
model.IDPConfigSearchKey(iam_model.IDPConfigSearchKeyOwnerRemoved),
|
||||
true,
|
||||
repository.Key{Key: model.IDPConfigSearchKey(iam_model.IDPConfigSearchKeyInstanceID), Value: instanceID},
|
||||
repository.Key{Key: model.IDPConfigSearchKey(iam_model.IDPConfigSearchKeyAggregateID), Value: aggID},
|
||||
)
|
||||
return update(db)
|
||||
}
|
||||
|
||||
func DeleteInstanceIDPs(db *gorm.DB, table, instanceID string) error {
|
||||
delete := repository.PrepareDeleteByKey(table, model.IDPConfigSearchKey(iam_model.IDPConfigSearchKeyInstanceID), instanceID)
|
||||
return delete(db)
|
||||
}
|
@@ -1,123 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"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 (
|
||||
IDPConfigKeyIdpConfigID = "idp_config_id"
|
||||
IDPConfigKeyAggregateID = "aggregate_id"
|
||||
IDPConfigKeyName = "name"
|
||||
IDPConfigKeyProviderType = "idp_provider_type"
|
||||
IDPConfigKeyInstanceID = "instance_id"
|
||||
IDPConfigKeyOwnerRemoved = "owner_removed"
|
||||
)
|
||||
|
||||
type IDPConfigView struct {
|
||||
IDPConfigID string `json:"idpConfigId" gorm:"column:idp_config_id;primary_key"`
|
||||
AggregateID string `json:"-" gorm:"column:aggregate_id"`
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
StylingType int32 `json:"stylingType" gorm:"column:styling_type"`
|
||||
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
IDPState int32 `json:"-" gorm:"column:idp_state"`
|
||||
IDPProviderType int32 `json:"-" gorm:"column:idp_provider_type"`
|
||||
AutoRegister bool `json:"autoRegister" gorm:"column:auto_register"`
|
||||
|
||||
IsOIDC bool `json:"-" gorm:"column:is_oidc"`
|
||||
OIDCClientID string `json:"clientId" gorm:"column:oidc_client_id"`
|
||||
OIDCClientSecret *crypto.CryptoValue `json:"clientSecret" gorm:"column:oidc_client_secret"`
|
||||
OIDCIssuer string `json:"issuer" gorm:"column:oidc_issuer"`
|
||||
OIDCScopes database.TextArray[string] `json:"scopes" gorm:"column:oidc_scopes"`
|
||||
OIDCIDPDisplayNameMapping int32 `json:"idpDisplayNameMapping" gorm:"column:oidc_idp_display_name_mapping"`
|
||||
OIDCUsernameMapping int32 `json:"usernameMapping" gorm:"column:oidc_idp_username_mapping"`
|
||||
OAuthAuthorizationEndpoint string `json:"authorizationEndpoint" gorm:"column:oauth_authorization_endpoint"`
|
||||
OAuthTokenEndpoint string `json:"tokenEndpoint" gorm:"column:oauth_token_endpoint"`
|
||||
JWTEndpoint string `json:"jwtEndpoint" gorm:"jwt_endpoint"`
|
||||
JWTKeysEndpoint string `json:"keysEndpoint" gorm:"jwt_keys_endpoint"`
|
||||
JWTHeaderName string `json:"headerName" gorm:"jwt_header_name"`
|
||||
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
InstanceID string `json:"instanceID" gorm:"column:instance_id;primary_key"`
|
||||
}
|
||||
|
||||
func IDPConfigViewToModel(idp *IDPConfigView) *model.IDPConfigView {
|
||||
view := &model.IDPConfigView{
|
||||
IDPConfigID: idp.IDPConfigID,
|
||||
AggregateID: idp.AggregateID,
|
||||
State: model.IDPConfigState(idp.IDPState),
|
||||
Name: idp.Name,
|
||||
StylingType: model.IDPStylingType(idp.StylingType),
|
||||
AutoRegister: idp.AutoRegister,
|
||||
Sequence: idp.Sequence,
|
||||
CreationDate: idp.CreationDate,
|
||||
ChangeDate: idp.ChangeDate,
|
||||
IDPProviderType: model.IDPProviderType(idp.IDPProviderType),
|
||||
IsOIDC: idp.IsOIDC,
|
||||
OIDCClientID: idp.OIDCClientID,
|
||||
OIDCClientSecret: idp.OIDCClientSecret,
|
||||
OIDCScopes: idp.OIDCScopes,
|
||||
OIDCIDPDisplayNameMapping: model.OIDCMappingField(idp.OIDCIDPDisplayNameMapping),
|
||||
OIDCUsernameMapping: model.OIDCMappingField(idp.OIDCUsernameMapping),
|
||||
OAuthAuthorizationEndpoint: idp.OAuthAuthorizationEndpoint,
|
||||
OAuthTokenEndpoint: idp.OAuthTokenEndpoint,
|
||||
}
|
||||
if idp.IsOIDC {
|
||||
view.OIDCIssuer = idp.OIDCIssuer
|
||||
return view
|
||||
}
|
||||
view.JWTEndpoint = idp.JWTEndpoint
|
||||
view.JWTIssuer = idp.OIDCIssuer
|
||||
view.JWTKeysEndpoint = idp.JWTKeysEndpoint
|
||||
view.JWTHeaderName = idp.JWTHeaderName
|
||||
return view
|
||||
}
|
||||
|
||||
func (i *IDPConfigView) AppendEvent(providerType model.IDPProviderType, event eventstore.Event) (err error) {
|
||||
i.Sequence = event.Sequence()
|
||||
i.ChangeDate = event.CreatedAt()
|
||||
switch event.Type() {
|
||||
case instance.IDPConfigAddedEventType, org.IDPConfigAddedEventType:
|
||||
i.setRootData(event)
|
||||
i.CreationDate = event.CreatedAt()
|
||||
i.IDPProviderType = int32(providerType)
|
||||
err = i.SetData(event)
|
||||
case instance.IDPOIDCConfigAddedEventType, org.IDPOIDCConfigAddedEventType:
|
||||
i.IsOIDC = true
|
||||
err = i.SetData(event)
|
||||
case instance.IDPOIDCConfigChangedEventType, org.IDPOIDCConfigChangedEventType,
|
||||
instance.IDPConfigChangedEventType, org.IDPConfigChangedEventType,
|
||||
org.IDPJWTConfigAddedEventType, instance.IDPJWTConfigAddedEventType,
|
||||
org.IDPJWTConfigChangedEventType, instance.IDPJWTConfigChangedEventType:
|
||||
err = i.SetData(event)
|
||||
case instance.IDPConfigDeactivatedEventType, org.IDPConfigDeactivatedEventType:
|
||||
i.IDPState = int32(model.IDPConfigStateInactive)
|
||||
case instance.IDPConfigReactivatedEventType, org.IDPConfigReactivatedEventType:
|
||||
i.IDPState = int32(model.IDPConfigStateActive)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *IDPConfigView) setRootData(event eventstore.Event) {
|
||||
r.AggregateID = event.Aggregate().ID
|
||||
r.InstanceID = event.Aggregate().InstanceID
|
||||
}
|
||||
|
||||
func (r *IDPConfigView) SetData(event eventstore.Event) error {
|
||||
err := event.Unmarshal(r)
|
||||
if err != nil {
|
||||
logging.New().WithError(err).Error("could not unmarshal event data")
|
||||
return zerrors.ThrowInternal(err, "MODEL-lub6s", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
type IDPConfigSearchRequest iam_model.IDPConfigSearchRequest
|
||||
type IDPConfigSearchQuery iam_model.IDPConfigSearchQuery
|
||||
type IDPConfigSearchKey iam_model.IDPConfigSearchKey
|
||||
|
||||
func (req IDPConfigSearchRequest) GetLimit() uint64 {
|
||||
return req.Limit
|
||||
}
|
||||
|
||||
func (req IDPConfigSearchRequest) GetOffset() uint64 {
|
||||
return req.Offset
|
||||
}
|
||||
|
||||
func (req IDPConfigSearchRequest) GetSortingColumn() repository.ColumnKey {
|
||||
if req.SortingColumn == iam_model.IDPConfigSearchKeyUnspecified {
|
||||
return nil
|
||||
}
|
||||
return IDPConfigSearchKey(req.SortingColumn)
|
||||
}
|
||||
|
||||
func (req IDPConfigSearchRequest) GetAsc() bool {
|
||||
return req.Asc
|
||||
}
|
||||
|
||||
func (req IDPConfigSearchRequest) GetQueries() []repository.SearchQuery {
|
||||
result := make([]repository.SearchQuery, len(req.Queries))
|
||||
for i, q := range req.Queries {
|
||||
result[i] = IDPConfigSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (req IDPConfigSearchQuery) GetKey() repository.ColumnKey {
|
||||
return IDPConfigSearchKey(req.Key)
|
||||
}
|
||||
|
||||
func (req IDPConfigSearchQuery) GetMethod() domain.SearchMethod {
|
||||
return req.Method
|
||||
}
|
||||
|
||||
func (req IDPConfigSearchQuery) GetValue() interface{} {
|
||||
return req.Value
|
||||
}
|
||||
|
||||
func (key IDPConfigSearchKey) ToColumnName() string {
|
||||
switch iam_model.IDPConfigSearchKey(key) {
|
||||
case iam_model.IDPConfigSearchKeyAggregateID:
|
||||
return IDPConfigKeyAggregateID
|
||||
case iam_model.IDPConfigSearchKeyIdpConfigID:
|
||||
return IDPConfigKeyIdpConfigID
|
||||
case iam_model.IDPConfigSearchKeyName:
|
||||
return IDPConfigKeyName
|
||||
case iam_model.IDPConfigSearchKeyIdpProviderType:
|
||||
return IDPConfigKeyProviderType
|
||||
case iam_model.IDPConfigSearchKeyInstanceID:
|
||||
return IDPConfigKeyInstanceID
|
||||
case iam_model.IDPConfigSearchKeyOwnerRemoved:
|
||||
return IDPConfigKeyOwnerRemoved
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
@@ -1,87 +0,0 @@
|
||||
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
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
type IDPProviderSearchRequest iam_model.IDPProviderSearchRequest
|
||||
type IDPProviderSearchQuery iam_model.IDPProviderSearchQuery
|
||||
type IDPProviderSearchKey iam_model.IDPProviderSearchKey
|
||||
|
||||
func (req IDPProviderSearchRequest) GetLimit() uint64 {
|
||||
return req.Limit
|
||||
}
|
||||
|
||||
func (req IDPProviderSearchRequest) GetOffset() uint64 {
|
||||
return req.Offset
|
||||
}
|
||||
|
||||
func (req IDPProviderSearchRequest) GetSortingColumn() repository.ColumnKey {
|
||||
if req.SortingColumn == iam_model.IDPProviderSearchKeyUnspecified {
|
||||
return nil
|
||||
}
|
||||
return IDPProviderSearchKey(req.SortingColumn)
|
||||
}
|
||||
|
||||
func (req IDPProviderSearchRequest) GetAsc() bool {
|
||||
return req.Asc
|
||||
}
|
||||
|
||||
func (req IDPProviderSearchRequest) GetQueries() []repository.SearchQuery {
|
||||
result := make([]repository.SearchQuery, len(req.Queries))
|
||||
for i, q := range req.Queries {
|
||||
result[i] = IDPProviderSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (req IDPProviderSearchQuery) GetKey() repository.ColumnKey {
|
||||
return IDPProviderSearchKey(req.Key)
|
||||
}
|
||||
|
||||
func (req IDPProviderSearchQuery) GetMethod() domain.SearchMethod {
|
||||
return req.Method
|
||||
}
|
||||
|
||||
func (req IDPProviderSearchQuery) GetValue() interface{} {
|
||||
return req.Value
|
||||
}
|
||||
|
||||
func (key IDPProviderSearchKey) ToColumnName() string {
|
||||
switch iam_model.IDPProviderSearchKey(key) {
|
||||
case iam_model.IDPProviderSearchKeyAggregateID:
|
||||
return IDPProviderKeyAggregateID
|
||||
case iam_model.IDPProviderSearchKeyIdpConfigID:
|
||||
return IDPProviderKeyIdpConfigID
|
||||
case iam_model.IDPProviderSearchKeyState:
|
||||
return IDPProviderKeyState
|
||||
case iam_model.IDPProviderSearchKeyInstanceID:
|
||||
return IDPProviderKeyInstanceID
|
||||
case iam_model.IDPProviderSearchKeyOwnerRemoved:
|
||||
return IDPProviderKeyOwnerRemoved
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
@@ -6,37 +6,9 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
type LabelPolicySearchRequest iam_model.LabelPolicySearchRequest
|
||||
type LabelPolicySearchQuery iam_model.LabelPolicySearchQuery
|
||||
type LabelPolicySearchKey iam_model.LabelPolicySearchKey
|
||||
|
||||
func (req LabelPolicySearchRequest) GetLimit() uint64 {
|
||||
return req.Limit
|
||||
}
|
||||
|
||||
func (req LabelPolicySearchRequest) GetOffset() uint64 {
|
||||
return req.Offset
|
||||
}
|
||||
|
||||
func (req LabelPolicySearchRequest) GetSortingColumn() repository.ColumnKey {
|
||||
if req.SortingColumn == iam_model.LabelPolicySearchKeyUnspecified {
|
||||
return nil
|
||||
}
|
||||
return LabelPolicySearchKey(req.SortingColumn)
|
||||
}
|
||||
|
||||
func (req LabelPolicySearchRequest) GetAsc() bool {
|
||||
return req.Asc
|
||||
}
|
||||
|
||||
func (req LabelPolicySearchRequest) GetQueries() []repository.SearchQuery {
|
||||
result := make([]repository.SearchQuery, len(req.Queries))
|
||||
for i, q := range req.Queries {
|
||||
result[i] = LabelPolicySearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (req LabelPolicySearchQuery) GetKey() repository.ColumnKey {
|
||||
return LabelPolicySearchKey(req.Key)
|
||||
}
|
||||
|
@@ -1,38 +1,10 @@
|
||||
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/query"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
PasswordComplexityKeyAggregateID = "aggregate_id"
|
||||
)
|
||||
|
||||
type PasswordComplexityPolicyView struct {
|
||||
AggregateID string `json:"-" gorm:"column:aggregate_id;primary_key"`
|
||||
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
State int32 `json:"-" gorm:"column:complexity_policy_state"`
|
||||
|
||||
MinLength uint64 `json:"minLength" gorm:"column:min_length"`
|
||||
HasLowercase bool `json:"hasLowercase" gorm:"column:has_lowercase"`
|
||||
HasUppercase bool `json:"hasUppercase" gorm:"column:has_uppercase"`
|
||||
HasSymbol bool `json:"hasSymbol" gorm:"column:has_symbol"`
|
||||
HasNumber bool `json:"hasNumber" gorm:"column:has_number"`
|
||||
Default bool `json:"-" gorm:"-"`
|
||||
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
}
|
||||
|
||||
func PasswordComplexityViewToModel(policy *query.PasswordComplexityPolicy) *model.PasswordComplexityPolicyView {
|
||||
return &model.PasswordComplexityPolicyView{
|
||||
AggregateID: policy.ID,
|
||||
@@ -47,31 +19,3 @@ func PasswordComplexityViewToModel(policy *query.PasswordComplexityPolicy) *mode
|
||||
Default: policy.IsDefault,
|
||||
}
|
||||
}
|
||||
|
||||
func (i *PasswordComplexityPolicyView) AppendEvent(event eventstore.Event) (err error) {
|
||||
i.Sequence = event.Sequence()
|
||||
i.ChangeDate = event.CreatedAt()
|
||||
switch event.Type() {
|
||||
case instance.PasswordComplexityPolicyAddedEventType,
|
||||
org.PasswordComplexityPolicyAddedEventType:
|
||||
i.setRootData(event)
|
||||
i.CreationDate = event.CreatedAt()
|
||||
err = i.SetData(event)
|
||||
case instance.PasswordComplexityPolicyChangedEventType,
|
||||
org.PasswordComplexityPolicyChangedEventType:
|
||||
err = i.SetData(event)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *PasswordComplexityPolicyView) setRootData(event eventstore.Event) {
|
||||
r.AggregateID = event.Aggregate().ID
|
||||
}
|
||||
|
||||
func (r *PasswordComplexityPolicyView) SetData(event eventstore.Event) error {
|
||||
if err := event.Unmarshal(r); err != nil {
|
||||
logging.Log("EVEN-Dmi9g").WithError(err).Error("could not unmarshal event data")
|
||||
return zerrors.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user