2021-08-09 06:01:20 +00:00
|
|
|
package metadata
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
|
|
meta_pb "github.com/zitadel/zitadel/pkg/grpc/metadata"
|
2021-08-09 06:01:20 +00:00
|
|
|
)
|
|
|
|
|
2022-01-20 14:40:25 +00:00
|
|
|
func MetadataListToPb(dataList []*query.UserMetadata) []*meta_pb.Metadata {
|
2021-08-09 06:01:20 +00:00
|
|
|
mds := make([]*meta_pb.Metadata, len(dataList))
|
|
|
|
for i, data := range dataList {
|
|
|
|
mds[i] = DomainMetadataToPb(data)
|
|
|
|
}
|
|
|
|
return mds
|
|
|
|
}
|
|
|
|
|
2022-01-20 14:40:25 +00:00
|
|
|
func DomainMetadataToPb(data *query.UserMetadata) *meta_pb.Metadata {
|
2021-08-09 06:01:20 +00:00
|
|
|
return &meta_pb.Metadata{
|
|
|
|
Key: data.Key,
|
|
|
|
Value: data.Value,
|
|
|
|
Details: object.ToViewDetailsPb(
|
|
|
|
data.Sequence,
|
|
|
|
data.CreationDate,
|
|
|
|
data.ChangeDate,
|
|
|
|
data.ResourceOwner,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 14:40:25 +00:00
|
|
|
func MetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) {
|
|
|
|
q := make([]query.SearchQuery, len(queries))
|
2021-08-09 06:01:20 +00:00
|
|
|
for i, query := range queries {
|
2022-01-20 14:40:25 +00:00
|
|
|
q[i], err = MetadataQueryToQuery(query)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-09 06:01:20 +00:00
|
|
|
}
|
2022-01-20 14:40:25 +00:00
|
|
|
return q, nil
|
2021-08-09 06:01:20 +00:00
|
|
|
}
|
|
|
|
|
2022-01-20 14:40:25 +00:00
|
|
|
func MetadataQueryToQuery(query *meta_pb.MetadataQuery) (query.SearchQuery, error) {
|
2021-08-09 06:01:20 +00:00
|
|
|
switch q := query.Query.(type) {
|
|
|
|
case *meta_pb.MetadataQuery_KeyQuery:
|
2022-01-20 14:40:25 +00:00
|
|
|
return MetadataKeyQueryToQuery(q.KeyQuery)
|
2021-08-09 06:01:20 +00:00
|
|
|
default:
|
2022-01-20 14:40:25 +00:00
|
|
|
return nil, errors.ThrowInvalidArgument(nil, "METAD-fdg23", "List.Query.Invalid")
|
2021-08-09 06:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 14:40:25 +00:00
|
|
|
func MetadataKeyQueryToQuery(q *meta_pb.MetadataKeyQuery) (query.SearchQuery, error) {
|
|
|
|
return query.NewUserMetadataKeySearchQuery(q.Key, object.TextMethodToQuery(q.Method))
|
2021-08-09 06:01:20 +00:00
|
|
|
}
|