2022-04-21 10:37:39 +00:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2022-04-28 08:30:41 +00:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
instance_grpc "github.com/zitadel/zitadel/internal/api/grpc/instance"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
|
|
instance_pb "github.com/zitadel/zitadel/pkg/grpc/instance"
|
|
|
|
system_pb "github.com/zitadel/zitadel/pkg/grpc/system"
|
2022-04-21 10:37:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func AddInstancePbToSetupInstance(req *system_pb.AddInstanceRequest, defaultInstance command.InstanceSetup) *command.InstanceSetup {
|
|
|
|
if req.InstanceName != "" {
|
|
|
|
defaultInstance.InstanceName = req.InstanceName
|
|
|
|
defaultInstance.Org.Name = req.InstanceName
|
|
|
|
}
|
|
|
|
if req.CustomDomain != "" {
|
|
|
|
defaultInstance.CustomDomain = req.CustomDomain
|
|
|
|
}
|
|
|
|
if req.FirstOrgName != "" {
|
|
|
|
defaultInstance.Org.Name = req.FirstOrgName
|
|
|
|
}
|
2022-04-27 15:18:34 +00:00
|
|
|
if req.OwnerEmail.Email != "" {
|
|
|
|
defaultInstance.Org.Human.Email.Address = req.OwnerEmail.Email
|
|
|
|
defaultInstance.Org.Human.Email.Verified = req.OwnerEmail.IsEmailVerified
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
2022-04-27 15:18:34 +00:00
|
|
|
if req.OwnerProfile != nil {
|
|
|
|
if req.OwnerProfile.FirstName != "" {
|
|
|
|
defaultInstance.Org.Human.FirstName = req.OwnerProfile.FirstName
|
|
|
|
}
|
|
|
|
if req.OwnerProfile.LastName != "" {
|
|
|
|
defaultInstance.Org.Human.LastName = req.OwnerProfile.LastName
|
|
|
|
}
|
|
|
|
if req.OwnerProfile.PreferredLanguage != "" {
|
|
|
|
lang, err := language.Parse(req.OwnerProfile.PreferredLanguage)
|
|
|
|
if err == nil {
|
2022-04-28 08:30:41 +00:00
|
|
|
defaultInstance.Org.Human.PreferredLanguage = lang
|
2022-04-27 15:18:34 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
2022-04-27 15:18:34 +00:00
|
|
|
if req.OwnerUserName != "" {
|
|
|
|
defaultInstance.Org.Human.Username = req.OwnerUserName
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
2022-04-27 15:18:34 +00:00
|
|
|
if req.OwnerPassword != nil {
|
|
|
|
defaultInstance.Org.Human.Password = req.OwnerPassword.Password
|
|
|
|
defaultInstance.Org.Human.PasswordChangeRequired = req.OwnerPassword.PasswordChangeRequired
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
2022-05-03 13:58:38 +00:00
|
|
|
if lang := language.Make(req.DefaultLanguage); lang != language.Und {
|
|
|
|
defaultInstance.DefaultLanguage = lang
|
|
|
|
}
|
2022-04-27 15:18:34 +00:00
|
|
|
|
2022-04-21 10:37:39 +00:00
|
|
|
return &defaultInstance
|
|
|
|
}
|
|
|
|
func ListInstancesRequestToModel(req *system_pb.ListInstancesRequest) (*query.InstanceSearchQueries, error) {
|
|
|
|
offset, limit, asc := object.ListQueryToModel(req.Query)
|
|
|
|
queries, err := instance_grpc.InstanceQueriesToModel(req.Queries)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &query.InstanceSearchQueries{
|
|
|
|
SearchRequest: query.SearchRequest{
|
|
|
|
Offset: offset,
|
|
|
|
Limit: limit,
|
|
|
|
Asc: asc,
|
|
|
|
SortingColumn: fieldNameToInstanceColumn(req.SortingColumn),
|
|
|
|
},
|
|
|
|
Queries: queries,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func fieldNameToInstanceColumn(fieldName instance_pb.FieldName) query.Column {
|
|
|
|
switch fieldName {
|
|
|
|
case instance_pb.FieldName_FIELD_NAME_ID:
|
|
|
|
return query.InstanceColumnID
|
|
|
|
case instance_pb.FieldName_FIELD_NAME_NAME:
|
|
|
|
return query.InstanceColumnName
|
|
|
|
case instance_pb.FieldName_FIELD_NAME_CREATION_DATE:
|
|
|
|
return query.InstanceColumnCreationDate
|
|
|
|
default:
|
|
|
|
return query.Column{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ListInstanceDomainsRequestToModel(req *system_pb.ListDomainsRequest) (*query.InstanceDomainSearchQueries, error) {
|
|
|
|
offset, limit, asc := object.ListQueryToModel(req.Query)
|
|
|
|
queries, err := instance_grpc.DomainQueriesToModel(req.Queries)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &query.InstanceDomainSearchQueries{
|
|
|
|
SearchRequest: query.SearchRequest{
|
|
|
|
Offset: offset,
|
|
|
|
Limit: limit,
|
|
|
|
Asc: asc,
|
|
|
|
SortingColumn: fieldNameToInstanceDomainColumn(req.SortingColumn),
|
|
|
|
},
|
|
|
|
Queries: queries,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func fieldNameToInstanceDomainColumn(fieldName instance_pb.DomainFieldName) query.Column {
|
|
|
|
switch fieldName {
|
|
|
|
case instance_pb.DomainFieldName_DOMAIN_FIELD_NAME_DOMAIN:
|
|
|
|
return query.InstanceDomainDomainCol
|
|
|
|
case instance_pb.DomainFieldName_DOMAIN_FIELD_NAME_GENERATED:
|
|
|
|
return query.InstanceDomainIsGeneratedCol
|
|
|
|
case instance_pb.DomainFieldName_DOMAIN_FIELD_NAME_PRIMARY:
|
|
|
|
return query.InstanceDomainIsPrimaryCol
|
|
|
|
case instance_pb.DomainFieldName_DOMAIN_FIELD_NAME_CREATION_DATE:
|
|
|
|
return query.InstanceDomainCreationDateCol
|
|
|
|
default:
|
|
|
|
return query.Column{}
|
|
|
|
}
|
|
|
|
}
|