mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
98 lines
3.1 KiB
Go
98 lines
3.1 KiB
Go
|
package system
|
||
|
|
||
|
import (
|
||
|
instance_grpc "github.com/caos/zitadel/internal/api/grpc/instance"
|
||
|
"github.com/caos/zitadel/internal/api/grpc/object"
|
||
|
"github.com/caos/zitadel/internal/command"
|
||
|
"github.com/caos/zitadel/internal/query"
|
||
|
instance_pb "github.com/caos/zitadel/pkg/grpc/instance"
|
||
|
system_pb "github.com/caos/zitadel/pkg/grpc/system"
|
||
|
)
|
||
|
|
||
|
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
|
||
|
}
|
||
|
if req.OwnerEmail != "" {
|
||
|
defaultInstance.Org.Human.Email.Address = req.OwnerEmail
|
||
|
}
|
||
|
if req.OwnerUsername != "" {
|
||
|
defaultInstance.Org.Human.Username = req.OwnerUsername
|
||
|
}
|
||
|
if req.OwnerFirstName != "" {
|
||
|
defaultInstance.Org.Human.FirstName = req.OwnerFirstName
|
||
|
}
|
||
|
if req.OwnerLastName != "" {
|
||
|
defaultInstance.Org.Human.LastName = req.OwnerLastName
|
||
|
}
|
||
|
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{}
|
||
|
}
|
||
|
}
|