resolve conflicts
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 1m5s

This commit is contained in:
Arnaud Delcasse
2026-01-05 23:40:17 +01:00
53 changed files with 1718 additions and 894 deletions

0
grpcapi/README.md Normal file → Executable file
View File

34
grpcapi/accounts.go Normal file → Executable file
View File

@@ -2,17 +2,18 @@ package grpcapi
import (
"encoding/json"
"fmt"
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"github.com/rs/zerolog/log"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/structpb"
)
func (a Account) ToStorageType() storage.Account {
var localauth storage.LocalAuth
var localauth *storage.LocalAuth
if a.Authentication != nil && a.Authentication.Local != nil {
localauth = a.Authentication.Local.ToStorageType()
la := a.Authentication.Local.ToStorageType()
localauth = &la
}
account := storage.Account{
ID: a.Id,
@@ -26,7 +27,7 @@ func (a Account) ToStorageType() storage.Account {
for k, d := range a.Data.GetFields() {
jsondata, err := protojson.Marshal(d)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
break
}
var data any
@@ -51,17 +52,26 @@ func (lc LocalAuth) ToStorageType() storage.LocalAuth {
}
return storage.LocalAuth{
Username: lc.Username,
Password: lc.Password,
Email: lc.Email,
EmailValidation: emailValidation,
PhoneNumber: lc.PhoneNumber,
PhoneNumberValidation: phoneValidation,
Username: lc.Username,
Password: lc.Password,
Email: lc.Email,
EmailValidation: &storage.Validation{
Validated: lc.EmailValidation.Validated,
ValidationCode: lc.EmailValidation.ValidationCode,
},
PhoneNumber: lc.PhoneNumber,
PhoneNumberValidation: &storage.Validation{
Validated: lc.PhoneNumberValidation.Validated,
ValidationCode: lc.PhoneNumberValidation.ValidationCode,
},
}
}
func AccountFromStorageType(account *storage.Account) (*Account, error) {
lc := LocalAuthFromStorageType(account.Authentication.Local)
var lc *LocalAuth
if account.Authentication.Local != nil {
lc = LocalAuthFromStorageType(*account.Authentication.Local)
}
d, err := sanitizeData(account.Data)
if err != nil {
@@ -70,7 +80,7 @@ func AccountFromStorageType(account *storage.Account) (*Account, error) {
data, err := structpb.NewStruct(d)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, err
}

242
grpcapi/accounts.pb.go Normal file → Executable file
View File

@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.0
// protoc v3.19.4
// protoc-gen-go v1.36.7
// protoc v6.31.1
// source: accounts.proto
package grpcapi
@@ -12,6 +12,7 @@ import (
structpb "google.golang.org/protobuf/types/known/structpb"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
@@ -22,23 +23,20 @@ const (
)
type Account struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
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"`
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
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"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Account) Reset() {
*x = Account{}
if protoimpl.UnsafeEnabled {
mi := &file_accounts_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
mi := &file_accounts_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Account) String() string {
@@ -49,7 +47,7 @@ func (*Account) ProtoMessage() {}
func (x *Account) ProtoReflect() protoreflect.Message {
mi := &file_accounts_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
@@ -93,20 +91,17 @@ func (x *Account) GetData() *structpb.Struct {
}
type AccountAuth struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
state protoimpl.MessageState `protogen:"open.v1"`
Local *LocalAuth `protobuf:"bytes,7,opt,name=local,proto3,oneof" json:"local,omitempty"` //TODO SSO
unknownFields protoimpl.UnknownFields
Local *LocalAuth `protobuf:"bytes,7,opt,name=local,proto3" json:"local,omitempty"`
sizeCache protoimpl.SizeCache
}
func (x *AccountAuth) Reset() {
*x = AccountAuth{}
if protoimpl.UnsafeEnabled {
mi := &file_accounts_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
mi := &file_accounts_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AccountAuth) String() string {
@@ -117,7 +112,7 @@ func (*AccountAuth) ProtoMessage() {}
func (x *AccountAuth) ProtoReflect() protoreflect.Message {
mi := &file_accounts_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
@@ -140,25 +135,22 @@ func (x *AccountAuth) GetLocal() *LocalAuth {
}
type LocalAuth struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Username string `protobuf:"bytes,10,opt,name=username,proto3" json:"username,omitempty"`
Password string `protobuf:"bytes,11,opt,name=password,proto3" json:"password,omitempty"`
Email string `protobuf:"bytes,12,opt,name=email,proto3" json:"email,omitempty"`
PhoneNumber string `protobuf:"bytes,13,opt,name=phone_number,json=phoneNumber,proto3" json:"phone_number,omitempty"`
EmailValidation *Validation `protobuf:"bytes,14,opt,name=email_validation,json=emailValidation,proto3" json:"email_validation,omitempty"`
PhoneNumberValidation *Validation `protobuf:"bytes,15,opt,name=phone_number_validation,json=phoneNumberValidation,proto3" json:"phone_number_validation,omitempty"`
state protoimpl.MessageState `protogen:"open.v1"`
Username *string `protobuf:"bytes,10,opt,name=username,proto3,oneof" json:"username,omitempty"`
Password string `protobuf:"bytes,11,opt,name=password,proto3" json:"password,omitempty"`
Email *string `protobuf:"bytes,12,opt,name=email,proto3,oneof" json:"email,omitempty"`
PhoneNumber *string `protobuf:"bytes,13,opt,name=phone_number,json=phoneNumber,proto3,oneof" json:"phone_number,omitempty"`
EmailValidation *Validation `protobuf:"bytes,14,opt,name=email_validation,json=emailValidation,proto3,oneof" json:"email_validation,omitempty"`
PhoneNumberValidation *Validation `protobuf:"bytes,15,opt,name=phone_number_validation,json=phoneNumberValidation,proto3,oneof" json:"phone_number_validation,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *LocalAuth) Reset() {
*x = LocalAuth{}
if protoimpl.UnsafeEnabled {
mi := &file_accounts_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
mi := &file_accounts_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *LocalAuth) String() string {
@@ -169,7 +161,7 @@ func (*LocalAuth) ProtoMessage() {}
func (x *LocalAuth) ProtoReflect() protoreflect.Message {
mi := &file_accounts_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
@@ -185,8 +177,8 @@ func (*LocalAuth) Descriptor() ([]byte, []int) {
}
func (x *LocalAuth) GetUsername() string {
if x != nil {
return x.Username
if x != nil && x.Username != nil {
return *x.Username
}
return ""
}
@@ -199,15 +191,15 @@ func (x *LocalAuth) GetPassword() string {
}
func (x *LocalAuth) GetEmail() string {
if x != nil {
return x.Email
if x != nil && x.Email != nil {
return *x.Email
}
return ""
}
func (x *LocalAuth) GetPhoneNumber() string {
if x != nil {
return x.PhoneNumber
if x != nil && x.PhoneNumber != nil {
return *x.PhoneNumber
}
return ""
}
@@ -227,21 +219,18 @@ func (x *LocalAuth) GetPhoneNumberValidation() *Validation {
}
type Validation struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Validated bool `protobuf:"varint,20,opt,name=validated,proto3" json:"validated,omitempty"`
ValidationCode string `protobuf:"bytes,21,opt,name=validation_code,json=validationCode,proto3" json:"validation_code,omitempty"`
state protoimpl.MessageState `protogen:"open.v1"`
Validated bool `protobuf:"varint,20,opt,name=validated,proto3" json:"validated,omitempty"`
ValidationCode string `protobuf:"bytes,21,opt,name=validation_code,json=validationCode,proto3" json:"validation_code,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Validation) Reset() {
*x = Validation{}
if protoimpl.UnsafeEnabled {
mi := &file_accounts_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
mi := &file_accounts_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Validation) String() string {
@@ -252,7 +241,7 @@ func (*Validation) ProtoMessage() {}
func (x *Validation) ProtoReflect() protoreflect.Message {
mi := &file_accounts_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
@@ -283,64 +272,50 @@ func (x *Validation) GetValidationCode() string {
var File_accounts_proto protoreflect.FileDescriptor
var file_accounts_proto_rawDesc = []byte{
0x0a, 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9a,
0x01, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61,
0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e,
0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x0e, 0x61, 0x75, 0x74, 0x68,
0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x0c, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x41, 0x75, 0x74, 0x68, 0x52, 0x0e,
0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2b,
0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67,
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53,
0x74, 0x72, 0x75, 0x63, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x2f, 0x0a, 0x0b, 0x41,
0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x41, 0x75, 0x74, 0x68, 0x12, 0x20, 0x0a, 0x05, 0x6c, 0x6f,
0x63, 0x61, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x4c, 0x6f, 0x63, 0x61,
0x6c, 0x41, 0x75, 0x74, 0x68, 0x52, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x22, 0xf9, 0x01, 0x0a,
0x09, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x75, 0x74, 0x68, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73,
0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73,
0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f,
0x72, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f,
0x72, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x0c, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x68, 0x6f, 0x6e,
0x65, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b,
0x70, 0x68, 0x6f, 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x36, 0x0a, 0x10, 0x65,
0x6d, 0x61, 0x69, 0x6c, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18,
0x0e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x52, 0x0f, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x12, 0x43, 0x0a, 0x17, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x5f, 0x6e, 0x75, 0x6d,
0x62, 0x65, 0x72, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x0f,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x52, 0x15, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x56, 0x61,
0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x53, 0x0a, 0x0a, 0x56, 0x61, 0x6c, 0x69,
0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x0a, 0x09, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61,
0x74, 0x65, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x76, 0x61, 0x6c, 0x69, 0x64,
0x61, 0x74, 0x65, 0x64, 0x12, 0x27, 0x0a, 0x0f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x76,
0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 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,
}
const file_accounts_proto_rawDesc = "" +
"\n" +
"\x0eaccounts.proto\x1a\x1cgoogle/protobuf/struct.proto\"\x9a\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" +
"\vAccountAuth\x12%\n" +
"\x05local\x18\a \x01(\v2\n" +
".LocalAuthH\x00R\x05local\x88\x01\x01B\b\n" +
"\x06_local\"\xeb\x02\n" +
"\tLocalAuth\x12\x1f\n" +
"\busername\x18\n" +
" \x01(\tH\x00R\busername\x88\x01\x01\x12\x1a\n" +
"\bpassword\x18\v \x01(\tR\bpassword\x12\x19\n" +
"\x05email\x18\f \x01(\tH\x01R\x05email\x88\x01\x01\x12&\n" +
"\fphone_number\x18\r \x01(\tH\x02R\vphoneNumber\x88\x01\x01\x12;\n" +
"\x10email_validation\x18\x0e \x01(\v2\v.ValidationH\x03R\x0femailValidation\x88\x01\x01\x12H\n" +
"\x17phone_number_validation\x18\x0f \x01(\v2\v.ValidationH\x04R\x15phoneNumberValidation\x88\x01\x01B\v\n" +
"\t_usernameB\b\n" +
"\x06_emailB\x0f\n" +
"\r_phone_numberB\x13\n" +
"\x11_email_validationB\x1a\n" +
"\x18_phone_number_validation\"S\n" +
"\n" +
"Validation\x12\x1c\n" +
"\tvalidated\x18\x14 \x01(\bR\tvalidated\x12'\n" +
"\x0fvalidation_code\x18\x15 \x01(\tR\x0evalidationCodeB9Z7git.coopgo.io/coopgo-platform/mobility-accounts/grpcapib\x06proto3"
var (
file_accounts_proto_rawDescOnce sync.Once
file_accounts_proto_rawDescData = file_accounts_proto_rawDesc
file_accounts_proto_rawDescData []byte
)
func file_accounts_proto_rawDescGZIP() []byte {
file_accounts_proto_rawDescOnce.Do(func() {
file_accounts_proto_rawDescData = protoimpl.X.CompressGZIP(file_accounts_proto_rawDescData)
file_accounts_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_accounts_proto_rawDesc), len(file_accounts_proto_rawDesc)))
})
return file_accounts_proto_rawDescData
}
var file_accounts_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_accounts_proto_goTypes = []interface{}{
var file_accounts_proto_goTypes = []any{
(*Account)(nil), // 0: Account
(*AccountAuth)(nil), // 1: AccountAuth
(*LocalAuth)(nil), // 2: LocalAuth
@@ -365,61 +340,13 @@ func file_accounts_proto_init() {
if File_accounts_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_accounts_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Account); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_accounts_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*AccountAuth); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_accounts_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LocalAuth); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_accounts_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Validation); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
file_accounts_proto_msgTypes[1].OneofWrappers = []any{}
file_accounts_proto_msgTypes[2].OneofWrappers = []any{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_accounts_proto_rawDesc,
RawDescriptor: unsafe.Slice(unsafe.StringData(file_accounts_proto_rawDesc), len(file_accounts_proto_rawDesc)),
NumEnums: 0,
NumMessages: 4,
NumExtensions: 0,
@@ -430,7 +357,6 @@ func file_accounts_proto_init() {
MessageInfos: file_accounts_proto_msgTypes,
}.Build()
File_accounts_proto = out.File
file_accounts_proto_rawDesc = nil
file_accounts_proto_goTypes = nil
file_accounts_proto_depIdxs = nil
}

13
grpcapi/accounts.proto Normal file → Executable file
View File

@@ -12,16 +12,17 @@ message Account {
}
message AccountAuth {
LocalAuth local = 7;
optional LocalAuth local = 7;
//TODO SSO
}
message LocalAuth {
string username = 10;
optional string username = 10;
string password = 11;
string email = 12;
string phone_number = 13;
Validation email_validation = 14;
Validation phone_number_validation = 15;
optional string email = 12;
optional string phone_number = 13;
optional Validation email_validation = 14;
optional Validation phone_number_validation = 15;
}
message Validation {

731
grpcapi/comasvc.pb.go Normal file → Executable file

File diff suppressed because it is too large Load Diff

0
grpcapi/comasvc.proto Normal file → Executable file
View File

86
grpcapi/comasvc_grpc.pb.go Normal file → Executable file
View File

@@ -1,7 +1,9 @@
//COMA (COOPGO Mobility Accounts) gRPC service definition
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.19.4
// - protoc-gen-go-grpc v1.5.1
// - protoc v6.31.1
// source: comasvc.proto
package grpcapi
@@ -15,8 +17,20 @@ import (
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
MobilityAccounts_Register_FullMethodName = "/MobilityAccounts/Register"
MobilityAccounts_UpdateData_FullMethodName = "/MobilityAccounts/UpdateData"
MobilityAccounts_UpdatePhoneNumber_FullMethodName = "/MobilityAccounts/UpdatePhoneNumber"
MobilityAccounts_GetAccount_FullMethodName = "/MobilityAccounts/GetAccount"
MobilityAccounts_GetAccountUsername_FullMethodName = "/MobilityAccounts/GetAccountUsername"
MobilityAccounts_GetAccounts_FullMethodName = "/MobilityAccounts/GetAccounts"
MobilityAccounts_GetAccountsBatch_FullMethodName = "/MobilityAccounts/GetAccountsBatch"
MobilityAccounts_Login_FullMethodName = "/MobilityAccounts/Login"
MobilityAccounts_ChangePassword_FullMethodName = "/MobilityAccounts/ChangePassword"
)
// MobilityAccountsClient is the client API for MobilityAccounts service.
//
@@ -43,8 +57,9 @@ func NewMobilityAccountsClient(cc grpc.ClientConnInterface) MobilityAccountsClie
}
func (c *mobilityAccountsClient) Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(RegisterResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/Register", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_Register_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -52,8 +67,9 @@ func (c *mobilityAccountsClient) Register(ctx context.Context, in *RegisterReque
}
func (c *mobilityAccountsClient) UpdateData(ctx context.Context, in *UpdateDataRequest, opts ...grpc.CallOption) (*UpdateDataResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdateDataResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/UpdateData", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_UpdateData_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -61,8 +77,9 @@ func (c *mobilityAccountsClient) UpdateData(ctx context.Context, in *UpdateDataR
}
func (c *mobilityAccountsClient) UpdatePhoneNumber(ctx context.Context, in *UpdatePhoneNumberRequest, opts ...grpc.CallOption) (*UpdatePhoneNumberResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdatePhoneNumberResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/UpdatePhoneNumber", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_UpdatePhoneNumber_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -70,8 +87,9 @@ func (c *mobilityAccountsClient) UpdatePhoneNumber(ctx context.Context, in *Upda
}
func (c *mobilityAccountsClient) GetAccount(ctx context.Context, in *GetAccountRequest, opts ...grpc.CallOption) (*GetAccountResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetAccountResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/GetAccount", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_GetAccount_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -79,8 +97,9 @@ func (c *mobilityAccountsClient) GetAccount(ctx context.Context, in *GetAccountR
}
func (c *mobilityAccountsClient) GetAccountUsername(ctx context.Context, in *GetAccountUsernameRequest, opts ...grpc.CallOption) (*GetAccountUsernameResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetAccountUsernameResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/GetAccountUsername", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_GetAccountUsername_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -88,8 +107,9 @@ func (c *mobilityAccountsClient) GetAccountUsername(ctx context.Context, in *Get
}
func (c *mobilityAccountsClient) GetAccounts(ctx context.Context, in *GetAccountsRequest, opts ...grpc.CallOption) (*GetAccountsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetAccountsResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/GetAccounts", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_GetAccounts_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -97,8 +117,9 @@ func (c *mobilityAccountsClient) GetAccounts(ctx context.Context, in *GetAccount
}
func (c *mobilityAccountsClient) GetAccountsBatch(ctx context.Context, in *GetAccountsBatchRequest, opts ...grpc.CallOption) (*GetAccountsBatchResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetAccountsBatchResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/GetAccountsBatch", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_GetAccountsBatch_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -106,8 +127,9 @@ func (c *mobilityAccountsClient) GetAccountsBatch(ctx context.Context, in *GetAc
}
func (c *mobilityAccountsClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(LoginResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/Login", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_Login_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -115,8 +137,9 @@ func (c *mobilityAccountsClient) Login(ctx context.Context, in *LoginRequest, op
}
func (c *mobilityAccountsClient) ChangePassword(ctx context.Context, in *ChangePasswordRequest, opts ...grpc.CallOption) (*ChangePasswordResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ChangePasswordResponse)
err := c.cc.Invoke(ctx, "/MobilityAccounts/ChangePassword", in, out, opts...)
err := c.cc.Invoke(ctx, MobilityAccounts_ChangePassword_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
@@ -125,7 +148,7 @@ func (c *mobilityAccountsClient) ChangePassword(ctx context.Context, in *ChangeP
// MobilityAccountsServer is the server API for MobilityAccounts service.
// All implementations must embed UnimplementedMobilityAccountsServer
// for forward compatibility
// for forward compatibility.
type MobilityAccountsServer interface {
Register(context.Context, *RegisterRequest) (*RegisterResponse, error)
UpdateData(context.Context, *UpdateDataRequest) (*UpdateDataResponse, error)
@@ -140,9 +163,12 @@ type MobilityAccountsServer interface {
mustEmbedUnimplementedMobilityAccountsServer()
}
// UnimplementedMobilityAccountsServer must be embedded to have forward compatible implementations.
type UnimplementedMobilityAccountsServer struct {
}
// UnimplementedMobilityAccountsServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedMobilityAccountsServer struct{}
func (UnimplementedMobilityAccountsServer) Register(context.Context, *RegisterRequest) (*RegisterResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Register not implemented")
@@ -172,6 +198,7 @@ func (UnimplementedMobilityAccountsServer) ChangePassword(context.Context, *Chan
return nil, status.Errorf(codes.Unimplemented, "method ChangePassword not implemented")
}
func (UnimplementedMobilityAccountsServer) mustEmbedUnimplementedMobilityAccountsServer() {}
func (UnimplementedMobilityAccountsServer) testEmbeddedByValue() {}
// UnsafeMobilityAccountsServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to MobilityAccountsServer will
@@ -181,6 +208,13 @@ type UnsafeMobilityAccountsServer interface {
}
func RegisterMobilityAccountsServer(s grpc.ServiceRegistrar, srv MobilityAccountsServer) {
// If the following call pancis, it indicates UnimplementedMobilityAccountsServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&MobilityAccounts_ServiceDesc, srv)
}
@@ -194,7 +228,7 @@ func _MobilityAccounts_Register_Handler(srv interface{}, ctx context.Context, de
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/Register",
FullMethod: MobilityAccounts_Register_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).Register(ctx, req.(*RegisterRequest))
@@ -212,7 +246,7 @@ func _MobilityAccounts_UpdateData_Handler(srv interface{}, ctx context.Context,
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/UpdateData",
FullMethod: MobilityAccounts_UpdateData_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).UpdateData(ctx, req.(*UpdateDataRequest))
@@ -230,7 +264,7 @@ func _MobilityAccounts_UpdatePhoneNumber_Handler(srv interface{}, ctx context.Co
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/UpdatePhoneNumber",
FullMethod: MobilityAccounts_UpdatePhoneNumber_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).UpdatePhoneNumber(ctx, req.(*UpdatePhoneNumberRequest))
@@ -248,7 +282,7 @@ func _MobilityAccounts_GetAccount_Handler(srv interface{}, ctx context.Context,
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/GetAccount",
FullMethod: MobilityAccounts_GetAccount_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).GetAccount(ctx, req.(*GetAccountRequest))
@@ -266,7 +300,7 @@ func _MobilityAccounts_GetAccountUsername_Handler(srv interface{}, ctx context.C
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/GetAccountUsername",
FullMethod: MobilityAccounts_GetAccountUsername_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).GetAccountUsername(ctx, req.(*GetAccountUsernameRequest))
@@ -284,7 +318,7 @@ func _MobilityAccounts_GetAccounts_Handler(srv interface{}, ctx context.Context,
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/GetAccounts",
FullMethod: MobilityAccounts_GetAccounts_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).GetAccounts(ctx, req.(*GetAccountsRequest))
@@ -302,7 +336,7 @@ func _MobilityAccounts_GetAccountsBatch_Handler(srv interface{}, ctx context.Con
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/GetAccountsBatch",
FullMethod: MobilityAccounts_GetAccountsBatch_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).GetAccountsBatch(ctx, req.(*GetAccountsBatchRequest))
@@ -320,7 +354,7 @@ func _MobilityAccounts_Login_Handler(srv interface{}, ctx context.Context, dec f
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/Login",
FullMethod: MobilityAccounts_Login_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).Login(ctx, req.(*LoginRequest))
@@ -338,7 +372,7 @@ func _MobilityAccounts_ChangePassword_Handler(srv interface{}, ctx context.Conte
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/MobilityAccounts/ChangePassword",
FullMethod: MobilityAccounts_ChangePassword_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MobilityAccountsServer).ChangePassword(ctx, req.(*ChangePasswordRequest))

25
grpcapi/grpcapi.go Normal file → Executable file
View File

@@ -2,11 +2,10 @@ package grpcapi
import (
context "context"
"fmt"
"log"
"net"
"git.coopgo.io/coopgo-platform/mobility-accounts/handlers"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
@@ -31,7 +30,7 @@ func (s MobilityAccountsServerImpl) Login(ctx context.Context, req *LoginRequest
}
response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &LoginResponse{Account: response}, nil
@@ -40,12 +39,12 @@ func (s MobilityAccountsServerImpl) Register(ctx context.Context, req *RegisterR
a := req.Account.ToStorageType()
account, err := s.handler.Register(a)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.AlreadyExists, "account creation failed : %v", err)
}
response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &RegisterResponse{Account: response}, nil
@@ -58,7 +57,7 @@ func (s MobilityAccountsServerImpl) UpdateData(ctx context.Context, req *UpdateD
}
response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &UpdateDataResponse{Account: response}, nil
@@ -78,12 +77,12 @@ func (s MobilityAccountsServerImpl) UpdatePhoneNumber(ctx context.Context, req *
func (s MobilityAccountsServerImpl) GetAccount(ctx context.Context, req *GetAccountRequest) (*GetAccountResponse, error) {
account, err := s.handler.GetAccount(req.Id)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.AlreadyExists, "issue while retrieving account : %v", err)
}
response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &GetAccountResponse{Account: response}, nil
@@ -91,12 +90,12 @@ func (s MobilityAccountsServerImpl) GetAccount(ctx context.Context, req *GetAcco
func (s MobilityAccountsServerImpl) GetAccountUsername(ctx context.Context, req *GetAccountUsernameRequest) (*GetAccountUsernameResponse, error) {
account, err := s.handler.GetAccountUsername(req.Username, req.Namespace)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.AlreadyExists, "issue while retrieving account : %v", err)
}
response, err := AccountFromStorageType(account)
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "issue while retrieving account : %v", err)
}
return &GetAccountUsernameResponse{Account: response}, nil
@@ -147,13 +146,13 @@ func Run(done chan error, cfg *viper.Viper, handler handlers.MobilityAccountsHan
dev_env = cfg.GetBool("dev_env")
address = ":" + cfg.GetString("services.grpc.port")
)
fmt.Println("-> GRPC server on", address)
log.Info().Str("address", address).Msg("Running gRPC server")
server := grpc.NewServer()
RegisterMobilityAccountsServer(server, NewMobilityAccountsServer(handler))
l, err := net.Listen("tcp", address)
if err != nil {
log.Fatal(err)
log.Fatal().Str("address", address).Err(err).Msg("gRPC server cannot listen")
}
if dev_env {
@@ -161,7 +160,7 @@ func Run(done chan error, cfg *viper.Viper, handler handlers.MobilityAccountsHan
}
if err := server.Serve(l); err != nil {
fmt.Println("gRPC service ended")
log.Error().Err(err).Msg("gRPC service ended")
done <- err
}
}