-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
grpc.go
32 lines (27 loc) · 1.05 KB
/
grpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package shared
import (
"github.com/grepplabs/kafka-proxy/pkg/apis"
"github.com/grepplabs/kafka-proxy/plugin/token-info/proto"
"github.com/hashicorp/go-plugin"
"golang.org/x/net/context"
)
// GRPCClient is an implementation of TokenInfo that talks over gRPC.
type GRPCClient struct {
broker *plugin.GRPCBroker
client proto.TokenInfoClient
}
func (m *GRPCClient) VerifyToken(ctx context.Context, request apis.VerifyRequest) (apis.VerifyResponse, error) {
resp, err := m.client.VerifyToken(ctx, &proto.VerifyRequest{Token: request.Token, Params: request.Params})
return apis.VerifyResponse{Success: resp.Success, Status: resp.Status}, err
}
// Here is the gRPC server that GRPCClient talks to.
type GRPCServer struct {
broker *plugin.GRPCBroker
Impl apis.TokenInfo
}
func (m *GRPCServer) VerifyToken(
ctx context.Context,
req *proto.VerifyRequest) (*proto.VerifyResponse, error) {
resp, err := m.Impl.VerifyToken(ctx, apis.VerifyRequest{Token: req.Token, Params: req.Params})
return &proto.VerifyResponse{Success: resp.Success, Status: resp.Status}, err
}