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:

ClientIdentityEntry | None

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.