From 841ab460895d302c1982d8cec3fbd88d8f8b36f8 Mon Sep 17 00:00:00 2001 From: yyasha Date: Sun, 17 Dec 2023 13:37:57 +0300 Subject: [PATCH] update protos --- config/local.yaml | 2 +- gen/sso/sso.pb.go | 501 ------------------------------ gen/sso/sso_grpc.pb.go | 183 ----------- go.mod | 14 +- go.sum | 12 +- internal/grpc/auth/server.go | 3 +- proto/sso/sso.proto | 38 --- tests/auth_register_login_test.go | 3 +- tests/suite/suite.go | 3 +- 9 files changed, 18 insertions(+), 741 deletions(-) delete mode 100644 gen/sso/sso.pb.go delete mode 100644 gen/sso/sso_grpc.pb.go delete mode 100644 proto/sso/sso.proto diff --git a/config/local.yaml b/config/local.yaml index 320c06c..fa45d7f 100644 --- a/config/local.yaml +++ b/config/local.yaml @@ -3,4 +3,4 @@ storage_path: "./storage/sso.db" token_ttl: 1h grpc: port: 44044 - timeout: 10m \ No newline at end of file + timeout: 10m diff --git a/gen/sso/sso.pb.go b/gen/sso/sso.pb.go deleted file mode 100644 index abbeb02..0000000 --- a/gen/sso/sso.pb.go +++ /dev/null @@ -1,501 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.31.0 -// protoc v4.25.1 -// source: sso/sso.proto - -package ssov1 - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type RegisterRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` // Email of the user to register - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` // User ID of the registered user -} - -func (x *RegisterRequest) Reset() { - *x = RegisterRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_sso_sso_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *RegisterRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*RegisterRequest) ProtoMessage() {} - -func (x *RegisterRequest) ProtoReflect() protoreflect.Message { - mi := &file_sso_sso_proto_msgTypes[0] - 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 RegisterRequest.ProtoReflect.Descriptor instead. -func (*RegisterRequest) Descriptor() ([]byte, []int) { - return file_sso_sso_proto_rawDescGZIP(), []int{0} -} - -func (x *RegisterRequest) GetEmail() string { - if x != nil { - return x.Email - } - return "" -} - -func (x *RegisterRequest) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - -type RegisterResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // User ID of the registered user. -} - -func (x *RegisterResponse) Reset() { - *x = RegisterResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_sso_sso_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *RegisterResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*RegisterResponse) ProtoMessage() {} - -func (x *RegisterResponse) ProtoReflect() protoreflect.Message { - mi := &file_sso_sso_proto_msgTypes[1] - 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 RegisterResponse.ProtoReflect.Descriptor instead. -func (*RegisterResponse) Descriptor() ([]byte, []int) { - return file_sso_sso_proto_rawDescGZIP(), []int{1} -} - -func (x *RegisterResponse) GetUserId() int64 { - if x != nil { - return x.UserId - } - return 0 -} - -type LoginRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` // Email of the user to login. - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` // Password of the user to login. - AppId int32 `protobuf:"varint,3,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"` // ID of the app to login to. -} - -func (x *LoginRequest) Reset() { - *x = LoginRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_sso_sso_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *LoginRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*LoginRequest) ProtoMessage() {} - -func (x *LoginRequest) ProtoReflect() protoreflect.Message { - mi := &file_sso_sso_proto_msgTypes[2] - 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 LoginRequest.ProtoReflect.Descriptor instead. -func (*LoginRequest) Descriptor() ([]byte, []int) { - return file_sso_sso_proto_rawDescGZIP(), []int{2} -} - -func (x *LoginRequest) GetEmail() string { - if x != nil { - return x.Email - } - return "" -} - -func (x *LoginRequest) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - -func (x *LoginRequest) GetAppId() int32 { - if x != nil { - return x.AppId - } - return 0 -} - -type LoginResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` // Auth token of the logged in user. -} - -func (x *LoginResponse) Reset() { - *x = LoginResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_sso_sso_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *LoginResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*LoginResponse) ProtoMessage() {} - -func (x *LoginResponse) ProtoReflect() protoreflect.Message { - mi := &file_sso_sso_proto_msgTypes[3] - 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 LoginResponse.ProtoReflect.Descriptor instead. -func (*LoginResponse) Descriptor() ([]byte, []int) { - return file_sso_sso_proto_rawDescGZIP(), []int{3} -} - -func (x *LoginResponse) GetToken() string { - if x != nil { - return x.Token - } - return "" -} - -type IsAdminRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` // User ID to validate -} - -func (x *IsAdminRequest) Reset() { - *x = IsAdminRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_sso_sso_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *IsAdminRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*IsAdminRequest) ProtoMessage() {} - -func (x *IsAdminRequest) ProtoReflect() protoreflect.Message { - mi := &file_sso_sso_proto_msgTypes[4] - 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 IsAdminRequest.ProtoReflect.Descriptor instead. -func (*IsAdminRequest) Descriptor() ([]byte, []int) { - return file_sso_sso_proto_rawDescGZIP(), []int{4} -} - -func (x *IsAdminRequest) GetUserId() int64 { - if x != nil { - return x.UserId - } - return 0 -} - -type IsAdminResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - IsAdmin bool `protobuf:"varint,1,opt,name=is_admin,json=isAdmin,proto3" json:"is_admin,omitempty"` // Indicates whether the user is an admin. -} - -func (x *IsAdminResponse) Reset() { - *x = IsAdminResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_sso_sso_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *IsAdminResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*IsAdminResponse) ProtoMessage() {} - -func (x *IsAdminResponse) ProtoReflect() protoreflect.Message { - mi := &file_sso_sso_proto_msgTypes[5] - 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 IsAdminResponse.ProtoReflect.Descriptor instead. -func (*IsAdminResponse) Descriptor() ([]byte, []int) { - return file_sso_sso_proto_rawDescGZIP(), []int{5} -} - -func (x *IsAdminResponse) GetIsAdmin() bool { - if x != nil { - return x.IsAdmin - } - return false -} - -var File_sso_sso_proto protoreflect.FileDescriptor - -var file_sso_sso_proto_rawDesc = []byte{ - 0x0a, 0x0d, 0x73, 0x73, 0x6f, 0x2f, 0x73, 0x73, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x04, 0x61, 0x75, 0x74, 0x68, 0x22, 0x43, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, - 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, - 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, - 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x2b, 0x0a, 0x10, 0x52, 0x65, - 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x17, - 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x57, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, 0x69, 0x6e, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, - 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, - 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, - 0x22, 0x25, 0x0a, 0x0d, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x29, 0x0a, 0x0e, 0x49, 0x73, 0x41, 0x64, 0x6d, - 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, - 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, - 0x49, 0x64, 0x22, 0x2c, 0x0a, 0x0f, 0x49, 0x73, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x61, 0x64, 0x6d, 0x69, - 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x41, 0x64, 0x6d, 0x69, 0x6e, - 0x32, 0xab, 0x01, 0x0a, 0x04, 0x41, 0x75, 0x74, 0x68, 0x12, 0x39, 0x0a, 0x08, 0x52, 0x65, 0x67, - 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x15, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, 0x65, 0x67, - 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x61, - 0x75, 0x74, 0x68, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x12, 0x2e, - 0x61, 0x75, 0x74, 0x68, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x13, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, 0x0a, 0x07, 0x49, 0x73, 0x41, 0x64, 0x6d, 0x69, - 0x6e, 0x12, 0x14, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x49, 0x73, 0x41, 0x64, 0x6d, 0x69, 0x6e, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x49, - 0x73, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x13, - 0x5a, 0x11, 0x79, 0x61, 0x73, 0x68, 0x2e, 0x73, 0x73, 0x6f, 0x2e, 0x76, 0x31, 0x3b, 0x73, 0x73, - 0x6f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_sso_sso_proto_rawDescOnce sync.Once - file_sso_sso_proto_rawDescData = file_sso_sso_proto_rawDesc -) - -func file_sso_sso_proto_rawDescGZIP() []byte { - file_sso_sso_proto_rawDescOnce.Do(func() { - file_sso_sso_proto_rawDescData = protoimpl.X.CompressGZIP(file_sso_sso_proto_rawDescData) - }) - return file_sso_sso_proto_rawDescData -} - -var file_sso_sso_proto_msgTypes = make([]protoimpl.MessageInfo, 6) -var file_sso_sso_proto_goTypes = []interface{}{ - (*RegisterRequest)(nil), // 0: auth.RegisterRequest - (*RegisterResponse)(nil), // 1: auth.RegisterResponse - (*LoginRequest)(nil), // 2: auth.LoginRequest - (*LoginResponse)(nil), // 3: auth.LoginResponse - (*IsAdminRequest)(nil), // 4: auth.IsAdminRequest - (*IsAdminResponse)(nil), // 5: auth.IsAdminResponse -} -var file_sso_sso_proto_depIdxs = []int32{ - 0, // 0: auth.Auth.Register:input_type -> auth.RegisterRequest - 2, // 1: auth.Auth.Login:input_type -> auth.LoginRequest - 4, // 2: auth.Auth.IsAdmin:input_type -> auth.IsAdminRequest - 1, // 3: auth.Auth.Register:output_type -> auth.RegisterResponse - 3, // 4: auth.Auth.Login:output_type -> auth.LoginResponse - 5, // 5: auth.Auth.IsAdmin:output_type -> auth.IsAdminResponse - 3, // [3:6] is the sub-list for method output_type - 0, // [0:3] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_sso_sso_proto_init() } -func file_sso_sso_proto_init() { - if File_sso_sso_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_sso_sso_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RegisterRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_sso_sso_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RegisterResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_sso_sso_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LoginRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_sso_sso_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*LoginResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_sso_sso_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IsAdminRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_sso_sso_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*IsAdminResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_sso_sso_proto_rawDesc, - NumEnums: 0, - NumMessages: 6, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_sso_sso_proto_goTypes, - DependencyIndexes: file_sso_sso_proto_depIdxs, - MessageInfos: file_sso_sso_proto_msgTypes, - }.Build() - File_sso_sso_proto = out.File - file_sso_sso_proto_rawDesc = nil - file_sso_sso_proto_goTypes = nil - file_sso_sso_proto_depIdxs = nil -} diff --git a/gen/sso/sso_grpc.pb.go b/gen/sso/sso_grpc.pb.go deleted file mode 100644 index 594e01c..0000000 --- a/gen/sso/sso_grpc.pb.go +++ /dev/null @@ -1,183 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v4.25.1 -// source: sso/sso.proto - -package ssov1 - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// 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 - -const ( - Auth_Register_FullMethodName = "/auth.Auth/Register" - Auth_Login_FullMethodName = "/auth.Auth/Login" - Auth_IsAdmin_FullMethodName = "/auth.Auth/IsAdmin" -) - -// AuthClient is the client API for Auth service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type AuthClient interface { - Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterResponse, error) - Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) - IsAdmin(ctx context.Context, in *IsAdminRequest, opts ...grpc.CallOption) (*IsAdminResponse, error) -} - -type authClient struct { - cc grpc.ClientConnInterface -} - -func NewAuthClient(cc grpc.ClientConnInterface) AuthClient { - return &authClient{cc} -} - -func (c *authClient) Register(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterResponse, error) { - out := new(RegisterResponse) - err := c.cc.Invoke(ctx, Auth_Register_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) Login(ctx context.Context, in *LoginRequest, opts ...grpc.CallOption) (*LoginResponse, error) { - out := new(LoginResponse) - err := c.cc.Invoke(ctx, Auth_Login_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *authClient) IsAdmin(ctx context.Context, in *IsAdminRequest, opts ...grpc.CallOption) (*IsAdminResponse, error) { - out := new(IsAdminResponse) - err := c.cc.Invoke(ctx, Auth_IsAdmin_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// AuthServer is the server API for Auth service. -// All implementations must embed UnimplementedAuthServer -// for forward compatibility -type AuthServer interface { - Register(context.Context, *RegisterRequest) (*RegisterResponse, error) - Login(context.Context, *LoginRequest) (*LoginResponse, error) - IsAdmin(context.Context, *IsAdminRequest) (*IsAdminResponse, error) - mustEmbedUnimplementedAuthServer() -} - -// UnimplementedAuthServer must be embedded to have forward compatible implementations. -type UnimplementedAuthServer struct { -} - -func (UnimplementedAuthServer) Register(context.Context, *RegisterRequest) (*RegisterResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Register not implemented") -} -func (UnimplementedAuthServer) Login(context.Context, *LoginRequest) (*LoginResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Login not implemented") -} -func (UnimplementedAuthServer) IsAdmin(context.Context, *IsAdminRequest) (*IsAdminResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method IsAdmin not implemented") -} -func (UnimplementedAuthServer) mustEmbedUnimplementedAuthServer() {} - -// UnsafeAuthServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to AuthServer will -// result in compilation errors. -type UnsafeAuthServer interface { - mustEmbedUnimplementedAuthServer() -} - -func RegisterAuthServer(s grpc.ServiceRegistrar, srv AuthServer) { - s.RegisterService(&Auth_ServiceDesc, srv) -} - -func _Auth_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(RegisterRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).Register(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Auth_Register_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).Register(ctx, req.(*RegisterRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_Login_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LoginRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).Login(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Auth_Login_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).Login(ctx, req.(*LoginRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Auth_IsAdmin_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(IsAdminRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(AuthServer).IsAdmin(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Auth_IsAdmin_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AuthServer).IsAdmin(ctx, req.(*IsAdminRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Auth_ServiceDesc is the grpc.ServiceDesc for Auth service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Auth_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "auth.Auth", - HandlerType: (*AuthServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Register", - Handler: _Auth_Register_Handler, - }, - { - MethodName: "Login", - Handler: _Auth_Login_Handler, - }, - { - MethodName: "IsAdmin", - Handler: _Auth_IsAdmin_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "sso/sso.proto", -} diff --git a/go.mod b/go.mod index ff1e8b5..ba3b69c 100644 --- a/go.mod +++ b/go.mod @@ -1,36 +1,36 @@ -module gitea.computernetthings.ru/yash/sso +module sso go 1.21.4 require ( + gitea.computernetthings.ru/yash/protos v0.0.0-20231217102721-4a790fbcdf08 + github.com/brianvoe/gofakeit/v6 v6.26.3 github.com/fatih/color v1.16.0 github.com/golang-jwt/jwt/v5 v5.2.0 + github.com/golang-migrate/migrate/v4 v4.16.2 github.com/ilyakaznacheev/cleanenv v1.5.0 + github.com/mattn/go-sqlite3 v1.14.19 + github.com/stretchr/testify v1.8.4 golang.org/x/crypto v0.16.0 google.golang.org/grpc v1.59.0 - google.golang.org/protobuf v1.31.0 ) require ( github.com/BurntSushi/toml v1.2.1 // indirect - github.com/brianvoe/gofakeit/v6 v6.26.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang-migrate/migrate/v4 v4.16.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/joho/godotenv v1.5.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-sqlite3 v1.14.19 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/objx v0.5.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect go.uber.org/atomic v1.7.0 // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect ) diff --git a/go.sum b/go.sum index 93c2577..325427f 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +gitea.computernetthings.ru/yash/protos v0.0.0-20231217102721-4a790fbcdf08 h1:JwfUsP/n9J6qwEwDwg1p4Qtsaq8w5ipeeGIM+8vSjQE= +gitea.computernetthings.ru/yash/protos v0.0.0-20231217102721-4a790fbcdf08/go.mod h1:j7+PiS3iZUUGe9LU03ic2SjFwbHLXWtMxaoNiJsPMIQ= github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8= @@ -26,24 +28,19 @@ github.com/ilyakaznacheev/cleanenv v1.5.0 h1:0VNZXggJE2OYdXE87bfSSwGxeiGt9moSR2l github.com/ilyakaznacheev/cleanenv v1.5.0/go.mod h1:a5aDzaJrLCQZsazHol1w8InnDcOX0OColm64SlIi6gk= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8= +github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= -github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= @@ -69,7 +66,6 @@ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 h1:slmdOY3vp8a7KQbHkL+FLbvbkgMqmXojpFUO/jENuqQ= diff --git a/internal/grpc/auth/server.go b/internal/grpc/auth/server.go index 9dabcdd..1bf002c 100644 --- a/internal/grpc/auth/server.go +++ b/internal/grpc/auth/server.go @@ -3,9 +3,10 @@ package auth import ( "context" "errors" - ssov1 "sso/gen/sso" "sso/internal/services/auth" + ssov1 "gitea.computernetthings.ru/yash/protos/gen/sso" + "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/proto/sso/sso.proto b/proto/sso/sso.proto deleted file mode 100644 index 746a607..0000000 --- a/proto/sso/sso.proto +++ /dev/null @@ -1,38 +0,0 @@ -syntax = "proto3"; - -package auth; - -option go_package = "yash.sso.v1;ssov1"; - -service Auth { - rpc Register (RegisterRequest) returns (RegisterResponse); - rpc Login (LoginRequest) returns (LoginResponse); - rpc IsAdmin (IsAdminRequest) returns (IsAdminResponse); -} - -message RegisterRequest { - string email = 1; // Email of the user to register - string password = 2; // User ID of the registered user -} - -message RegisterResponse { - int64 user_id = 1; // User ID of the registered user. -} - -message LoginRequest { - string email = 1; // Email of the user to login. - string password = 2; // Password of the user to login. - int32 app_id = 3; // ID of the app to login to. -} - -message LoginResponse { - string token = 1; // Auth token of the logged in user. -} - -message IsAdminRequest { - int64 user_id = 1; // User ID to validate -} - -message IsAdminResponse { - bool is_admin = 1; // Indicates whether the user is an admin. -} diff --git a/tests/auth_register_login_test.go b/tests/auth_register_login_test.go index 6c39935..c2c5b65 100644 --- a/tests/auth_register_login_test.go +++ b/tests/auth_register_login_test.go @@ -1,11 +1,12 @@ package tests import ( - ssov1 "sso/gen/sso" "sso/tests/suite" "testing" "time" + ssov1 "gitea.computernetthings.ru/yash/protos/gen/sso" + "github.com/brianvoe/gofakeit/v6" "github.com/golang-jwt/jwt/v5" "github.com/stretchr/testify/assert" diff --git a/tests/suite/suite.go b/tests/suite/suite.go index b316607..91199e1 100644 --- a/tests/suite/suite.go +++ b/tests/suite/suite.go @@ -3,11 +3,12 @@ package suite import ( "context" "net" - ssov1 "sso/gen/sso" "sso/internal/config" "strconv" "testing" + ssov1 "gitea.computernetthings.ru/yash/protos/gen/sso" + "google.golang.org/grpc" )