judgevet.adapters.outbound.gateway

Status: draft.

judgevet.adapters.outbound.gateway

Configure explicit gateway credentials and metadata without implicit forwarding.

Apigee documents configurable key fields at https://docs.cloud.google.com/apigee/docs/api-platform/reference/policies/verify-api-key-policy. Direct defaults retain TypeSafe authentication: https://docs.typesafe.ai/api. Trace fields are caller text, not automatic W3C tracing or baggage collection. See https://www.w3.org/TR/trace-context/ and https://www.w3.org/TR/baggage/.

Examples:

from judgevet.adapters.outbound.gateway import GatewayConfig, RequestMetadata

gateway = GatewayConfig(auth_header="x-apikey", auth_scheme="")
metadata = RequestMetadata(headers={"Example-Tenant": "synthetic"})
assert gateway.request_headers(metadata)["example-tenant"] == "synthetic"
See Also

GatewayConfig dataclass

Select authentication, default metadata and deliberate correlation.

Custom authentication replaces Authorization; the caller supplies the gateway credential through the adapter's existing api_key argument.

Attributes:

Name Type Description
auth_header str

Credential field, default Authorization.

auth_scheme str

Token prefix, default Bearer; empty sends a bare key.

headers Mapping[str, str] | None

Immutable defaults, omitted from repr.

request_id_header str | None

Optional field for the scoped request ID.

Examples:

gateway = GatewayConfig(auth_header="x-apikey", auth_scheme="")
assert gateway.authentication("dummy")["x-apikey"] == "dummy"

__post_init__()

Validate configuration before the adapter acquires a client.

Raises:

Type Description
ValueError

If names, scheme, fields or correlation conflict.

authentication(key)

Build the single credential field and JSON content type.

Parameters:

Name Type Description Default
key str

Credential already resolved by the caller.

required

Returns:

Type Description
dict[str, str]

Authentication and payload fields for the owned client.

Raises:

Type Description
ValueError

If the credential contains unsafe field content.

request_headers(metadata=None)

Snapshot merged metadata and the opted-in scoped ID for one logical call.

Parameters:

Name Type Description Default
metadata RequestMetadata | None

Per-call fields, which replace defaults case-insensitively.

None

Returns:

Type Description
dict[str, str]

Fresh validated request fields reused across retry attempts.

Raises:

Type Description
ValueError

If merged fields conflict or exceed local limits.

GatewayOptions

Bases: TypedDict

Type the optional adapter extension without changing existing parameters.

Attributes:

Name Type Description
gateway GatewayConfig | None

Explicit configuration or direct defaults.

RequestMetadata dataclass

Snapshot explicit per-call metadata with case-insensitive field names.

Attributes:

Name Type Description
headers Mapping[str, str]

Immutable string fields, omitted from repr.

Examples:

metadata = RequestMetadata(headers={"Example-Tenant": "synthetic"})
assert metadata.headers["example-tenant"] == "synthetic"

__post_init__()

Validate and copy fields before a call can transmit them.

Raises:

Type Description
ValueError

If fields violate the metadata contract.

configured_gateway(options)

Resolve typed constructor extensions and reject unknown runtime keywords.

Parameters:

Name Type Description Default
options GatewayOptions

Keyword extensions accepted by either HTTP adapter.

required

Returns:

Type Description
GatewayConfig

Explicit gateway or the unchanged direct default.

Raises:

Type Description
TypeError

If an untyped caller supplies an unknown option.