2020-08-26 07:56:23 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-04-06 14:03:07 +00:00
|
|
|
caos_errors "github.com/caos/zitadel/internal/errors"
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IDPProviderView struct {
|
|
|
|
AggregateID string
|
|
|
|
IDPConfigID string
|
|
|
|
IDPProviderType IDPProviderType
|
|
|
|
Name string
|
2020-10-19 15:10:02 +00:00
|
|
|
StylingType IDPStylingType
|
2020-08-26 07:56:23 +00:00
|
|
|
IDPConfigType IdpConfigType
|
2020-09-23 14:52:19 +00:00
|
|
|
IDPState IDPConfigState
|
2020-08-26 07:56:23 +00:00
|
|
|
|
|
|
|
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
|
2020-09-23 14:52:19 +00:00
|
|
|
IDPProviderSearchKeyState
|
2020-08-26 07:56:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type IDPProviderSearchQuery struct {
|
|
|
|
Key IDPProviderSearchKey
|
2021-03-01 07:48:50 +00:00
|
|
|
Method domain.SearchMethod
|
2020-08-26 07:56:23 +00:00
|
|
|
Value interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDPProviderSearchResponse struct {
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
TotalResult uint64
|
|
|
|
Result []*IDPProviderView
|
|
|
|
Sequence uint64
|
|
|
|
Timestamp time.Time
|
|
|
|
}
|
|
|
|
|
2021-04-06 14:03:07 +00:00
|
|
|
func (r *IDPProviderSearchRequest) EnsureLimit(limit uint64) error {
|
|
|
|
if r.Limit > limit {
|
|
|
|
return caos_errors.ThrowInvalidArgument(nil, "SEARCH-3n8fs", "Errors.Limit.ExceedsDefault")
|
|
|
|
}
|
|
|
|
if r.Limit == 0 {
|
2020-08-26 07:56:23 +00:00
|
|
|
r.Limit = limit
|
|
|
|
}
|
2021-04-06 14:03:07 +00:00
|
|
|
return nil
|
2020-08-26 07:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *IDPProviderSearchRequest) AppendAggregateIDQuery(aggregateID string) {
|
2021-03-01 07:48:50 +00:00
|
|
|
r.Queries = append(r.Queries, &IDPProviderSearchQuery{Key: IDPProviderSearchKeyAggregateID, Method: domain.SearchMethodEquals, Value: aggregateID})
|
2020-08-26 07:56:23 +00:00
|
|
|
}
|
2021-02-08 10:30:30 +00:00
|
|
|
|
|
|
|
func IdpProviderViewsToDomain(idpProviders []*IDPProviderView) []*domain.IDPProvider {
|
|
|
|
providers := make([]*domain.IDPProvider, len(idpProviders))
|
|
|
|
for i, provider := range idpProviders {
|
|
|
|
p := &domain.IDPProvider{
|
|
|
|
IDPConfigID: provider.IDPConfigID,
|
|
|
|
Type: idpProviderTypeToDomain(provider.IDPProviderType),
|
|
|
|
Name: provider.Name,
|
|
|
|
IDPConfigType: idpConfigTypeToDomain(provider.IDPConfigType),
|
|
|
|
StylingType: idpStylingTypeToDomain(provider.StylingType),
|
|
|
|
IDPState: idpStateToDomain(provider.IDPState),
|
|
|
|
}
|
|
|
|
providers[i] = p
|
|
|
|
}
|
|
|
|
return providers
|
|
|
|
}
|
|
|
|
|
|
|
|
func idpProviderTypeToDomain(idpType IDPProviderType) domain.IdentityProviderType {
|
|
|
|
switch idpType {
|
|
|
|
case IDPProviderTypeSystem:
|
|
|
|
return domain.IdentityProviderTypeSystem
|
|
|
|
case IDPProviderTypeOrg:
|
|
|
|
return domain.IdentityProviderTypeOrg
|
|
|
|
default:
|
|
|
|
return domain.IdentityProviderTypeSystem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func idpConfigTypeToDomain(idpType IdpConfigType) domain.IDPConfigType {
|
|
|
|
switch idpType {
|
|
|
|
case IDPConfigTypeOIDC:
|
|
|
|
return domain.IDPConfigTypeOIDC
|
|
|
|
case IDPConfigTypeSAML:
|
|
|
|
return domain.IDPConfigTypeSAML
|
2021-09-14 13:15:01 +00:00
|
|
|
case IDPConfigTypeJWT:
|
|
|
|
return domain.IDPConfigTypeJWT
|
2021-02-08 10:30:30 +00:00
|
|
|
default:
|
|
|
|
return domain.IDPConfigTypeOIDC
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func idpStylingTypeToDomain(stylingType IDPStylingType) domain.IDPConfigStylingType {
|
|
|
|
switch stylingType {
|
|
|
|
case IDPStylingTypeGoogle:
|
|
|
|
return domain.IDPConfigStylingTypeGoogle
|
|
|
|
default:
|
|
|
|
return domain.IDPConfigStylingTypeUnspecified
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func idpStateToDomain(state IDPConfigState) domain.IDPConfigState {
|
|
|
|
switch state {
|
|
|
|
case IDPConfigStateActive:
|
|
|
|
return domain.IDPConfigStateActive
|
|
|
|
case IDPConfigStateInactive:
|
|
|
|
return domain.IDPConfigStateInactive
|
|
|
|
case IDPConfigStateRemoved:
|
|
|
|
return domain.IDPConfigStateRemoved
|
|
|
|
default:
|
|
|
|
return domain.IDPConfigStateActive
|
|
|
|
}
|
|
|
|
}
|