peridot/vendor/github.com/authzed/grpcutil/reflection.go
Mustafa Gezen ad0f7a5305
Major upgrades
Upgrade to Go 1.20.5, Hydra v2 SDK, rules-go v0.44.2 (with proper resolves), protobuf v25.3 and mass upgrade of Go dependencies.
2024-03-17 08:06:08 +01:00

52 lines
1.5 KiB
Go

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
}