buildgrid.client.channel module

buildgrid.client.channel.setup_channel(remote_url: str, auth_token: Optional[str] = None, client_key: Optional[str] = None, client_cert: Optional[str] = None, server_cert: Optional[str] = None, action_id: Optional[str] = None, tool_invocation_id: Optional[str] = None, correlated_invocations_id: Optional[str] = None, asynchronous: bool = False)

Creates a new gRPC client communication chanel.

If remote_url does not point to a socket and does not specify a port number, defaults 50051.

Parameters
  • remote_url (str) – URL for the remote, including protocol and, if not a Unix domain socket, a port.

  • auth_token (str) – Authorization token file path.

  • server_cert (str) – TLS certificate chain file path.

  • client_key (str) – TLS root certificate file path.

  • client_cert (str) – TLS private key file path.

  • action_id (str) – Action identifier to which the request belongs to.

  • tool_invocation_id (str) – Identifier for a related group of Actions.

  • correlated_invocations_id (str) – Identifier that ties invocations together.

Returns

Client Channel to be used in order to access the server

at remote_url.

Return type

Channel

Raises

InvalidArgumentError – On any input parsing error.

class buildgrid.client.channel.RequestMetadataInterceptorBase(action_id: Optional[str] = None, tool_invocation_id: Optional[str] = None, correlated_invocations_id: Optional[str] = None)

Bases: object

class buildgrid.client.channel.RequestMetadataInterceptor(action_id: Optional[str] = None, tool_invocation_id: Optional[str] = None, correlated_invocations_id: Optional[str] = None)

Bases: buildgrid.client.channel.RequestMetadataInterceptorBase, grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamClientInterceptor, grpc.StreamUnaryClientInterceptor, grpc.StreamStreamClientInterceptor

intercept_unary_unary(continuation, client_call_details, request)

Intercepts a unary-unary invocation asynchronously.

Parameters
  • continuation – A function that proceeds with the invocation by executing the next interceptor in chain or invoking the actual RPC on the underlying Channel. It is the interceptor’s responsibility to call it if it decides to move the RPC forward. The interceptor can use response_future = continuation(client_call_details, request) to continue with the RPC. continuation returns an object that is both a Call for the RPC and a Future. In the event of RPC completion, the return Call-Future’s result value will be the response message of the RPC. Should the event terminate with non-OK status, the returned Call-Future’s exception value will be an RpcError.

  • client_call_details – A ClientCallDetails object describing the outgoing RPC.

  • request – The request value for the RPC.

Returns

An object that is both a Call for the RPC and a Future. In the event of RPC completion, the return Call-Future’s result value will be the response message of the RPC. Should the event terminate with non-OK status, the returned Call-Future’s exception value will be an RpcError.

intercept_unary_stream(continuation, client_call_details, request)

Intercepts a unary-stream invocation.

Parameters
  • continuation – A function that proceeds with the invocation by executing the next interceptor in chain or invoking the actual RPC on the underlying Channel. It is the interceptor’s responsibility to call it if it decides to move the RPC forward. The interceptor can use response_iterator = continuation(client_call_details, request) to continue with the RPC. continuation returns an object that is both a Call for the RPC and an iterator for response values. Drawing response values from the returned Call-iterator may raise RpcError indicating termination of the RPC with non-OK status.

  • client_call_details – A ClientCallDetails object describing the outgoing RPC.

  • request – The request value for the RPC.

Returns

An object that is both a Call for the RPC and an iterator of response values. Drawing response values from the returned Call-iterator may raise RpcError indicating termination of the RPC with non-OK status. This object should also fulfill the Future interface, though it may not.

intercept_stream_unary(continuation, client_call_details, request_iterator)

Intercepts a stream-unary invocation asynchronously.

Parameters
  • continuation – A function that proceeds with the invocation by executing the next interceptor in chain or invoking the actual RPC on the underlying Channel. It is the interceptor’s responsibility to call it if it decides to move the RPC forward. The interceptor can use response_future = continuation(client_call_details, request_iterator) to continue with the RPC. continuation returns an object that is both a Call for the RPC and a Future. In the event of RPC completion, the return Call-Future’s result value will be the response message of the RPC. Should the event terminate with non-OK status, the returned Call-Future’s exception value will be an RpcError.

  • client_call_details – A ClientCallDetails object describing the outgoing RPC.

  • request_iterator – An iterator that yields request values for the RPC.

Returns

An object that is both a Call for the RPC and a Future. In the event of RPC completion, the return Call-Future’s result value will be the response message of the RPC. Should the event terminate with non-OK status, the returned Call-Future’s exception value will be an RpcError.

intercept_stream_stream(continuation, client_call_details, request_iterator)

Intercepts a stream-stream invocation.

Parameters
  • continuation – A function that proceeds with the invocation by executing the next interceptor in chain or invoking the actual RPC on the underlying Channel. It is the interceptor’s responsibility to call it if it decides to move the RPC forward. The interceptor can use response_iterator = continuation(client_call_details, request_iterator) to continue with the RPC. continuation returns an object that is both a Call for the RPC and an iterator for response values. Drawing response values from the returned Call-iterator may raise RpcError indicating termination of the RPC with non-OK status.

  • client_call_details – A ClientCallDetails object describing the outgoing RPC.

  • request_iterator – An iterator that yields request values for the RPC.

Returns

An object that is both a Call for the RPC and an iterator of response values. Drawing response values from the returned Call-iterator may raise RpcError indicating termination of the RPC with non-OK status. This object should also fulfill the Future interface, though it may not.

class buildgrid.client.channel.AsyncRequestMetadataInterceptor(action_id: Optional[str] = None, tool_invocation_id: Optional[str] = None, correlated_invocations_id: Optional[str] = None)

Bases: buildgrid.client.channel.RequestMetadataInterceptorBase, grpc.aio._interceptor.UnaryUnaryClientInterceptor, grpc.aio._interceptor.UnaryStreamClientInterceptor, grpc.aio._interceptor.StreamUnaryClientInterceptor, grpc.aio._interceptor.StreamStreamClientInterceptor

async intercept_unary_unary(continuation, client_call_details, request)

Intercepts a unary-unary invocation asynchronously.

Parameters
  • continuation – A coroutine that proceeds with the invocation by executing the next interceptor in the chain or invoking the actual RPC on the underlying Channel. It is the interceptor’s responsibility to call it if it decides to move the RPC forward. The interceptor can use call = await continuation(client_call_details, request) to continue with the RPC. continuation returns the call to the RPC.

  • client_call_details – A ClientCallDetails object describing the outgoing RPC.

  • request – The request value for the RPC.

Returns

An object with the RPC response.

Raises
  • AioRpcError – Indicating that the RPC terminated with non-OK status.

  • asyncio.CancelledError – Indicating that the RPC was canceled.

async intercept_unary_stream(continuation, client_call_details, request)

Intercepts a unary-stream invocation asynchronously.

The function could return the call object or an asynchronous iterator, in case of being an asyncrhonous iterator this will become the source of the reads done by the caller.

Parameters
  • continuation – A coroutine that proceeds with the invocation by executing the next interceptor in the chain or invoking the actual RPC on the underlying Channel. It is the interceptor’s responsibility to call it if it decides to move the RPC forward. The interceptor can use call = await continuation(client_call_details, request) to continue with the RPC. continuation returns the call to the RPC.

  • client_call_details – A ClientCallDetails object describing the outgoing RPC.

  • request – The request value for the RPC.

Returns

The RPC Call or an asynchronous iterator.

Raises
  • AioRpcError – Indicating that the RPC terminated with non-OK status.

  • asyncio.CancelledError – Indicating that the RPC was canceled.

async intercept_stream_unary(continuation, client_call_details, request_iterator)

Intercepts a stream-unary invocation asynchronously.

Within the interceptor the usage of the call methods like write or even awaiting the call should be done carefully, since the caller could be expecting an untouched call, for example for start writing messages to it.

Parameters
  • continuation – A coroutine that proceeds with the invocation by executing the next interceptor in the chain or invoking the actual RPC on the underlying Channel. It is the interceptor’s responsibility to call it if it decides to move the RPC forward. The interceptor can use call = await continuation(client_call_details, request_iterator) to continue with the RPC. continuation returns the call to the RPC.

  • client_call_details – A ClientCallDetails object describing the outgoing RPC.

  • request_iterator – The request iterator that will produce requests for the RPC.

Returns

The RPC Call.

Raises
  • AioRpcError – Indicating that the RPC terminated with non-OK status.

  • asyncio.CancelledError – Indicating that the RPC was canceled.

async intercept_stream_stream(continuation, client_call_details, request_iterator)

Intercepts a stream-stream invocation asynchronously.

Within the interceptor the usage of the call methods like write or even awaiting the call should be done carefully, since the caller could be expecting an untouched call, for example for start writing messages to it.

The function could return the call object or an asynchronous iterator, in case of being an asyncrhonous iterator this will become the source of the reads done by the caller.

Parameters
  • continuation – A coroutine that proceeds with the invocation by executing the next interceptor in the chain or invoking the actual RPC on the underlying Channel. It is the interceptor’s responsibility to call it if it decides to move the RPC forward. The interceptor can use call = await continuation(client_call_details, request_iterator) to continue with the RPC. continuation returns the call to the RPC.

  • client_call_details – A ClientCallDetails object describing the outgoing RPC.

  • request_iterator – The request iterator that will produce requests for the RPC.

Returns

The RPC Call or an asynchronous iterator.

Raises
  • AioRpcError – Indicating that the RPC terminated with non-OK status.

  • asyncio.CancelledError – Indicating that the RPC was canceled.