✨ Record event & check user relation permission APis
This commit is contained in:
parent
ad83100677
commit
4e96bb2cd5
@ -3,10 +3,11 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/internal/directory"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (v *Server) Authenticate(ctx context.Context, request *proto.AuthRequest) (*proto.AuthReply, error) {
|
||||
@ -27,10 +28,10 @@ func (v *Server) Authenticate(ctx context.Context, request *proto.AuthRequest) (
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (v *Server) EnsurePermGranted(ctx context.Context, request *proto.CheckPermRequest) (*proto.CheckPermReply, error) {
|
||||
func (v *Server) EnsurePermGranted(ctx context.Context, request *proto.CheckPermRequest) (*proto.CheckPermResponse, error) {
|
||||
instance := directory.GetServiceInstanceByType(hyper.ServiceTypeAuthProvider)
|
||||
if instance == nil {
|
||||
return &proto.CheckPermReply{}, fmt.Errorf("no available service %s found", hyper.ServiceTypeAuthProvider)
|
||||
return &proto.CheckPermResponse{}, fmt.Errorf("no available service %s found", hyper.ServiceTypeAuthProvider)
|
||||
}
|
||||
|
||||
conn, err := instance.GetGrpcConn()
|
||||
@ -44,3 +45,21 @@ func (v *Server) EnsurePermGranted(ctx context.Context, request *proto.CheckPerm
|
||||
out, err := proto.NewAuthClient(conn).EnsurePermGranted(ctx, request)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (v *Server) EnsureUserPermGranted(ctx context.Context, request *proto.CheckUserPermRequest) (*proto.CheckUserPermResponse, error) {
|
||||
instance := directory.GetServiceInstance(hyper.ServiceTypeAuthProvider)
|
||||
if instance == nil {
|
||||
return &proto.CheckUserPermResponse{}, fmt.Errorf("no available service %s found", hyper.ServiceTypeAuthProvider)
|
||||
}
|
||||
|
||||
conn, err := instance.GetGrpcConn()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("service is down: %v", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
out, err := proto.NewAuthClient(conn).EnsureUserPermGranted(ctx, request)
|
||||
return out, err
|
||||
}
|
||||
|
29
pkg/internal/grpc/record.go
Normal file
29
pkg/internal/grpc/record.go
Normal file
@ -0,0 +1,29 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/internal/directory"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
)
|
||||
|
||||
func (v *Server) RecordEvent(ctx context.Context, request *proto.RecordEventRequest) (*proto.RecordEventResponse, error) {
|
||||
instance := directory.GetServiceInstance(hyper.ServiceTypeAuthProvider)
|
||||
if instance == nil {
|
||||
return &proto.RecordEventResponse{}, fmt.Errorf("no available service %s found", hyper.ServiceTypeAuthProvider)
|
||||
}
|
||||
|
||||
conn, err := instance.GetGrpcConn()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("service is down: %v", err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
out, err := proto.NewEventRecorderClient(conn).RecordEvent(ctx, request)
|
||||
return out, err
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"net"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
|
||||
"google.golang.org/grpc/reflection"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
@ -15,6 +16,7 @@ import (
|
||||
type Server struct {
|
||||
proto.UnimplementedServiceDirectoryServer
|
||||
proto.UnimplementedStreamControllerServer
|
||||
proto.UnimplementedEventRecorderServer
|
||||
proto.UnimplementedAuthServer
|
||||
|
||||
srv *grpc.Server
|
||||
@ -27,6 +29,7 @@ func NewServer() *Server {
|
||||
|
||||
proto.RegisterServiceDirectoryServer(server.srv, server)
|
||||
proto.RegisterStreamControllerServer(server.srv, server)
|
||||
proto.RegisterEventRecorderServer(server.srv, server)
|
||||
proto.RegisterAuthServer(server.srv, server)
|
||||
health.RegisterHealthServer(server.srv, server)
|
||||
|
||||
|
@ -367,7 +367,7 @@ func (x *CheckPermRequest) GetValue() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
type CheckPermReply struct {
|
||||
type CheckPermResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
@ -375,8 +375,8 @@ type CheckPermReply struct {
|
||||
IsValid bool `protobuf:"varint,1,opt,name=is_valid,json=isValid,proto3" json:"is_valid,omitempty"`
|
||||
}
|
||||
|
||||
func (x *CheckPermReply) Reset() {
|
||||
*x = CheckPermReply{}
|
||||
func (x *CheckPermResponse) Reset() {
|
||||
*x = CheckPermResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_auth_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@ -384,13 +384,13 @@ func (x *CheckPermReply) Reset() {
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CheckPermReply) String() string {
|
||||
func (x *CheckPermResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CheckPermReply) ProtoMessage() {}
|
||||
func (*CheckPermResponse) ProtoMessage() {}
|
||||
|
||||
func (x *CheckPermReply) ProtoReflect() protoreflect.Message {
|
||||
func (x *CheckPermResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_auth_proto_msgTypes[5]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@ -402,12 +402,130 @@ func (x *CheckPermReply) ProtoReflect() protoreflect.Message {
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CheckPermReply.ProtoReflect.Descriptor instead.
|
||||
func (*CheckPermReply) Descriptor() ([]byte, []int) {
|
||||
// Deprecated: Use CheckPermResponse.ProtoReflect.Descriptor instead.
|
||||
func (*CheckPermResponse) Descriptor() ([]byte, []int) {
|
||||
return file_auth_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *CheckPermReply) GetIsValid() bool {
|
||||
func (x *CheckPermResponse) GetIsValid() bool {
|
||||
if x != nil {
|
||||
return x.IsValid
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type CheckUserPermRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId uint64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||
OtherId uint64 `protobuf:"varint,2,opt,name=other_id,json=otherId,proto3" json:"other_id,omitempty"`
|
||||
Key string `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"`
|
||||
Value []byte `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"`
|
||||
}
|
||||
|
||||
func (x *CheckUserPermRequest) Reset() {
|
||||
*x = CheckUserPermRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_auth_proto_msgTypes[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CheckUserPermRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CheckUserPermRequest) ProtoMessage() {}
|
||||
|
||||
func (x *CheckUserPermRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_auth_proto_msgTypes[6]
|
||||
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 CheckUserPermRequest.ProtoReflect.Descriptor instead.
|
||||
func (*CheckUserPermRequest) Descriptor() ([]byte, []int) {
|
||||
return file_auth_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *CheckUserPermRequest) GetUserId() uint64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *CheckUserPermRequest) GetOtherId() uint64 {
|
||||
if x != nil {
|
||||
return x.OtherId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *CheckUserPermRequest) GetKey() string {
|
||||
if x != nil {
|
||||
return x.Key
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CheckUserPermRequest) GetValue() []byte {
|
||||
if x != nil {
|
||||
return x.Value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type CheckUserPermResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
IsValid bool `protobuf:"varint,1,opt,name=is_valid,json=isValid,proto3" json:"is_valid,omitempty"`
|
||||
}
|
||||
|
||||
func (x *CheckUserPermResponse) Reset() {
|
||||
*x = CheckUserPermResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_auth_proto_msgTypes[7]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CheckUserPermResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CheckUserPermResponse) ProtoMessage() {}
|
||||
|
||||
func (x *CheckUserPermResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_auth_proto_msgTypes[7]
|
||||
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 CheckUserPermResponse.ProtoReflect.Descriptor instead.
|
||||
func (*CheckUserPermResponse) Descriptor() ([]byte, []int) {
|
||||
return file_auth_proto_rawDescGZIP(), []int{7}
|
||||
}
|
||||
|
||||
func (x *CheckUserPermResponse) GetIsValid() bool {
|
||||
if x != nil {
|
||||
return x.IsValid
|
||||
}
|
||||
@ -463,20 +581,36 @@ var file_auth_proto_rawDesc = []byte{
|
||||
0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74,
|
||||
0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18,
|
||||
0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x2b, 0x0a, 0x0e,
|
||||
0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x19,
|
||||
0x0a, 0x08, 0x69, 0x73, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08,
|
||||
0x52, 0x07, 0x69, 0x73, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x32, 0x85, 0x01, 0x0a, 0x04, 0x41, 0x75,
|
||||
0x74, 0x68, 0x12, 0x36, 0x0a, 0x0c, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61,
|
||||
0x74, 0x65, 0x12, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41,
|
||||
0x75, 0x74, 0x68, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x11, 0x45, 0x6e,
|
||||
0x73, 0x75, 0x72, 0x65, 0x50, 0x65, 0x72, 0x6d, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x12,
|
||||
0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x65, 0x72,
|
||||
0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22,
|
||||
0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x2e, 0x0a, 0x11,
|
||||
0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x22, 0x72, 0x0a, 0x14,
|
||||
0x43, 0x68, 0x65, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x71,
|
||||
0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x19, 0x0a,
|
||||
0x08, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52,
|
||||
0x07, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x49, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
|
||||
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
|
||||
0x6c, 0x75, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
|
||||
0x22, 0x32, 0x0a, 0x15, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x50, 0x65, 0x72,
|
||||
0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f,
|
||||
0x76, 0x61, 0x6c, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x56,
|
||||
0x61, 0x6c, 0x69, 0x64, 0x32, 0xde, 0x01, 0x0a, 0x04, 0x41, 0x75, 0x74, 0x68, 0x12, 0x36, 0x0a,
|
||||
0x0c, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x12, 0x12, 0x2e,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65,
|
||||
0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x11, 0x45, 0x6e, 0x73, 0x75, 0x72, 0x65, 0x50,
|
||||
0x65, 0x72, 0x6d, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68, 0x65, 0x63,
|
||||
0x6b, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12,
|
||||
0x54, 0x0a, 0x15, 0x45, 0x6e, 0x73, 0x75, 0x72, 0x65, 0x55, 0x73, 0x65, 0x72, 0x50, 0x65, 0x72,
|
||||
0x6d, 0x47, 0x72, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x12, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x68,
|
||||
0x65, 0x63, 0x6b, 0x55, 0x73, 0x65, 0x72, 0x50, 0x65, 0x72, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -491,24 +625,28 @@ func file_auth_proto_rawDescGZIP() []byte {
|
||||
return file_auth_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_auth_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
||||
var file_auth_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
|
||||
var file_auth_proto_goTypes = []any{
|
||||
(*UserInfo)(nil), // 0: proto.UserInfo
|
||||
(*AuthInfo)(nil), // 1: proto.AuthInfo
|
||||
(*AuthRequest)(nil), // 2: proto.AuthRequest
|
||||
(*AuthReply)(nil), // 3: proto.AuthReply
|
||||
(*CheckPermRequest)(nil), // 4: proto.CheckPermRequest
|
||||
(*CheckPermReply)(nil), // 5: proto.CheckPermReply
|
||||
(*CheckPermResponse)(nil), // 5: proto.CheckPermResponse
|
||||
(*CheckUserPermRequest)(nil), // 6: proto.CheckUserPermRequest
|
||||
(*CheckUserPermResponse)(nil), // 7: proto.CheckUserPermResponse
|
||||
}
|
||||
var file_auth_proto_depIdxs = []int32{
|
||||
0, // 0: proto.AuthInfo.info:type_name -> proto.UserInfo
|
||||
1, // 1: proto.AuthReply.info:type_name -> proto.AuthInfo
|
||||
2, // 2: proto.Auth.Authenticate:input_type -> proto.AuthRequest
|
||||
4, // 3: proto.Auth.EnsurePermGranted:input_type -> proto.CheckPermRequest
|
||||
3, // 4: proto.Auth.Authenticate:output_type -> proto.AuthReply
|
||||
5, // 5: proto.Auth.EnsurePermGranted:output_type -> proto.CheckPermReply
|
||||
4, // [4:6] is the sub-list for method output_type
|
||||
2, // [2:4] is the sub-list for method input_type
|
||||
6, // 4: proto.Auth.EnsureUserPermGranted:input_type -> proto.CheckUserPermRequest
|
||||
3, // 5: proto.Auth.Authenticate:output_type -> proto.AuthReply
|
||||
5, // 6: proto.Auth.EnsurePermGranted:output_type -> proto.CheckPermResponse
|
||||
7, // 7: proto.Auth.EnsureUserPermGranted:output_type -> proto.CheckUserPermResponse
|
||||
5, // [5:8] is the sub-list for method output_type
|
||||
2, // [2:5] is the sub-list for method input_type
|
||||
2, // [2:2] is the sub-list for extension type_name
|
||||
2, // [2:2] is the sub-list for extension extendee
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
@ -581,7 +719,31 @@ func file_auth_proto_init() {
|
||||
}
|
||||
}
|
||||
file_auth_proto_msgTypes[5].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*CheckPermReply); i {
|
||||
switch v := v.(*CheckPermResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_auth_proto_msgTypes[6].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*CheckUserPermRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_auth_proto_msgTypes[7].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*CheckUserPermResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@ -603,7 +765,7 @@ func file_auth_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_auth_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 6,
|
||||
NumMessages: 8,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
@ -6,7 +6,8 @@ package proto;
|
||||
|
||||
service Auth {
|
||||
rpc Authenticate(AuthRequest) returns (AuthReply) {}
|
||||
rpc EnsurePermGranted(CheckPermRequest) returns (CheckPermReply) {}
|
||||
rpc EnsurePermGranted(CheckPermRequest) returns (CheckPermResponse) {}
|
||||
rpc EnsureUserPermGranted(CheckUserPermRequest) returns (CheckUserPermResponse) {}
|
||||
}
|
||||
|
||||
message UserInfo {
|
||||
@ -43,6 +44,17 @@ message CheckPermRequest {
|
||||
bytes value = 3;
|
||||
}
|
||||
|
||||
message CheckPermReply {
|
||||
message CheckPermResponse {
|
||||
bool is_valid = 1;
|
||||
}
|
||||
|
||||
message CheckUserPermRequest {
|
||||
uint64 user_id = 1;
|
||||
uint64 other_id = 2;
|
||||
string key = 3;
|
||||
bytes value = 4;
|
||||
}
|
||||
|
||||
message CheckUserPermResponse {
|
||||
bool is_valid = 1;
|
||||
}
|
@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion8
|
||||
const (
|
||||
Auth_Authenticate_FullMethodName = "/proto.Auth/Authenticate"
|
||||
Auth_EnsurePermGranted_FullMethodName = "/proto.Auth/EnsurePermGranted"
|
||||
Auth_EnsureUserPermGranted_FullMethodName = "/proto.Auth/EnsureUserPermGranted"
|
||||
)
|
||||
|
||||
// AuthClient is the client API for Auth service.
|
||||
@ -28,7 +29,8 @@ const (
|
||||
// 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 {
|
||||
Authenticate(ctx context.Context, in *AuthRequest, opts ...grpc.CallOption) (*AuthReply, error)
|
||||
EnsurePermGranted(ctx context.Context, in *CheckPermRequest, opts ...grpc.CallOption) (*CheckPermReply, error)
|
||||
EnsurePermGranted(ctx context.Context, in *CheckPermRequest, opts ...grpc.CallOption) (*CheckPermResponse, error)
|
||||
EnsureUserPermGranted(ctx context.Context, in *CheckUserPermRequest, opts ...grpc.CallOption) (*CheckUserPermResponse, error)
|
||||
}
|
||||
|
||||
type authClient struct {
|
||||
@ -49,9 +51,9 @@ func (c *authClient) Authenticate(ctx context.Context, in *AuthRequest, opts ...
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authClient) EnsurePermGranted(ctx context.Context, in *CheckPermRequest, opts ...grpc.CallOption) (*CheckPermReply, error) {
|
||||
func (c *authClient) EnsurePermGranted(ctx context.Context, in *CheckPermRequest, opts ...grpc.CallOption) (*CheckPermResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CheckPermReply)
|
||||
out := new(CheckPermResponse)
|
||||
err := c.cc.Invoke(ctx, Auth_EnsurePermGranted_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -59,12 +61,23 @@ func (c *authClient) EnsurePermGranted(ctx context.Context, in *CheckPermRequest
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authClient) EnsureUserPermGranted(ctx context.Context, in *CheckUserPermRequest, opts ...grpc.CallOption) (*CheckUserPermResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CheckUserPermResponse)
|
||||
err := c.cc.Invoke(ctx, Auth_EnsureUserPermGranted_FullMethodName, in, out, cOpts...)
|
||||
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 {
|
||||
Authenticate(context.Context, *AuthRequest) (*AuthReply, error)
|
||||
EnsurePermGranted(context.Context, *CheckPermRequest) (*CheckPermReply, error)
|
||||
EnsurePermGranted(context.Context, *CheckPermRequest) (*CheckPermResponse, error)
|
||||
EnsureUserPermGranted(context.Context, *CheckUserPermRequest) (*CheckUserPermResponse, error)
|
||||
mustEmbedUnimplementedAuthServer()
|
||||
}
|
||||
|
||||
@ -75,9 +88,12 @@ type UnimplementedAuthServer struct {
|
||||
func (UnimplementedAuthServer) Authenticate(context.Context, *AuthRequest) (*AuthReply, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Authenticate not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServer) EnsurePermGranted(context.Context, *CheckPermRequest) (*CheckPermReply, error) {
|
||||
func (UnimplementedAuthServer) EnsurePermGranted(context.Context, *CheckPermRequest) (*CheckPermResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method EnsurePermGranted not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServer) EnsureUserPermGranted(context.Context, *CheckUserPermRequest) (*CheckUserPermResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method EnsureUserPermGranted not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServer) mustEmbedUnimplementedAuthServer() {}
|
||||
|
||||
// UnsafeAuthServer may be embedded to opt out of forward compatibility for this service.
|
||||
@ -127,6 +143,24 @@ func _Auth_EnsurePermGranted_Handler(srv interface{}, ctx context.Context, dec f
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Auth_EnsureUserPermGranted_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CheckUserPermRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServer).EnsureUserPermGranted(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Auth_EnsureUserPermGranted_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServer).EnsureUserPermGranted(ctx, req.(*CheckUserPermRequest))
|
||||
}
|
||||
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)
|
||||
@ -142,6 +176,10 @@ var Auth_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "EnsurePermGranted",
|
||||
Handler: _Auth_EnsurePermGranted_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "EnsureUserPermGranted",
|
||||
Handler: _Auth_EnsureUserPermGranted_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "auth.proto",
|
||||
|
251
pkg/proto/record.pb.go
Normal file
251
pkg/proto/record.pb.go
Normal file
@ -0,0 +1,251 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.34.2
|
||||
// protoc v5.27.1
|
||||
// source: record.proto
|
||||
|
||||
package proto
|
||||
|
||||
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 RecordEventRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId uint64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||
Action string `protobuf:"bytes,2,opt,name=action,proto3" json:"action,omitempty"`
|
||||
Target string `protobuf:"bytes,3,opt,name=target,proto3" json:"target,omitempty"`
|
||||
Ip string `protobuf:"bytes,4,opt,name=ip,proto3" json:"ip,omitempty"`
|
||||
UserAgent string `protobuf:"bytes,5,opt,name=user_agent,json=userAgent,proto3" json:"user_agent,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) Reset() {
|
||||
*x = RecordEventRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_record_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*RecordEventRequest) ProtoMessage() {}
|
||||
|
||||
func (x *RecordEventRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_record_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 RecordEventRequest.ProtoReflect.Descriptor instead.
|
||||
func (*RecordEventRequest) Descriptor() ([]byte, []int) {
|
||||
return file_record_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) GetUserId() uint64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) GetAction() string {
|
||||
if x != nil {
|
||||
return x.Action
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) GetTarget() string {
|
||||
if x != nil {
|
||||
return x.Target
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) GetIp() string {
|
||||
if x != nil {
|
||||
return x.Ip
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *RecordEventRequest) GetUserAgent() string {
|
||||
if x != nil {
|
||||
return x.UserAgent
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type RecordEventResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
IsSuccess bool `protobuf:"varint,1,opt,name=is_success,json=isSuccess,proto3" json:"is_success,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RecordEventResponse) Reset() {
|
||||
*x = RecordEventResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_record_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *RecordEventResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*RecordEventResponse) ProtoMessage() {}
|
||||
|
||||
func (x *RecordEventResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_record_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 RecordEventResponse.ProtoReflect.Descriptor instead.
|
||||
func (*RecordEventResponse) Descriptor() ([]byte, []int) {
|
||||
return file_record_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *RecordEventResponse) GetIsSuccess() bool {
|
||||
if x != nil {
|
||||
return x.IsSuccess
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var File_record_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_record_proto_rawDesc = []byte{
|
||||
0x0a, 0x0c, 0x72, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8c, 0x01, 0x0a, 0x12, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64,
|
||||
0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07,
|
||||
0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x75,
|
||||
0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a,
|
||||
0x06, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74,
|
||||
0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x02, 0x69, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x61, 0x67,
|
||||
0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x41,
|
||||
0x67, 0x65, 0x6e, 0x74, 0x22, 0x34, 0x0a, 0x13, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x45, 0x76,
|
||||
0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69,
|
||||
0x73, 0x5f, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52,
|
||||
0x09, 0x69, 0x73, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x32, 0x57, 0x0a, 0x0d, 0x45, 0x76,
|
||||
0x65, 0x6e, 0x74, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x46, 0x0a, 0x0b, 0x52,
|
||||
0x65, 0x63, 0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x19, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65,
|
||||
0x63, 0x6f, 0x72, 0x64, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_record_proto_rawDescOnce sync.Once
|
||||
file_record_proto_rawDescData = file_record_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_record_proto_rawDescGZIP() []byte {
|
||||
file_record_proto_rawDescOnce.Do(func() {
|
||||
file_record_proto_rawDescData = protoimpl.X.CompressGZIP(file_record_proto_rawDescData)
|
||||
})
|
||||
return file_record_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_record_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_record_proto_goTypes = []any{
|
||||
(*RecordEventRequest)(nil), // 0: proto.RecordEventRequest
|
||||
(*RecordEventResponse)(nil), // 1: proto.RecordEventResponse
|
||||
}
|
||||
var file_record_proto_depIdxs = []int32{
|
||||
0, // 0: proto.EventRecorder.RecordEvent:input_type -> proto.RecordEventRequest
|
||||
1, // 1: proto.EventRecorder.RecordEvent:output_type -> proto.RecordEventResponse
|
||||
1, // [1:2] is the sub-list for method output_type
|
||||
0, // [0:1] 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_record_proto_init() }
|
||||
func file_record_proto_init() {
|
||||
if File_record_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_record_proto_msgTypes[0].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*RecordEventRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_record_proto_msgTypes[1].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*RecordEventResponse); 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_record_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_record_proto_goTypes,
|
||||
DependencyIndexes: file_record_proto_depIdxs,
|
||||
MessageInfos: file_record_proto_msgTypes,
|
||||
}.Build()
|
||||
File_record_proto = out.File
|
||||
file_record_proto_rawDesc = nil
|
||||
file_record_proto_goTypes = nil
|
||||
file_record_proto_depIdxs = nil
|
||||
}
|
21
pkg/proto/record.proto
Normal file
21
pkg/proto/record.proto
Normal file
@ -0,0 +1,21 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option go_package = ".;proto";
|
||||
|
||||
package proto;
|
||||
|
||||
service EventRecorder {
|
||||
rpc RecordEvent(RecordEventRequest) returns (RecordEventResponse) {}
|
||||
}
|
||||
|
||||
message RecordEventRequest {
|
||||
uint64 user_id = 1;
|
||||
string action = 2;
|
||||
string target = 3;
|
||||
string ip = 4;
|
||||
string user_agent = 5;
|
||||
}
|
||||
|
||||
message RecordEventResponse {
|
||||
bool is_success = 1;
|
||||
}
|
110
pkg/proto/record_grpc.pb.go
Normal file
110
pkg/proto/record_grpc.pb.go
Normal file
@ -0,0 +1,110 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.4.0
|
||||
// - protoc v5.27.1
|
||||
// source: record.proto
|
||||
|
||||
package proto
|
||||
|
||||
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.62.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion8
|
||||
|
||||
const (
|
||||
EventRecorder_RecordEvent_FullMethodName = "/proto.EventRecorder/RecordEvent"
|
||||
)
|
||||
|
||||
// EventRecorderClient is the client API for EventRecorder 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 EventRecorderClient interface {
|
||||
RecordEvent(ctx context.Context, in *RecordEventRequest, opts ...grpc.CallOption) (*RecordEventResponse, error)
|
||||
}
|
||||
|
||||
type eventRecorderClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewEventRecorderClient(cc grpc.ClientConnInterface) EventRecorderClient {
|
||||
return &eventRecorderClient{cc}
|
||||
}
|
||||
|
||||
func (c *eventRecorderClient) RecordEvent(ctx context.Context, in *RecordEventRequest, opts ...grpc.CallOption) (*RecordEventResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(RecordEventResponse)
|
||||
err := c.cc.Invoke(ctx, EventRecorder_RecordEvent_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// EventRecorderServer is the server API for EventRecorder service.
|
||||
// All implementations must embed UnimplementedEventRecorderServer
|
||||
// for forward compatibility
|
||||
type EventRecorderServer interface {
|
||||
RecordEvent(context.Context, *RecordEventRequest) (*RecordEventResponse, error)
|
||||
mustEmbedUnimplementedEventRecorderServer()
|
||||
}
|
||||
|
||||
// UnimplementedEventRecorderServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedEventRecorderServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedEventRecorderServer) RecordEvent(context.Context, *RecordEventRequest) (*RecordEventResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method RecordEvent not implemented")
|
||||
}
|
||||
func (UnimplementedEventRecorderServer) mustEmbedUnimplementedEventRecorderServer() {}
|
||||
|
||||
// UnsafeEventRecorderServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to EventRecorderServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeEventRecorderServer interface {
|
||||
mustEmbedUnimplementedEventRecorderServer()
|
||||
}
|
||||
|
||||
func RegisterEventRecorderServer(s grpc.ServiceRegistrar, srv EventRecorderServer) {
|
||||
s.RegisterService(&EventRecorder_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _EventRecorder_RecordEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RecordEventRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(EventRecorderServer).RecordEvent(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: EventRecorder_RecordEvent_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EventRecorderServer).RecordEvent(ctx, req.(*RecordEventRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// EventRecorder_ServiceDesc is the grpc.ServiceDesc for EventRecorder service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var EventRecorder_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "proto.EventRecorder",
|
||||
HandlerType: (*EventRecorderServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "RecordEvent",
|
||||
Handler: _EventRecorder_RecordEvent_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "record.proto",
|
||||
}
|
Loading…
Reference in New Issue
Block a user