MCPcopy
hub / github.com/grpc/grpc-go / callCredsValidatingServerInterceptor

Function callCredsValidatingServerInterceptor

balancer/rls/control_channel_test.go:194–209  ·  balancer/rls/control_channel_test.go::callCredsValidatingServerInterceptor

Unary server interceptor which validates if the RPC contains call credentials which match `perRPCCredsData

(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler)

Source from the content-addressed store, hash-verified

192// Unary server interceptor which validates if the RPC contains call credentials
193// which match `perRPCCredsData
194func callCredsValidatingServerInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
195 md, ok := metadata.FromIncomingContext(ctx)
196 if !ok {
197 return nil, status.Error(codes.PermissionDenied, "didn't find metadata in context")
198 }
199 for k, want := range perRPCCredsData {
200 got, ok := md[k]
201 if !ok {
202 return ctx, status.Errorf(codes.PermissionDenied, "didn't find call creds key %v in context", k)
203 }
204 if got[0] != want {
205 return ctx, status.Errorf(codes.PermissionDenied, "for key %v, got value %v, want %v", k, got, want)
206 }
207 }
208 return handler(ctx, req)
209}
210
211// makeTLSCreds is a test helper which creates a TLS based transport credentials
212// from files specified in the arguments.

Callers

nothing calls this directly

Calls 3

FromIncomingContextFunction · 0.92
ErrorFunction · 0.92
ErrorfFunction · 0.92

Tested by

no test coverage detected