Class ApiKeyServerInterceptor
java.lang.Object
ai.pipestream.connector.intake.grpc.ApiKeyServerInterceptor
- All Implemented Interfaces:
io.grpc.ServerInterceptor
@ApplicationScoped
public class ApiKeyServerInterceptor
extends Object
implements io.grpc.ServerInterceptor
Captures the
x-api-key gRPC metadata header into the call Context.
This is the ONLY way credentials enter the intake gRPC surface —
request messages carry no api_key fields (security audit 2026-06-12; the
proto fields are reserved). Services read the key via
apiKey() on the thread handling the call.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final io.grpc.Metadata.Key<String> Header carrying the datasource API key. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringapiKey()The calling request's API key, or""when the header was absent.static <T> TcallWithApiKey(String apiKey, Callable<T> body) RunbodywithapiKeybound as the call credential.<ReqT,RespT>
io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT, RespT> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<ReqT, RespT> next)
-
Field Details
-
API_KEY_HEADER
Header carrying the datasource API key.
-
-
Constructor Details
-
ApiKeyServerInterceptor
public ApiKeyServerInterceptor()CDI.
-
-
Method Details
-
apiKey
The calling request's API key, or""when the header was absent. Valid on any thread carrying the call's gRPC Context (request handlers, stream observer callbacks, and the thread that opened a bidi stream).- Returns:
- the api key from
x-api-key, never null
-
callWithApiKey
RunbodywithapiKeybound as the call credential. For in-process callers that bypass the gRPC server (tests injecting the service bean directly, internal replays) — over the wire the interceptor binds it from thex-api-keyheader instead.- Type Parameters:
T- the body's result type- Parameters:
apiKey- the api key to bind for the duration ofbodybody- the work to run with the key bound- Returns:
body's result- Throws:
Exception- whateverbodythrows
-
interceptCall
public <ReqT,RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT, RespT> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<ReqT, RespT> next) - Specified by:
interceptCallin interfaceio.grpc.ServerInterceptor
-