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 passwordAgePolicyFromModel(policy *model.PasswordAgePolicy) *management.PasswordAgePolicy {
|
2020-05-14 09:48:57 +00:00
|
|
|
creationDate, err := ptypes.TimestampProto(policy.CreationDate)
|
|
|
|
logging.Log("GRPC-6ILdB").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.TimestampProto(policy.ChangeDate)
|
|
|
|
logging.Log("GRPC-ngUzJ").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
return &management.PasswordAgePolicy{
|
2020-05-14 09:48:57 +00:00
|
|
|
Id: policy.AggregateID,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: policy.Sequence,
|
|
|
|
Description: policy.Description,
|
|
|
|
ExpireWarnDays: policy.ExpireWarnDays,
|
|
|
|
MaxAgeDays: policy.MaxAgeDays,
|
|
|
|
IsDefault: policy.AggregateID == "",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func passwordAgePolicyToModel(policy *management.PasswordAgePolicy) *model.PasswordAgePolicy {
|
2020-05-14 09:48:57 +00:00
|
|
|
creationDate, err := ptypes.Timestamp(policy.CreationDate)
|
|
|
|
logging.Log("GRPC-2QSfU").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
changeDate, err := ptypes.Timestamp(policy.ChangeDate)
|
|
|
|
logging.Log("GRPC-LdU91").OnError(err).Debug("unable to parse timestamp")
|
|
|
|
|
|
|
|
return &model.PasswordAgePolicy{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: policy.Id,
|
|
|
|
CreationDate: creationDate,
|
|
|
|
ChangeDate: changeDate,
|
|
|
|
Sequence: policy.Sequence,
|
|
|
|
},
|
|
|
|
Description: policy.Description,
|
|
|
|
ExpireWarnDays: policy.ExpireWarnDays,
|
|
|
|
MaxAgeDays: policy.MaxAgeDays,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func passwordAgePolicyCreateToModel(policy *management.PasswordAgePolicyCreate) *model.PasswordAgePolicy {
|
2020-05-14 09:48:57 +00:00
|
|
|
return &model.PasswordAgePolicy{
|
|
|
|
Description: policy.Description,
|
|
|
|
ExpireWarnDays: policy.ExpireWarnDays,
|
|
|
|
MaxAgeDays: policy.MaxAgeDays,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 11:56:37 +00:00
|
|
|
func passwordAgePolicyUpdateToModel(policy *management.PasswordAgePolicyUpdate) *model.PasswordAgePolicy {
|
2020-05-14 09:48:57 +00:00
|
|
|
return &model.PasswordAgePolicy{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: policy.Id,
|
|
|
|
},
|
|
|
|
Description: policy.Description,
|
|
|
|
ExpireWarnDays: policy.ExpireWarnDays,
|
|
|
|
MaxAgeDays: policy.MaxAgeDays,
|
|
|
|
}
|
|
|
|
}
|