peridot/vendor/github.com/authzed/grpcutil/reflection.go

52 lines
1.5 KiB
Go
Raw Normal View History

2022-07-07 20:11:50 +00:00
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"
2022-07-07 20:11:50 +00:00
)
// NewAuthlessReflectionInterceptor creates a proxy GRPCServer which automatically converts
// ServerReflectionServer instances to ones that skip grpc auth middleware.
2022-07-07 20:11:50 +00:00
//
// 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
2022-07-07 20:11:50 +00:00
}
type authlessReflectionV1Alpha struct {
2022-07-07 20:11:50 +00:00
IgnoreAuthMixin
grpc_reflection_v1alpha.ServerReflectionServer
2022-07-07 20:11:50 +00:00
}