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/query"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2022-04-26 23:01:45 +00:00
|
|
|
meta_pb "github.com/zitadel/zitadel/pkg/grpc/metadata"
|
2021-08-09 06:01:20 +00:00
|
|
|
)
|
|
|
|
|
2022-09-20 14:32:09 +00:00
|
|
|
func UserMetadataListToPb(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 {
|
2022-09-20 14:32:09 +00:00
|
|
|
mds[i] = UserMetadataToPb(data)
|
2021-08-09 06:01:20 +00:00
|
|
|
}
|
|
|
|
return mds
|
|
|
|
}
|
|
|
|
|
2022-09-20 14:32:09 +00:00
|
|
|
func UserMetadataToPb(data *query.UserMetadata) *meta_pb.Metadata {
|
|
|
|
return &meta_pb.Metadata{
|
|
|
|
Key: data.Key,
|
|
|
|
Value: data.Value,
|
|
|
|
Details: object.ToViewDetailsPb(
|
|
|
|
data.Sequence,
|
|
|
|
data.CreationDate,
|
|
|
|
data.ChangeDate,
|
|
|
|
data.ResourceOwner,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func OrgMetadataListToPb(dataList []*query.OrgMetadata) []*meta_pb.Metadata {
|
|
|
|
mds := make([]*meta_pb.Metadata, len(dataList))
|
|
|
|
for i, data := range dataList {
|
|
|
|
mds[i] = OrgMetadataToPb(data)
|
|
|
|
}
|
|
|
|
return mds
|
|
|
|
}
|
|
|
|
|
|
|
|
func OrgMetadataToPb(data *query.OrgMetadata) *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,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 14:56:58 +00:00
|
|
|
func OrgMetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) {
|
2022-01-20 14:40:25 +00:00
|
|
|
q := make([]query.SearchQuery, len(queries))
|
2021-08-09 06:01:20 +00:00
|
|
|
for i, query := range queries {
|
2024-03-21 14:56:58 +00:00
|
|
|
q[i], err = OrgMetadataQueryToQuery(query)
|
2022-01-20 14:40:25 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-03-21 14:56:58 +00:00
|
|
|
func OrgMetadataQueryToQuery(metadataQuery *meta_pb.MetadataQuery) (query.SearchQuery, error) {
|
|
|
|
switch q := metadataQuery.Query.(type) {
|
2021-08-09 06:01:20 +00:00
|
|
|
case *meta_pb.MetadataQuery_KeyQuery:
|
2024-03-21 14:56:58 +00:00
|
|
|
return query.NewOrgMetadataKeySearchQuery(q.KeyQuery.Key, object.TextMethodToQuery(q.KeyQuery.Method))
|
2021-08-09 06:01:20 +00:00
|
|
|
default:
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "METAD-fdg23", "List.Query.Invalid")
|
2021-08-09 06:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 14:56:58 +00:00
|
|
|
func UserMetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) {
|
|
|
|
q := make([]query.SearchQuery, len(queries))
|
|
|
|
for i, query := range queries {
|
|
|
|
q[i], err = UserMetadataQueryToQuery(query)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return q, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func UserMetadataQueryToQuery(metadataQuery *meta_pb.MetadataQuery) (query.SearchQuery, error) {
|
|
|
|
switch q := metadataQuery.Query.(type) {
|
|
|
|
case *meta_pb.MetadataQuery_KeyQuery:
|
|
|
|
return query.NewUserMetadataKeySearchQuery(q.KeyQuery.Key, object.TextMethodToQuery(q.KeyQuery.Method))
|
|
|
|
default:
|
|
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "METAD-Vn7qy", "List.Query.Invalid")
|
|
|
|
}
|
2021-08-09 06:01:20 +00:00
|
|
|
}
|