2020-07-08 11:56:37 +00:00
|
|
|
package management
|
2020-05-14 09:48:57 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/logging"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
|
|
|
2020-05-14 09:48:57 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
"github.com/caos/zitadel/internal/policy/model"
|
2020-07-08 11:56:37 +00:00
|
|
|
"github.com/caos/zitadel/pkg/grpc/management"
|
2020-05-14 09:48:57 +00:00
|
|
|
)
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func passwordComplexityPolicyFromModel(policy *model.PasswordComplexityPolicy) *management.PasswordComplexityPolicy {
|
2020-05-14 09:48:57 +00:00
|
|
|
creationDate, err := ptypes.TimestampProto(policy.CreationDate)
|
|
|
|
logging.Log("GRPC-cQRHE").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(policy.ChangeDate)
|
|
|
|
logging.Log("GRPC-PVA1c").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
return &management.PasswordComplexityPolicy{
|
2020-05-14 09:48:57 +00:00
|
|
|
Id: policy.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Description: policy.Description,
|
|
|
|
Sequence: policy.Sequence,
|
|
|
|
MinLength: policy.MinLength,
|
|
|
|
HasLowercase: policy.HasLowercase,
|
|
|
|
HasUppercase: policy.HasUppercase,
|
|
|
|
HasNumber: policy.HasNumber,
|
|
|
|
HasSymbol: policy.HasSymbol,
|
|
|
|
IsDefault: policy.AggregateID == "",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func passwordComplexityPolicyToModel(policy *management.PasswordComplexityPolicy) *model.PasswordComplexityPolicy {
|
2020-05-14 09:48:57 +00:00
|
|
|
creationDate, err := ptypes.Timestamp(policy.CreationDate)
|
|
|
|
logging.Log("GRPC-asmEZ").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.Timestamp(policy.ChangeDate)
|
|
|
|
logging.Log("GRPC-MCE4o").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &model.PasswordComplexityPolicy{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: policy.Id,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: policy.Sequence,
|
|
|
|
},
|
|
|
|
Description: policy.Description,
|
|
|
|
MinLength: policy.MinLength,
|
|
|
|
HasLowercase: policy.HasLowercase,
|
|
|
|
HasUppercase: policy.HasUppercase,
|
|
|
|
HasNumber: policy.HasNumber,
|
|
|
|
HasSymbol: policy.HasSymbol,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func passwordComplexityPolicyCreateToModel(policy *management.PasswordComplexityPolicyCreate) *model.PasswordComplexityPolicy {
|
2020-05-14 09:48:57 +00:00
|
|
|
return &model.PasswordComplexityPolicy{
|
|
|
|
Description: policy.Description,
|
|
|
|
MinLength: policy.MinLength,
|
|
|
|
HasLowercase: policy.HasLowercase,
|
|
|
|
HasUppercase: policy.HasUppercase,
|
|
|
|
HasNumber: policy.HasNumber,
|
|
|
|
HasSymbol: policy.HasSymbol,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func passwordComplexityPolicyUpdateToModel(policy *management.PasswordComplexityPolicyUpdate) *model.PasswordComplexityPolicy {
|
2020-05-14 09:48:57 +00:00
|
|
|
return &model.PasswordComplexityPolicy{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: policy.Id,
|
|
|
|
},
|
|
|
|
Description: policy.Description,
|
|
|
|
MinLength: policy.MinLength,
|
|
|
|
HasLowercase: policy.HasLowercase,
|
|
|
|
HasUppercase: policy.HasUppercase,
|
|
|
|
HasNumber: policy.HasNumber,
|
|
|
|
HasSymbol: policy.HasSymbol,
|
|
|
|
}
|
|
|
|
}
|