From bc7ba530d438bb8a10ef86082a4ce05f13feefc4 Mon Sep 17 00:00:00 2001 From: Arnaud Delcasse Date: Wed, 14 Jan 2026 00:38:18 +0100 Subject: [PATCH] Add metadate management in grpc --- grpcapi/accounts.go | 24 ++++++++++++++++++++++++ grpcapi/accounts.pb.go | 30 ++++++++++++++++++++---------- grpcapi/accounts.proto | 3 ++- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/grpcapi/accounts.go b/grpcapi/accounts.go index 998bb56..c6184d7 100755 --- a/grpcapi/accounts.go +++ b/grpcapi/accounts.go @@ -19,6 +19,7 @@ func (a Account) ToStorageType() storage.Account { ID: a.Id, Namespace: a.Namespace, Data: map[string]any{}, + Metadata: map[string]any{}, Authentication: storage.AccountAuth{ Local: localauth, }, @@ -35,6 +36,17 @@ func (a Account) ToStorageType() storage.Account { account.Data[k] = data } + for k, d := range a.Metadata.GetFields() { + jsondata, err := protojson.Marshal(d) + if err != nil { + log.Error().Err(err).Msg("") + break + } + var data any + json.Unmarshal(jsondata, &data) + account.Metadata[k] = data + } + return account } @@ -84,10 +96,22 @@ func AccountFromStorageType(account *storage.Account) (*Account, error) { return nil, err } + m, err := sanitizeData(account.Metadata) + if err != nil { + return nil, err + } + + metadata, err := structpb.NewStruct(m) + if err != nil { + log.Error().Err(err).Msg("") + return nil, err + } + return &Account{ Id: account.ID, Namespace: account.Namespace, Data: data, + Metadata: metadata, Authentication: &AccountAuth{ Local: lc, }, diff --git a/grpcapi/accounts.pb.go b/grpcapi/accounts.pb.go index 160f6b6..fac0591 100755 --- a/grpcapi/accounts.pb.go +++ b/grpcapi/accounts.pb.go @@ -28,6 +28,7 @@ type Account struct { Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,omitempty"` Authentication *AccountAuth `protobuf:"bytes,3,opt,name=authentication,proto3" json:"authentication,omitempty"` Data *structpb.Struct `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` + Metadata *structpb.Struct `protobuf:"bytes,5,opt,name=metadata,proto3" json:"metadata,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -90,6 +91,13 @@ func (x *Account) GetData() *structpb.Struct { return nil } +func (x *Account) GetMetadata() *structpb.Struct { + if x != nil { + return x.Metadata + } + return nil +} + type AccountAuth struct { state protoimpl.MessageState `protogen:"open.v1"` Local *LocalAuth `protobuf:"bytes,7,opt,name=local,proto3,oneof" json:"local,omitempty"` //TODO SSO @@ -274,12 +282,13 @@ var File_accounts_proto protoreflect.FileDescriptor const file_accounts_proto_rawDesc = "" + "\n" + - "\x0eaccounts.proto\x1a\x1cgoogle/protobuf/struct.proto\"\x9a\x01\n" + + "\x0eaccounts.proto\x1a\x1cgoogle/protobuf/struct.proto\"\xcf\x01\n" + "\aAccount\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x12\x1c\n" + "\tnamespace\x18\x02 \x01(\tR\tnamespace\x124\n" + "\x0eauthentication\x18\x03 \x01(\v2\f.AccountAuthR\x0eauthentication\x12+\n" + - "\x04data\x18\x04 \x01(\v2\x17.google.protobuf.StructR\x04data\">\n" + + "\x04data\x18\x04 \x01(\v2\x17.google.protobuf.StructR\x04data\x123\n" + + "\bmetadata\x18\x05 \x01(\v2\x17.google.protobuf.StructR\bmetadata\">\n" + "\vAccountAuth\x12%\n" + "\x05local\x18\a \x01(\v2\n" + ".LocalAuthH\x00R\x05local\x88\x01\x01B\b\n" + @@ -325,14 +334,15 @@ var file_accounts_proto_goTypes = []any{ var file_accounts_proto_depIdxs = []int32{ 1, // 0: Account.authentication:type_name -> AccountAuth 4, // 1: Account.data:type_name -> google.protobuf.Struct - 2, // 2: AccountAuth.local:type_name -> LocalAuth - 3, // 3: LocalAuth.email_validation:type_name -> Validation - 3, // 4: LocalAuth.phone_number_validation:type_name -> Validation - 5, // [5:5] is the sub-list for method output_type - 5, // [5:5] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name + 4, // 2: Account.metadata:type_name -> google.protobuf.Struct + 2, // 3: AccountAuth.local:type_name -> LocalAuth + 3, // 4: LocalAuth.email_validation:type_name -> Validation + 3, // 5: LocalAuth.phone_number_validation:type_name -> Validation + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_accounts_proto_init() } diff --git a/grpcapi/accounts.proto b/grpcapi/accounts.proto index b8dceb3..f36e6ab 100755 --- a/grpcapi/accounts.proto +++ b/grpcapi/accounts.proto @@ -6,9 +6,10 @@ import "google/protobuf/struct.proto"; message Account { string id = 1; - string namespace = 2; + string namespace = 2; AccountAuth authentication = 3; google.protobuf.Struct data = 4; + google.protobuf.Struct metadata = 5; } message AccountAuth {