summaryrefslogtreecommitdiff
path: root/vendor/github.com/authzed/grpcutil/reflection.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/authzed/grpcutil/reflection.go')
-rw-r--r--vendor/github.com/authzed/grpcutil/reflection.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/vendor/github.com/authzed/grpcutil/reflection.go b/vendor/github.com/authzed/grpcutil/reflection.go
new file mode 100644
index 0000000..092b568
--- /dev/null
+++ b/vendor/github.com/authzed/grpcutil/reflection.go
@@ -0,0 +1,51 @@
+package grpcutil
+
+import (
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/reflection"
+ rpbv1 "google.golang.org/grpc/reflection/grpc_reflection_v1"
+ "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
+)
+
+// NewAuthlessReflectionInterceptor creates a proxy GRPCServer which automatically converts
+// ServerReflectionServer instances to ones that skip grpc auth middleware.
+//
+// change:
+// reflection.Register(srv)
+// to:
+// reflection.Register(grpcutil.NewAuthlessReflectionInterceptor(srv))
+func NewAuthlessReflectionInterceptor(srv reflection.GRPCServer) reflection.GRPCServer {
+ return interceptingRegistrar{srv}
+}
+
+type interceptingRegistrar struct {
+ delegate reflection.GRPCServer
+}
+
+func (ir interceptingRegistrar) GetServiceInfo() map[string]grpc.ServiceInfo {
+ return ir.delegate.GetServiceInfo()
+}
+
+func (ir interceptingRegistrar) RegisterService(desc *grpc.ServiceDesc, impl interface{}) {
+ reflectionSrvv1, ok := impl.(rpbv1.ServerReflectionServer)
+ if ok {
+ ir.delegate.RegisterService(desc, &authlessReflectionV1{ServerReflectionServer: reflectionSrvv1})
+ }
+
+ reflectionSrvv1alpha, ok := impl.(grpc_reflection_v1alpha.ServerReflectionServer)
+ if ok {
+ ir.delegate.RegisterService(desc, &authlessReflectionV1Alpha{ServerReflectionServer: reflectionSrvv1alpha})
+ }
+}
+
+type authlessReflectionV1 struct {
+ IgnoreAuthMixin
+
+ rpbv1.ServerReflectionServer
+}
+
+type authlessReflectionV1Alpha struct {
+ IgnoreAuthMixin
+
+ grpc_reflection_v1alpha.ServerReflectionServer
+}