✨ Record event & check user relation permission APis
This commit is contained in:
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user