buildgrid.server.metadata module

buildgrid.server.metadata.metadata_list() Tuple[Tuple[str, str | bytes], ...]

Helper function to construct the metadata list from the ContextVar.

buildgrid.server.metadata.printable_request_metadata(metadata_entries: Any) str

Given a metadata object, return a human-readable representation of its RequestMetadata entry.

Parameters:

metadata_entries – tuple of entries obtained from a gRPC context with, for example, context.invocation_metadata().

Returns:

A string with the metadata contents.

buildgrid.server.metadata.extract_request_metadata_dict(metadata_entries: Any) Dict[str, str]
buildgrid.server.metadata.extract_request_metadata(metadata_entries: Any) RequestMetadata

Given a list of string tuples, extract the RequestMetadata header values if they are present. If they were not provided, returns an empty message.

Parameters:

metadata_entries – tuple of entries obtained from a gRPC context with, for example, context.invocation_metadata().

Returns:

A RequestMetadata proto. If the metadata is not defined in the request, the message will be empty.

buildgrid.server.metadata.request_metadata_to_string(request_metadata: RequestMetadata) str
buildgrid.server.metadata.request_metadata_to_dict(request_metadata: RequestMetadata) Dict[str, str]
buildgrid.server.metadata.extract_client_identity_dict(instance: str, invocation_metadata: Iterable[Tuple[str, Any]]) Dict[str, Any]
buildgrid.server.metadata.extract_client_identity(instance: str, invocation_metadata: Iterable[Tuple[str, Any]]) ClientIdentityEntry | None

Checks for the existence of the client identity in the ClientIdentity context var. If the context var is not set then extracts the ClientIdentity from gRPC metadata

Parameters:
  • instance (str) – the instance where the request was invoked from

  • invocation_metadata (List[Tuple[str, str]]) – grpc metadata

Returns:

identity of the client if exists

Return type:

Optional[ClientIdentityEntry]

buildgrid.server.metadata.printable_client_identity(instance: str, invocation_metadata: Iterable[Tuple[str, Any]]) str

Given a metadata object, return a human-readable representation of its ClientIdentity entry.

Parameters:
  • instance – REAPI instance name

  • invocation_metadata – tuple of entries obtained from a gRPC context with, for example, context.invocation_metadata().

Returns:

A string with the ClientIdentity contents.

buildgrid.server.metadata.extract_trailing_client_identity(metadata_entries: Metadata) ClientIdentity

Given a list of string tuples, extract the ClientIdentity header values if they are present. If they were not provided, returns an empty message.

Parameters:

metadata_entries – Sequence of gRPC trailing metadata headers.

Returns:

A ClientIdentity proto. If the metadata is not defined in the request, the message will be empty.