Add missing gRPC functions

This commit is contained in:
Arnaud Delcasse 2022-08-11 17:14:21 +02:00
parent 26090e9299
commit 6530d024f8
12 changed files with 448 additions and 164 deletions

View File

@ -46,12 +46,18 @@ func (lc LocalAuth) ToStorageType() storage.LocalAuth {
} }
} }
func AccountFromStorageType(account *storage.Account) *Account { func AccountFromStorageType(account *storage.Account) (*Account, error) {
lc := LocalAuthFromStorageType(account.Authentication.Local) lc := LocalAuthFromStorageType(account.Authentication.Local)
data, err := structpb.NewStruct(account.Data) d, err := sanitizeData(account.Data)
if err != nil { if err != nil {
return nil return nil, err
}
data, err := structpb.NewStruct(d)
if err != nil {
fmt.Println(err)
return nil, err
} }
return &Account{ return &Account{
@ -61,7 +67,7 @@ func AccountFromStorageType(account *storage.Account) *Account {
Authentication: &AccountAuth{ Authentication: &AccountAuth{
Local: lc, Local: lc,
}, },
} }, nil
} }
func LocalAuthFromStorageType(lc storage.LocalAuth) *LocalAuth { func LocalAuthFromStorageType(lc storage.LocalAuth) *LocalAuth {
@ -72,3 +78,16 @@ func LocalAuthFromStorageType(lc storage.LocalAuth) *LocalAuth {
PhoneNumber: lc.PhoneNumber, PhoneNumber: lc.PhoneNumber,
} }
} }
func sanitizeData(data map[string]any) (d map[string]any, err error) {
j, err := json.Marshal(data)
if err != nil {
return nil, err
}
if err = json.Unmarshal(j, &d); err != nil {
return nil, err
}
return d, nil
}

View File

@ -524,6 +524,100 @@ func (x *GetAccountsResponse) GetAccounts() []*Account {
return nil return nil
} }
type GetAccountsBatchRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Accountids []string `protobuf:"bytes,13,rep,name=accountids,proto3" json:"accountids,omitempty"` // Filter on namespaces
}
func (x *GetAccountsBatchRequest) Reset() {
*x = GetAccountsBatchRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_comasvc_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetAccountsBatchRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetAccountsBatchRequest) ProtoMessage() {}
func (x *GetAccountsBatchRequest) ProtoReflect() protoreflect.Message {
mi := &file_comasvc_proto_msgTypes[10]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetAccountsBatchRequest.ProtoReflect.Descriptor instead.
func (*GetAccountsBatchRequest) Descriptor() ([]byte, []int) {
return file_comasvc_proto_rawDescGZIP(), []int{10}
}
func (x *GetAccountsBatchRequest) GetAccountids() []string {
if x != nil {
return x.Accountids
}
return nil
}
type GetAccountsBatchResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Accounts []*Account `protobuf:"bytes,14,rep,name=accounts,proto3" json:"accounts,omitempty"`
}
func (x *GetAccountsBatchResponse) Reset() {
*x = GetAccountsBatchResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_comasvc_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetAccountsBatchResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetAccountsBatchResponse) ProtoMessage() {}
func (x *GetAccountsBatchResponse) ProtoReflect() protoreflect.Message {
mi := &file_comasvc_proto_msgTypes[11]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetAccountsBatchResponse.ProtoReflect.Descriptor instead.
func (*GetAccountsBatchResponse) Descriptor() ([]byte, []int) {
return file_comasvc_proto_rawDescGZIP(), []int{11}
}
func (x *GetAccountsBatchResponse) GetAccounts() []*Account {
if x != nil {
return x.Accounts
}
return nil
}
type ChangePasswordRequest struct { type ChangePasswordRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -536,7 +630,7 @@ type ChangePasswordRequest struct {
func (x *ChangePasswordRequest) Reset() { func (x *ChangePasswordRequest) Reset() {
*x = ChangePasswordRequest{} *x = ChangePasswordRequest{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_comasvc_proto_msgTypes[10] mi := &file_comasvc_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -549,7 +643,7 @@ func (x *ChangePasswordRequest) String() string {
func (*ChangePasswordRequest) ProtoMessage() {} func (*ChangePasswordRequest) ProtoMessage() {}
func (x *ChangePasswordRequest) ProtoReflect() protoreflect.Message { func (x *ChangePasswordRequest) ProtoReflect() protoreflect.Message {
mi := &file_comasvc_proto_msgTypes[10] mi := &file_comasvc_proto_msgTypes[12]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -562,7 +656,7 @@ func (x *ChangePasswordRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use ChangePasswordRequest.ProtoReflect.Descriptor instead. // Deprecated: Use ChangePasswordRequest.ProtoReflect.Descriptor instead.
func (*ChangePasswordRequest) Descriptor() ([]byte, []int) { func (*ChangePasswordRequest) Descriptor() ([]byte, []int) {
return file_comasvc_proto_rawDescGZIP(), []int{10} return file_comasvc_proto_rawDescGZIP(), []int{12}
} }
func (x *ChangePasswordRequest) GetId() string { func (x *ChangePasswordRequest) GetId() string {
@ -588,7 +682,7 @@ type ChangePasswordResponse struct {
func (x *ChangePasswordResponse) Reset() { func (x *ChangePasswordResponse) Reset() {
*x = ChangePasswordResponse{} *x = ChangePasswordResponse{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_comasvc_proto_msgTypes[11] mi := &file_comasvc_proto_msgTypes[13]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -601,7 +695,7 @@ func (x *ChangePasswordResponse) String() string {
func (*ChangePasswordResponse) ProtoMessage() {} func (*ChangePasswordResponse) ProtoMessage() {}
func (x *ChangePasswordResponse) ProtoReflect() protoreflect.Message { func (x *ChangePasswordResponse) ProtoReflect() protoreflect.Message {
mi := &file_comasvc_proto_msgTypes[11] mi := &file_comasvc_proto_msgTypes[13]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -614,7 +708,7 @@ func (x *ChangePasswordResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use ChangePasswordResponse.ProtoReflect.Descriptor instead. // Deprecated: Use ChangePasswordResponse.ProtoReflect.Descriptor instead.
func (*ChangePasswordResponse) Descriptor() ([]byte, []int) { func (*ChangePasswordResponse) Descriptor() ([]byte, []int) {
return file_comasvc_proto_rawDescGZIP(), []int{11} return file_comasvc_proto_rawDescGZIP(), []int{13}
} }
var File_comasvc_proto protoreflect.FileDescriptor var File_comasvc_proto protoreflect.FileDescriptor
@ -662,39 +756,52 @@ var file_comasvc_proto_rawDesc = []byte{
0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x12, 0x24, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x0e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x0e,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x08,
0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0x43, 0x0a, 0x15, 0x43, 0x68, 0x61, 0x6e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0x39, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x41,
0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75,
0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x69, 0x64,
0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x10, 0x20, 0x73, 0x18, 0x0d, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74,
0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x18, 0x0a, 0x69, 0x64, 0x73, 0x22, 0x40, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e,
0x16, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x74, 0x73, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xe2, 0x02, 0x0a, 0x10, 0x4d, 0x6f, 0x62, 0x69, 0x24, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x0e, 0x20, 0x03, 0x28,
0x6c, 0x69, 0x74, 0x79, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x31, 0x0a, 0x08, 0x0b, 0x32, 0x08, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x08, 0x61, 0x63, 0x63,
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x10, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0x43, 0x0a, 0x15, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50,
0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x52, 0x65, 0x67, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e,
0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a,
0x37, 0x0a, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x12, 0x2e, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09,
0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x18, 0x0a, 0x16, 0x43, 0x68,
0x74, 0x1a, 0x13, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x41, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xad, 0x03, 0x0a, 0x10, 0x4d, 0x6f, 0x62, 0x69, 0x6c, 0x69, 0x74,
0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x12, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x79, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x31, 0x0a, 0x08, 0x52, 0x65, 0x67,
0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x47, 0x65, 0x74, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x10, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72,
0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74,
0x00, 0x12, 0x3a, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x0a,
0x12, 0x13, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x12, 0x2e, 0x55, 0x70, 0x64,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13,
0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x28, 0x0a, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x0d, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6e, 0x74, 0x12, 0x12, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63,
0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x16, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a,
0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x13, 0x2e,
0x74, 0x1a, 0x17, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65,
0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73,
0x67, 0x69, 0x74, 0x2e, 0x63, 0x6f, 0x6f, 0x70, 0x67, 0x6f, 0x2e, 0x69, 0x6f, 0x2f, 0x63, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x49, 0x0a, 0x10, 0x47, 0x65,
0x6f, 0x70, 0x67, 0x6f, 0x2d, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x2f, 0x6d, 0x6f, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x18,
0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2d, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x42, 0x61, 0x74, 0x63,
0x67, 0x72, 0x70, 0x63, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x63,
0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x42, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x28, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x0d,
0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e,
0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12,
0x43, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72,
0x64, 0x12, 0x16, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f,
0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x43, 0x68, 0x61, 0x6e,
0x67, 0x65, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x2e, 0x63, 0x6f, 0x6f, 0x70,
0x67, 0x6f, 0x2e, 0x69, 0x6f, 0x2f, 0x63, 0x6f, 0x6f, 0x70, 0x67, 0x6f, 0x2d, 0x70, 0x6c, 0x61,
0x74, 0x66, 0x6f, 0x72, 0x6d, 0x2f, 0x6d, 0x6f, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x2d, 0x61,
0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x61, 0x70, 0x69, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -709,7 +816,7 @@ func file_comasvc_proto_rawDescGZIP() []byte {
return file_comasvc_proto_rawDescData return file_comasvc_proto_rawDescData
} }
var file_comasvc_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_comasvc_proto_msgTypes = make([]protoimpl.MessageInfo, 14)
var file_comasvc_proto_goTypes = []interface{}{ var file_comasvc_proto_goTypes = []interface{}{
(*LoginRequest)(nil), // 0: LoginRequest (*LoginRequest)(nil), // 0: LoginRequest
(*LoginResponse)(nil), // 1: LoginResponse (*LoginResponse)(nil), // 1: LoginResponse
@ -721,35 +828,40 @@ var file_comasvc_proto_goTypes = []interface{}{
(*GetAccountResponse)(nil), // 7: GetAccountResponse (*GetAccountResponse)(nil), // 7: GetAccountResponse
(*GetAccountsRequest)(nil), // 8: GetAccountsRequest (*GetAccountsRequest)(nil), // 8: GetAccountsRequest
(*GetAccountsResponse)(nil), // 9: GetAccountsResponse (*GetAccountsResponse)(nil), // 9: GetAccountsResponse
(*ChangePasswordRequest)(nil), // 10: ChangePasswordRequest (*GetAccountsBatchRequest)(nil), // 10: GetAccountsBatchRequest
(*ChangePasswordResponse)(nil), // 11: ChangePasswordResponse (*GetAccountsBatchResponse)(nil), // 11: GetAccountsBatchResponse
(*Account)(nil), // 12: Account (*ChangePasswordRequest)(nil), // 12: ChangePasswordRequest
(*ChangePasswordResponse)(nil), // 13: ChangePasswordResponse
(*Account)(nil), // 14: Account
} }
var file_comasvc_proto_depIdxs = []int32{ var file_comasvc_proto_depIdxs = []int32{
12, // 0: LoginResponse.account:type_name -> Account 14, // 0: LoginResponse.account:type_name -> Account
12, // 1: RegisterRequest.account:type_name -> Account 14, // 1: RegisterRequest.account:type_name -> Account
12, // 2: RegisterResponse.account:type_name -> Account 14, // 2: RegisterResponse.account:type_name -> Account
12, // 3: UpdateDataRequest.account:type_name -> Account 14, // 3: UpdateDataRequest.account:type_name -> Account
12, // 4: UpdateDataResponse.account:type_name -> Account 14, // 4: UpdateDataResponse.account:type_name -> Account
12, // 5: GetAccountResponse.account:type_name -> Account 14, // 5: GetAccountResponse.account:type_name -> Account
12, // 6: GetAccountsResponse.accounts:type_name -> Account 14, // 6: GetAccountsResponse.accounts:type_name -> Account
2, // 7: MobilityAccounts.Register:input_type -> RegisterRequest 14, // 7: GetAccountsBatchResponse.accounts:type_name -> Account
4, // 8: MobilityAccounts.UpdateData:input_type -> UpdateDataRequest 2, // 8: MobilityAccounts.Register:input_type -> RegisterRequest
6, // 9: MobilityAccounts.GetAccount:input_type -> GetAccountRequest 4, // 9: MobilityAccounts.UpdateData:input_type -> UpdateDataRequest
8, // 10: MobilityAccounts.GetAccounts:input_type -> GetAccountsRequest 6, // 10: MobilityAccounts.GetAccount:input_type -> GetAccountRequest
0, // 11: MobilityAccounts.Login:input_type -> LoginRequest 8, // 11: MobilityAccounts.GetAccounts:input_type -> GetAccountsRequest
10, // 12: MobilityAccounts.ChangePassword:input_type -> ChangePasswordRequest 10, // 12: MobilityAccounts.GetAccountsBatch:input_type -> GetAccountsBatchRequest
3, // 13: MobilityAccounts.Register:output_type -> RegisterResponse 0, // 13: MobilityAccounts.Login:input_type -> LoginRequest
5, // 14: MobilityAccounts.UpdateData:output_type -> UpdateDataResponse 12, // 14: MobilityAccounts.ChangePassword:input_type -> ChangePasswordRequest
7, // 15: MobilityAccounts.GetAccount:output_type -> GetAccountResponse 3, // 15: MobilityAccounts.Register:output_type -> RegisterResponse
9, // 16: MobilityAccounts.GetAccounts:output_type -> GetAccountsResponse 5, // 16: MobilityAccounts.UpdateData:output_type -> UpdateDataResponse
1, // 17: MobilityAccounts.Login:output_type -> LoginResponse 7, // 17: MobilityAccounts.GetAccount:output_type -> GetAccountResponse
11, // 18: MobilityAccounts.ChangePassword:output_type -> ChangePasswordResponse 9, // 18: MobilityAccounts.GetAccounts:output_type -> GetAccountsResponse
13, // [13:19] is the sub-list for method output_type 11, // 19: MobilityAccounts.GetAccountsBatch:output_type -> GetAccountsBatchResponse
7, // [7:13] is the sub-list for method input_type 1, // 20: MobilityAccounts.Login:output_type -> LoginResponse
7, // [7:7] is the sub-list for extension type_name 13, // 21: MobilityAccounts.ChangePassword:output_type -> ChangePasswordResponse
7, // [7:7] is the sub-list for extension extendee 15, // [15:22] is the sub-list for method output_type
0, // [0:7] is the sub-list for field type_name 8, // [8:15] is the sub-list for method input_type
8, // [8:8] is the sub-list for extension type_name
8, // [8:8] is the sub-list for extension extendee
0, // [0:8] is the sub-list for field type_name
} }
func init() { file_comasvc_proto_init() } func init() { file_comasvc_proto_init() }
@ -880,7 +992,7 @@ func file_comasvc_proto_init() {
} }
} }
file_comasvc_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { file_comasvc_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ChangePasswordRequest); i { switch v := v.(*GetAccountsBatchRequest); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@ -892,6 +1004,30 @@ func file_comasvc_proto_init() {
} }
} }
file_comasvc_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { file_comasvc_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetAccountsBatchResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_comasvc_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ChangePasswordRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_comasvc_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ChangePasswordResponse); i { switch v := v.(*ChangePasswordResponse); i {
case 0: case 0:
return &v.state return &v.state
@ -910,7 +1046,7 @@ func file_comasvc_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_comasvc_proto_rawDesc, RawDescriptor: file_comasvc_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 12, NumMessages: 14,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@ -11,6 +11,7 @@ service MobilityAccounts {
rpc UpdateData(UpdateDataRequest) returns (UpdateDataResponse) {} rpc UpdateData(UpdateDataRequest) returns (UpdateDataResponse) {}
rpc GetAccount(GetAccountRequest) returns (GetAccountResponse) {} rpc GetAccount(GetAccountRequest) returns (GetAccountResponse) {}
rpc GetAccounts(GetAccountsRequest) returns (GetAccountsResponse) {} rpc GetAccounts(GetAccountsRequest) returns (GetAccountsResponse) {}
rpc GetAccountsBatch(GetAccountsBatchRequest) returns (GetAccountsBatchResponse) {}
// Authentication functions // Authentication functions
rpc Login(LoginRequest) returns (LoginResponse) {} rpc Login(LoginRequest) returns (LoginResponse) {}
@ -61,6 +62,14 @@ message GetAccountsResponse {
repeated Account accounts = 14; repeated Account accounts = 14;
} }
message GetAccountsBatchRequest {
repeated string accountids = 13; // Filter on namespaces
}
message GetAccountsBatchResponse {
repeated Account accounts = 14;
}
message ChangePasswordRequest { message ChangePasswordRequest {
string id = 15; string id = 15;
string password = 16; string password = 16;

View File

@ -26,6 +26,7 @@ type MobilityAccountsClient interface {
UpdateData(ctx context.Context, in *UpdateDataRequest, opts ...grpc.CallOption) (*UpdateDataResponse, error) UpdateData(ctx context.Context, in *UpdateDataRequest, opts ...grpc.CallOption) (*UpdateDataResponse, error)
GetAccount(ctx context.Context, in *GetAccountRequest, opts ...grpc.CallOption) (*GetAccountResponse, error) GetAccount(ctx context.Context, in *GetAccountRequest, opts ...grpc.CallOption) (*GetAccountResponse, error)
GetAccounts(ctx context.Context, in *GetAccountsRequest, opts ...grpc.CallOption) (*GetAccountsResponse, error) GetAccounts(ctx context.Context, in *GetAccountsRequest, opts ...grpc.CallOption) (*GetAccountsResponse, error)
GetAccountsBatch(ctx context.Context, in *GetAccountsBatchRequest, opts ...grpc.CallOption) (*GetAccountsBatchResponse, error)
// Authentication functions // Authentication functions
Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error)
ChangePassword(ctx context.Context, in *ChangePasswordRequest, opts ...grpc.CallOption) (*ChangePasswordResponse, error) ChangePassword(ctx context.Context, in *ChangePasswordRequest, opts ...grpc.CallOption) (*ChangePasswordResponse, error)
@ -75,6 +76,15 @@ func (c *mobilityAccountsClient) GetAccounts(ctx context.Context, in *GetAccount
return out, nil return out, nil
} }
func (c *mobilityAccountsClient) GetAccountsBatch(ctx context.Context, in *GetAccountsBatchRequest, opts ...grpc.CallOption) (*GetAccountsBatchResponse, error) {
out := new(GetAccountsBatchResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/GetAccountsBatch", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *mobilityAccountsClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) { func (c *mobilityAccountsClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) {
out := new(LoginResponse) out := new(LoginResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/Login", in, out, opts...) err := c.cc.Invoke(ctx, "/MobilityAccounts/Login", in, out, opts...)
@ -101,6 +111,7 @@ type MobilityAccountsServer interface {
UpdateData(context.Context, *UpdateDataRequest) (*UpdateDataResponse, error) UpdateData(context.Context, *UpdateDataRequest) (*UpdateDataResponse, error)
GetAccount(context.Context, *GetAccountRequest) (*GetAccountResponse, error) GetAccount(context.Context, *GetAccountRequest) (*GetAccountResponse, error)
GetAccounts(context.Context, *GetAccountsRequest) (*GetAccountsResponse, error) GetAccounts(context.Context, *GetAccountsRequest) (*GetAccountsResponse, error)
GetAccountsBatch(context.Context, *GetAccountsBatchRequest) (*GetAccountsBatchResponse, error)
// Authentication functions // Authentication functions
Login(context.Context, *LoginRequest) (*LoginResponse, error) Login(context.Context, *LoginRequest) (*LoginResponse, error)
ChangePassword(context.Context, *ChangePasswordRequest) (*ChangePasswordResponse, error) ChangePassword(context.Context, *ChangePasswordRequest) (*ChangePasswordResponse, error)
@ -123,6 +134,9 @@ func (UnimplementedMobilityAccountsServer) GetAccount(context.Context, *GetAccou
func (UnimplementedMobilityAccountsServer) GetAccounts(context.Context, *GetAccountsRequest) (*GetAccountsResponse, error) { func (UnimplementedMobilityAccountsServer) GetAccounts(context.Context, *GetAccountsRequest) (*GetAccountsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetAccounts not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetAccounts not implemented")
} }
func (UnimplementedMobilityAccountsServer) GetAccountsBatch(context.Context, *GetAccountsBatchRequest) (*GetAccountsBatchResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetAccountsBatch not implemented")
}
func (UnimplementedMobilityAccountsServer) Login(context.Context, *LoginRequest) (*LoginResponse, error) { func (UnimplementedMobilityAccountsServer) Login(context.Context, *LoginRequest) (*LoginResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Login not implemented") return nil, status.Errorf(codes.Unimplemented, "method Login not implemented")
} }
@ -214,6 +228,24 @@ func _MobilityAccounts_GetAccounts_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _MobilityAccounts_GetAccountsBatch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetAccountsBatchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MobilityAccountsServer).GetAccountsBatch(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/GetAccountsBatch",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).GetAccountsBatch(ctx, req.(*GetAccountsBatchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _MobilityAccounts_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _MobilityAccounts_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LoginRequest) in := new(LoginRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
@ -273,6 +305,10 @@ var MobilityAccounts_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetAccounts", MethodName: "GetAccounts",
Handler: _MobilityAccounts_GetAccounts_Handler, Handler: _MobilityAccounts_GetAccounts_Handler,
}, },
{
MethodName: "GetAccountsBatch",
Handler: _MobilityAccounts_GetAccountsBatch_Handler,
},
{ {
MethodName: "Login", MethodName: "Login",
Handler: _MobilityAccounts_Login_Handler, Handler: _MobilityAccounts_Login_Handler,

View File

@ -29,7 +29,11 @@ func (s MobilityAccountsServerImpl) Login(ctx context.Context, req *LoginRequest
if err != nil { if err != nil {
return nil, status.Errorf(codes.NotFound, "could not log in : %v", err) return nil, status.Errorf(codes.NotFound, "could not log in : %v", err)
} }
response := AccountFromStorageType(account) response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &LoginResponse{Account: response}, nil return &LoginResponse{Account: response}, nil
} }
func (s MobilityAccountsServerImpl) Register(ctx context.Context, req *RegisterRequest) (*RegisterResponse, error) { func (s MobilityAccountsServerImpl) Register(ctx context.Context, req *RegisterRequest) (*RegisterResponse, error) {
@ -39,14 +43,38 @@ func (s MobilityAccountsServerImpl) Register(ctx context.Context, req *RegisterR
fmt.Println(err) fmt.Println(err)
return nil, status.Errorf(codes.AlreadyExists, "account creation failed : %v", err) return nil, status.Errorf(codes.AlreadyExists, "account creation failed : %v", err)
} }
response := AccountFromStorageType(account) response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &RegisterResponse{Account: response}, nil return &RegisterResponse{Account: response}, nil
} }
func (MobilityAccountsServerImpl) UpdateData(context.Context, *UpdateDataRequest) (*UpdateDataResponse, error) { func (s MobilityAccountsServerImpl) UpdateData(ctx context.Context, req *UpdateDataRequest) (*UpdateDataResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateData not implemented") a := req.Account.ToStorageType()
account, err := s.handler.UpdateData(a.ID, a.Data)
if err != nil {
return nil, status.Errorf(codes.Internal, "issue while apdating account : %v", err)
}
response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &UpdateDataResponse{Account: response}, nil
} }
func (MobilityAccountsServerImpl) GetAccount(context.Context, *GetAccountRequest) (*GetAccountResponse, error) { func (s MobilityAccountsServerImpl) GetAccount(ctx context.Context, req *GetAccountRequest) (*GetAccountResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetAccount not implemented") account, err := s.handler.GetAccount(req.Id)
if err != nil {
fmt.Println(err)
return nil, status.Errorf(codes.AlreadyExists, "issue while retrieving account : %v", err)
}
response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &GetAccountResponse{Account: response}, nil
} }
func (s MobilityAccountsServerImpl) GetAccounts(ctx context.Context, req *GetAccountsRequest) (*GetAccountsResponse, error) { func (s MobilityAccountsServerImpl) GetAccounts(ctx context.Context, req *GetAccountsRequest) (*GetAccountsResponse, error) {
responses, err := s.handler.GetAccounts(req.Namespaces) responses, err := s.handler.GetAccounts(req.Namespaces)
@ -54,11 +82,32 @@ func (s MobilityAccountsServerImpl) GetAccounts(ctx context.Context, req *GetAcc
return nil, status.Errorf(codes.NotFound, "could not get accounts : %v", err) return nil, status.Errorf(codes.NotFound, "could not get accounts : %v", err)
} }
var accounts []*Account var accounts []*Account
for _, a := range responses { for _, a := range responses {
accounts = append(accounts, AccountFromStorageType(&a)) account, err := AccountFromStorageType(&a)
if err != nil {
return nil, status.Errorf(codes.Internal, "could not get accounts : %v", err)
}
accounts = append(accounts, account)
} }
return &GetAccountsResponse{Accounts: accounts}, nil return &GetAccountsResponse{Accounts: accounts}, nil
} }
func (s MobilityAccountsServerImpl) GetAccountsBatch(ctx context.Context, req *GetAccountsBatchRequest) (*GetAccountsBatchResponse, error) {
responses, err := s.handler.GetAccountsBatch(req.Accountids)
if err != nil {
return nil, status.Errorf(codes.NotFound, "could not get accounts : %v", err)
}
var accounts []*Account
for _, a := range responses {
account, err := AccountFromStorageType(&a)
if err != nil {
return nil, status.Errorf(codes.Internal, "could not get accounts : %v", err)
}
accounts = append(accounts, account)
}
return &GetAccountsBatchResponse{Accounts: accounts}, nil
}
func (MobilityAccountsServerImpl) ChangePassword(ctc context.Context, req *ChangePasswordRequest) (*ChangePasswordResponse, error) { func (MobilityAccountsServerImpl) ChangePassword(ctc context.Context, req *ChangePasswordRequest) (*ChangePasswordResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method not implemented") return nil, status.Errorf(codes.Unimplemented, "method not implemented")
} }

View File

@ -2,27 +2,15 @@ package handlers
import ( import (
"errors" "errors"
"fmt"
"time" "time"
"git.coopgo.io/coopgo-platform/mobility-accounts/storage" "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/santhosh-tekuri/jsonschema/v5" "github.com/santhosh-tekuri/jsonschema/v5"
"github.com/spf13/viper"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
type MobilityAccountsHandler struct {
storage storage.Storage
config *viper.Viper
}
func NewHandler(cfg *viper.Viper, storage storage.Storage) MobilityAccountsHandler {
return MobilityAccountsHandler{
storage: storage,
config: cfg,
}
}
func (h MobilityAccountsHandler) Login(username string, password string, namespace string) (*storage.Account, error) { func (h MobilityAccountsHandler) Login(username string, password string, namespace string) (*storage.Account, error) {
if password == "" { if password == "" {
@ -100,6 +88,7 @@ func (h MobilityAccountsHandler) UpdateData(accountid string, datas map[string]a
dataschemas := h.config.GetStringMap("data_schemas") dataschemas := h.config.GetStringMap("data_schemas")
for k, v := range datas { for k, v := range datas {
if !h.config.GetBool("allow_any_data") && dataschemas[k] == nil { if !h.config.GetBool("allow_any_data") && dataschemas[k] == nil {
fmt.Println("data scope not allowed")
return nil, errors.New("data scope not allowed") return nil, errors.New("data scope not allowed")
} }
@ -107,16 +96,19 @@ func (h MobilityAccountsHandler) UpdateData(accountid string, datas map[string]a
s := dataschemas[k].(map[string]string) s := dataschemas[k].(map[string]string)
sch, err := jsonschema.Compile(s["schema"]) sch, err := jsonschema.Compile(s["schema"])
if err != nil { if err != nil {
fmt.Println(err)
return nil, err return nil, err
} }
if err = sch.Validate(v); err != nil { if err = sch.Validate(v); err != nil {
fmt.Println(err)
return nil, err return nil, err
} }
}
account.Data[k] = v account.Data[k] = v
} }
}
if err = h.storage.DB.UpdateAccount(*account); err != nil { if err = h.storage.DB.UpdateAccount(*account); err != nil {
fmt.Println(err)
return nil, err return nil, err
} }
@ -132,3 +124,11 @@ func (h MobilityAccountsHandler) GetAccounts(namespaces []string) (accounts []st
accounts, err = h.storage.DB.GetAccounts(namespaces) accounts, err = h.storage.DB.GetAccounts(namespaces)
return return
} }
func (h MobilityAccountsHandler) GetAccountsBatch(accountIds []string) (accounts []storage.Account, err error) {
if len(accountIds) == 0 {
return accounts, nil
}
accounts, err = h.storage.DB.GetAccountsByIds(accountIds)
return
}

18
handlers/handlers.go Normal file
View File

@ -0,0 +1,18 @@
package handlers
import (
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"github.com/spf13/viper"
)
type MobilityAccountsHandler struct {
storage storage.Storage
config *viper.Viper
}
func NewHandler(cfg *viper.Viper, storage storage.Storage) MobilityAccountsHandler {
return MobilityAccountsHandler{
storage: storage,
config: cfg,
}
}

View File

@ -40,8 +40,6 @@ func main() {
go op.Run(failed, cfg, handler, storage) go op.Run(failed, cfg, handler, storage)
} }
// Terminate if one of the services fails
err = <-failed err = <-failed
fmt.Println("Terminating :", err) fmt.Println("Terminating :", err)

28
storage/accounts.go Normal file
View File

@ -0,0 +1,28 @@
package storage
type Account struct {
ID string `json:"id" bson:"_id"`
Namespace string `json:"namespace"`
Authentication AccountAuth `json:"-" bson:"authentication"`
Data map[string]any `json:"data"`
Metadata map[string]any `json:"metadata"`
}
type AccountAuth struct {
Local LocalAuth
//TODO handle SSO
}
type LocalAuth struct {
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
EmailValidation Validation `json:"email_validation" bson:"email_validation"`
PhoneNumber string `json:"phone_number" bson:"phone_number"`
PhoneNumberValidation Validation `json:"phone_number_validation" bson:"phone_number_validation"`
}
type Validation struct {
Validated bool
ValidationCode string `json:"validation_code" bson:"validation_code"`
}

View File

@ -40,17 +40,10 @@ func NewEtcdKVStore(cfg *viper.Viper) (EtcdKVStore, error) {
} }
func (s EtcdKVStore) Put(k string, v any) error { func (s EtcdKVStore) Put(k string, v any) error {
// var data bytes.Buffer // Stand-in for a network connection
// enc := gob.NewEncoder(&data)
// err := enc.Encode(v)
// if err != nil {
// return err
// }
data, err := json.Marshal(v) data, err := json.Marshal(v)
if err != nil { if err != nil {
return err return err
} }
// _, err = s.Client.KV.Put(context.TODO(), k, data.String())
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_, err = s.Client.KV.Put(ctx, k, string(data)) _, err = s.Client.KV.Put(ctx, k, string(data))
cancel() cancel()
@ -66,17 +59,10 @@ func (s EtcdKVStore) PutWithTTL(k string, v any, duration time.Duration) error {
return err return err
} }
// var data bytes.Buffer // Stand-in for a network connection
// enc := gob.NewEncoder(&data)
// err = enc.Encode(v)
// if err != nil {
// return err
// }
data, err := json.Marshal(v) data, err := json.Marshal(v)
if err != nil { if err != nil {
return err return err
} }
// _, err = s.Client.KV.Put(context.TODO(), k, data.String(), clientv3.WithLease(lease.ID))
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_, err = s.Client.KV.Put(ctx, k, string(data), clientv3.WithLease(lease.ID)) _, err = s.Client.KV.Put(ctx, k, string(data), clientv3.WithLease(lease.ID))
cancel() cancel()
@ -95,10 +81,6 @@ func (s EtcdKVStore) Get(k string) (any, error) {
} }
for _, v := range resp.Kvs { for _, v := range resp.Kvs {
var data any var data any
// var reader bytes.Buffer
// reader.Write(v.Value)
// enc := gob.NewDecoder(&reader)
// err := enc.Decode(&data)
err := json.Unmarshal([]byte(v.Value), &data) err := json.Unmarshal([]byte(v.Value), &data)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -3,6 +3,7 @@ package storage
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
@ -46,17 +47,6 @@ func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
return storage, err return storage, err
} }
func (s MongoDBStorage) GetAccount(id string) (*Account, error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
account := &Account{}
if err := collection.FindOne(context.TODO(), bson.M{"_id": id}).Decode(account); err != nil {
return nil, err
}
return account, nil
}
// LocalAuthentication returns an Account matching with one of username, email or password. // LocalAuthentication returns an Account matching with one of username, email or password.
// If username, is provided (not an empty string), it will search by username only // If username, is provided (not an empty string), it will search by username only
// If username is an empty string and email is provided, it will search by email // If username is an empty string and email is provided, it will search by email
@ -85,6 +75,17 @@ func (s MongoDBStorage) LocalAuthentication(namespace string, username string, e
return account, nil return account, nil
} }
func (s MongoDBStorage) GetAccount(id string) (*Account, error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
account := &Account{}
if err := collection.FindOne(context.TODO(), bson.M{"_id": id}).Decode(account); err != nil {
return nil, err
}
return account, nil
}
func (s MongoDBStorage) GetAccounts(namespaces []string) (accounts []Account, err error) { func (s MongoDBStorage) GetAccounts(namespaces []string) (accounts []Account, err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"]) collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
@ -123,6 +124,41 @@ func (s MongoDBStorage) GetAccounts(namespaces []string) (accounts []Account, er
return return
} }
func (s MongoDBStorage) GetAccountsByIds(accountids []string) (accounts []Account, err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
var cur *mongo.Cursor
findOptions := options.Find()
if len(accountids) == 0 {
return accounts, errors.New("missing account ids")
} else {
cur, err = collection.Find(context.TODO(), bson.M{"_id": bson.M{"$in": accountids}}, findOptions)
if err != nil {
return accounts, err
}
}
for cur.Next(context.TODO()) {
var account Account
var elem bson.M
err := cur.Decode(&elem)
if err != nil {
return accounts, err
}
bsonBytes, _ := bson.Marshal(elem)
bson.Unmarshal(bsonBytes, &account)
accounts = append(accounts, account)
}
return
}
func (s MongoDBStorage) CreateAccount(account Account) error { func (s MongoDBStorage) CreateAccount(account Account) error {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"]) collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
if _, err := collection.InsertOne(context.TODO(), account); err != nil { if _, err := collection.InsertOne(context.TODO(), account); err != nil {
@ -135,6 +171,7 @@ func (s MongoDBStorage) CreateAccount(account Account) error {
func (s MongoDBStorage) UpdateAccount(account Account) error { func (s MongoDBStorage) UpdateAccount(account Account) error {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"]) collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
if _, err := collection.ReplaceOne(context.TODO(), bson.M{"_id": account.ID}, account); err != nil { if _, err := collection.ReplaceOne(context.TODO(), bson.M{"_id": account.ID}, account); err != nil {
fmt.Println(err)
return err return err
} }

View File

@ -32,6 +32,7 @@ type DBStorage interface {
GetAccount(id string) (*Account, error) GetAccount(id string) (*Account, error)
LocalAuthentication(namespace string, username string, email string, phone_number string) (*Account, error) LocalAuthentication(namespace string, username string, email string, phone_number string) (*Account, error)
GetAccounts(namespaces []string) ([]Account, error) GetAccounts(namespaces []string) ([]Account, error)
GetAccountsByIds(accountids []string) ([]Account, error)
CreateAccount(account Account) error CreateAccount(account Account) error
UpdateAccount(account Account) error UpdateAccount(account Account) error
} }
@ -62,32 +63,3 @@ func NewKVStore(cfg *viper.Viper) (KVStore, error) {
kv, err := NewEtcdKVStore(cfg) kv, err := NewEtcdKVStore(cfg)
return kv, err return kv, err
} }
// Data models
type Account struct {
ID string `json:"id" bson:"_id"`
Namespace string `json:"namespace"`
Authentication AccountAuth `json:"authentication" bson:"authentication"`
Data map[string]any `json:"data"`
Metadata map[string]any `json:"metadata"`
}
type AccountAuth struct {
Local LocalAuth
//TODO handle SSO
}
type LocalAuth struct {
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
EmailValidation Validation `json:"email_validation" bson:"email_validation"`
PhoneNumber string `json:"phone_number" bson:"phone_number"`
PhoneNumberValidation Validation `json:"phone_number_validation" bson:"phone_number_validation"`
}
type Validation struct {
Validated bool
ValidationCode string `json:"validation_code" bson:"validation_code"`
}