mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-26 06:18:46 +00:00
* chore: use pgx v5 * chore: update go version * remove direct pq dependency * remove unnecessary type * scan test * map scanner * converter * uint8 number array * duration * most unit tests work * unit tests work * chore: coverage * go 1.21 * linting * int64 gopfertammi * retry go 1.22 * retry go 1.22 * revert to go v1.21.5 * update go toolchain to 1.21.8 * go 1.21.8 * remove test flag * go 1.21.5 * linting * update toolchain * use correct array * use correct array * add byte array * correct value * correct error message * go 1.21 compatible
69 lines
2.9 KiB
Go
69 lines
2.9 KiB
Go
package policy
|
|
|
|
import (
|
|
"time"
|
|
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
idp_grpc "github.com/zitadel/zitadel/internal/api/grpc/idp"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
"github.com/zitadel/zitadel/pkg/grpc/object"
|
|
policy_pb "github.com/zitadel/zitadel/pkg/grpc/policy"
|
|
)
|
|
|
|
func ModelLoginPolicyToPb(policy *query.LoginPolicy) *policy_pb.LoginPolicy {
|
|
return &policy_pb.LoginPolicy{
|
|
IsDefault: policy.IsDefault,
|
|
AllowUsernamePassword: policy.AllowUsernamePassword,
|
|
AllowRegister: policy.AllowRegister,
|
|
AllowExternalIdp: policy.AllowExternalIDPs,
|
|
ForceMfa: policy.ForceMFA,
|
|
ForceMfaLocalOnly: policy.ForceMFALocalOnly,
|
|
PasswordlessType: ModelPasswordlessTypeToPb(policy.PasswordlessType),
|
|
HidePasswordReset: policy.HidePasswordReset,
|
|
IgnoreUnknownUsernames: policy.IgnoreUnknownUsernames,
|
|
AllowDomainDiscovery: policy.AllowDomainDiscovery,
|
|
DisableLoginWithEmail: policy.DisableLoginWithEmail,
|
|
DisableLoginWithPhone: policy.DisableLoginWithPhone,
|
|
DefaultRedirectUri: policy.DefaultRedirectURI,
|
|
PasswordCheckLifetime: durationpb.New(time.Duration(policy.PasswordCheckLifetime)),
|
|
ExternalLoginCheckLifetime: durationpb.New(time.Duration(policy.ExternalLoginCheckLifetime)),
|
|
MfaInitSkipLifetime: durationpb.New(time.Duration(policy.MFAInitSkipLifetime)),
|
|
SecondFactorCheckLifetime: durationpb.New(time.Duration(policy.SecondFactorCheckLifetime)),
|
|
MultiFactorCheckLifetime: durationpb.New(time.Duration(policy.MultiFactorCheckLifetime)),
|
|
SecondFactors: ModelSecondFactorTypesToPb(policy.SecondFactors),
|
|
MultiFactors: ModelMultiFactorTypesToPb(policy.MultiFactors),
|
|
Idps: idp_grpc.IDPLoginPolicyLinksToPb(policy.IDPLinks),
|
|
Details: &object.ObjectDetails{
|
|
Sequence: policy.Sequence,
|
|
CreationDate: timestamppb.New(policy.CreationDate),
|
|
ChangeDate: timestamppb.New(policy.ChangeDate),
|
|
ResourceOwner: policy.OrgID,
|
|
},
|
|
}
|
|
}
|
|
|
|
func PasswordlessTypeToDomain(passwordlessType policy_pb.PasswordlessType) domain.PasswordlessType {
|
|
switch passwordlessType {
|
|
case policy_pb.PasswordlessType_PASSWORDLESS_TYPE_ALLOWED:
|
|
return domain.PasswordlessTypeAllowed
|
|
case policy_pb.PasswordlessType_PASSWORDLESS_TYPE_NOT_ALLOWED:
|
|
return domain.PasswordlessTypeNotAllowed
|
|
default:
|
|
return -1
|
|
}
|
|
}
|
|
|
|
func ModelPasswordlessTypeToPb(passwordlessType domain.PasswordlessType) policy_pb.PasswordlessType {
|
|
switch passwordlessType {
|
|
case domain.PasswordlessTypeAllowed:
|
|
return policy_pb.PasswordlessType_PASSWORDLESS_TYPE_ALLOWED
|
|
case domain.PasswordlessTypeNotAllowed:
|
|
return policy_pb.PasswordlessType_PASSWORDLESS_TYPE_NOT_ALLOWED
|
|
default:
|
|
return policy_pb.PasswordlessType_PASSWORDLESS_TYPE_NOT_ALLOWED
|
|
}
|
|
}
|