✨ Third client query grpc endpoint
⬆️ Upgrade protobuf
This commit is contained in:
@ -20,6 +20,7 @@ type App struct {
|
||||
proto.UnimplementedRealmServiceServer
|
||||
proto.UnimplementedAuditServiceServer
|
||||
proto.UnimplementedNotifyServiceServer
|
||||
proto.UnimplementedThirdClientServiceServer
|
||||
health.UnimplementedHealthServer
|
||||
|
||||
srv *grpc.Server
|
||||
@ -36,6 +37,7 @@ func NewServer() *App {
|
||||
proto.RegisterNotifyServiceServer(server.srv, server)
|
||||
proto.RegisterRealmServiceServer(server.srv, server)
|
||||
proto.RegisterAuditServiceServer(server.srv, server)
|
||||
proto.RegisterThirdClientServiceServer(server.srv, server)
|
||||
health.RegisterHealthServer(server.srv, server)
|
||||
|
||||
reflection.Register(server.srv)
|
||||
|
31
pkg/internal/grpc/thrid_client.go
Normal file
31
pkg/internal/grpc/thrid_client.go
Normal file
@ -0,0 +1,31 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
|
||||
"git.solsynth.dev/hypernet/passport/pkg/proto"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (v *App) GetThirdClient(ctx context.Context, request *proto.GetThirdClientRequest) (*proto.GetThirdClientResponse, error) {
|
||||
var client models.ThirdClient
|
||||
if err := database.C.Where("id = ?", request.ClientId).First(&client).Error; err != nil {
|
||||
return nil, status.Errorf(codes.NotFound, "requested client with id %d was not found", request.ClientId)
|
||||
}
|
||||
|
||||
if request.Secret != nil {
|
||||
if client.Secret != request.GetSecret() {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "invalid secret")
|
||||
}
|
||||
}
|
||||
|
||||
return &proto.GetThirdClientResponse{
|
||||
Info: &proto.ThirdClientInfo{
|
||||
Id: uint64(client.ID),
|
||||
Name: client.Name,
|
||||
Description: client.Description,
|
||||
},
|
||||
}, nil
|
||||
}
|
Reference in New Issue
Block a user