From 31e73c438e33fd4d0d8ac5440fb1fb4ba942b3ab Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 14 Jul 2024 20:56:06 +0800 Subject: [PATCH] :truck: Move the service type into hyper sdk --- .idea/vcs.xml | 6 ++++++ pkg/hyper/auth.go | 5 ++--- pkg/hyper/const.go | 8 ++++++++ pkg/internal/directory/services.go | 5 ----- pkg/internal/grpc/auth.go | 9 +++++---- pkg/internal/server/exts/auth.go | 4 ++-- 6 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 pkg/hyper/const.go diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pkg/hyper/auth.go b/pkg/hyper/auth.go index 973d972..74bd849 100644 --- a/pkg/hyper/auth.go +++ b/pkg/hyper/auth.go @@ -3,7 +3,6 @@ package hyper import ( "context" "fmt" - "git.solsynth.dev/hydrogen/dealer/pkg/internal/directory" "time" "git.solsynth.dev/hydrogen/dealer/pkg/proto" @@ -15,7 +14,7 @@ func (v *HyperConn) DoAuthenticate(atk, rtk string) (acc *proto.UserInfo, access defer cancel() var in *grpc.ClientConn - in, err = v.GetServiceGrpcConn(directory.ServiceTypeAuthProvider) + in, err = v.GetServiceGrpcConn(ServiceTypeAuthProvider) if err != nil { return } @@ -45,7 +44,7 @@ func (v *HyperConn) CheckPermGranted(atk string, key string, val []byte) error { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - in, err := v.GetServiceGrpcConn(directory.ServiceTypeAuthProvider) + in, err := v.GetServiceGrpcConn(ServiceTypeAuthProvider) if err != nil { return err } diff --git a/pkg/hyper/const.go b/pkg/hyper/const.go new file mode 100644 index 0000000..d8f7b4a --- /dev/null +++ b/pkg/hyper/const.go @@ -0,0 +1,8 @@ +package hyper + +const ( + ServiceTypeAuthProvider = "auth" + ServiceTypeFileProvider = "files" + ServiceTypeInteractiveProvider = "interactive" + ServiceTypeMessagingProvider = "messaging" +) diff --git a/pkg/internal/directory/services.go b/pkg/internal/directory/services.go index bb9bcbe..17197b9 100644 --- a/pkg/internal/directory/services.go +++ b/pkg/internal/directory/services.go @@ -4,11 +4,6 @@ import ( "sync" ) -const ( - ServiceTypeAuthProvider = "passport" - ServiceTypeFileProvider = "paperclip" -) - var serviceDirectory sync.Map func GetServiceInstance(id string) *ServiceInstance { diff --git a/pkg/internal/grpc/auth.go b/pkg/internal/grpc/auth.go index 048a180..c30d20a 100644 --- a/pkg/internal/grpc/auth.go +++ b/pkg/internal/grpc/auth.go @@ -3,15 +3,16 @@ package grpc import ( "context" "fmt" + "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) { - instance := directory.GetServiceInstanceByType(directory.ServiceTypeAuthProvider) + instance := directory.GetServiceInstanceByType(hyper.ServiceTypeAuthProvider) if instance == nil { - return &proto.AuthReply{}, fmt.Errorf("no available service %s found", directory.ServiceTypeAuthProvider) + return &proto.AuthReply{}, fmt.Errorf("no available service %s found", hyper.ServiceTypeAuthProvider) } conn, err := instance.GetGrpcConn() @@ -27,9 +28,9 @@ func (v *Server) Authenticate(ctx context.Context, request *proto.AuthRequest) ( } func (v *Server) EnsurePermGranted(ctx context.Context, request *proto.CheckPermRequest) (*proto.CheckPermReply, error) { - instance := directory.GetServiceInstanceByType(directory.ServiceTypeAuthProvider) + instance := directory.GetServiceInstanceByType(hyper.ServiceTypeAuthProvider) if instance == nil { - return &proto.CheckPermReply{}, fmt.Errorf("no available service %s found", directory.ServiceTypeAuthProvider) + return &proto.CheckPermReply{}, fmt.Errorf("no available service %s found", hyper.ServiceTypeAuthProvider) } conn, err := instance.GetGrpcConn() diff --git a/pkg/internal/server/exts/auth.go b/pkg/internal/server/exts/auth.go index e105ac2..5a8244c 100644 --- a/pkg/internal/server/exts/auth.go +++ b/pkg/internal/server/exts/auth.go @@ -42,7 +42,7 @@ func DoAuthenticate(atk, rtk string) (acc *proto.UserInfo, accessTk string, refr ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - in := directory.GetServiceInstanceByType(directory.ServiceTypeAuthProvider) + in := directory.GetServiceInstanceByType(hyper.ServiceTypeAuthProvider) if in == nil { return } @@ -76,7 +76,7 @@ func CheckPermGranted(atk string, key string, val []byte) error { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - in := directory.GetServiceInstanceByType(directory.ServiceTypeAuthProvider) + in := directory.GetServiceInstanceByType(hyper.ServiceTypeAuthProvider) if in == nil { return fmt.Errorf("no auth provider found") }