🚚 Move the service type into hyper sdk

This commit is contained in:
LittleSheep 2024-07-14 20:56:06 +08:00
parent 466b240e95
commit 31e73c438e
6 changed files with 23 additions and 14 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -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
}

8
pkg/hyper/const.go Normal file
View File

@ -0,0 +1,8 @@
package hyper
const (
ServiceTypeAuthProvider = "auth"
ServiceTypeFileProvider = "files"
ServiceTypeInteractiveProvider = "interactive"
ServiceTypeMessagingProvider = "messaging"
)

View File

@ -4,11 +4,6 @@ import (
"sync"
)
const (
ServiceTypeAuthProvider = "passport"
ServiceTypeFileProvider = "paperclip"
)
var serviceDirectory sync.Map
func GetServiceInstance(id string) *ServiceInstance {

View File

@ -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()

View File

@ -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")
}