/
check.go
85 lines (70 loc) · 2.58 KB
/
check.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package auth
import (
"context"
log "github.com/sirupsen/logrus"
"google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
envoyAuthV2 "github.com/envoyproxy/go-control-plane/envoy/service/auth/v2"
envoyAuthV3 "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
)
// ##################### V3 Auth GRPC #################### //
type RPCv2 struct {
envoyAuthV2.UnimplementedAuthorizationServer
}
func (rpc *RPCv2) Check(ctx context.Context, r *envoyAuthV2.CheckRequest) (*envoyAuthV2.CheckResponse, error) {
if attr := r.GetAttributes(); attr != nil {
log.Debugf("request attributes.ContextExtension: %v", attr.GetContextExtensions())
log.Debugf("request attributes.Destination: %v", attr.GetDestination())
log.Debugf("request attributes.MetadataContext: %v", attr.GetMetadataContext())
log.Debugf("request attributes.Request: %v", attr.GetRequest())
log.Debugf("request attributes.Source: %v", attr.GetSource())
}
return &envoyAuthV2.CheckResponse{
HttpResponse: &envoyAuthV2.CheckResponse_OkResponse{
OkResponse: &envoyAuthV2.OkHttpResponse{},
},
Status: &status.Status{
Code: int32(codes.OK),
Message: "authorized",
},
}, nil
}
// Register wires up the RPC to the server
func (rpc *RPCv2) Register(server *grpc.Server) {
envoyAuthV2.RegisterAuthorizationServer(server, rpc)
}
// NewRPCv2 returns a new initialized RPC object.
func NewRPCv2() RPCInterface {
return &RPCv2{}
}
// ##################### V3 Auth GRPC #################### //
type RPCv3 struct {
envoyAuthV3.UnimplementedAuthorizationServer
}
func (rpc *RPCv3) Check(ctx context.Context, r *envoyAuthV3.CheckRequest) (*envoyAuthV3.CheckResponse, error) {
if attr := r.GetAttributes(); attr != nil {
log.Debugf("request attributes.ContextExtension: %v", attr.GetContextExtensions())
log.Debugf("request attributes.Destination: %v", attr.GetDestination())
log.Debugf("request attributes.MetadataContext: %v", attr.GetMetadataContext())
log.Debugf("request attributes.Request: %v", attr.GetRequest())
log.Debugf("request attributes.Source: %v", attr.GetSource())
}
return &envoyAuthV3.CheckResponse{
HttpResponse: &envoyAuthV3.CheckResponse_OkResponse{
OkResponse: &envoyAuthV3.OkHttpResponse{},
},
Status: &status.Status{
Code: int32(codes.OK),
Message: "authorized",
},
}, nil
}
// Register wires up the RPC to the server
func (rpc *RPCv3) Register(server *grpc.Server) {
envoyAuthV3.RegisterAuthorizationServer(server, rpc)
}
// NewRPCv3 returns a new initialized RPC object.
func NewRPCv3() RPCInterface {
return &RPCv3{}
}