#[non_exhaustive]pub struct CredentialSlot {
pub scope: Cow<'static, str>,
pub placement: CredentialPlacement,
pub replaces: Vec<Cow<'static, str>>,
pub required: bool,
}Expand description
Where an adapter takes its per-request credential from, and where it
puts it: the adapter’s side of a Credential.
Every HTTP adapter declares one and passes it to
HttpRequest::apply_options, which then:
- places the
Credential::api_keyaddressed toscopeasplacementsays, removing the configured credential and every header inreplaces; - adds the
Credential::headervalues addressed to the scope; - ignores credentials addressed to any other scope;
- refuses plain headers that would set a credential (see
HttpRequest::apply_options).
The scope names an account, not a wire format: it is independent of the
provider name and the namespaces, so telemetry identity never changes
with it. Bundled adapters default it to their provider name and publish
that default as DEFAULT_CREDENTIAL_SCOPE; their builders change it with
credential_scope. Two accounts of one provider in a fallback chain need
two scopes, and providers behind one gateway share one.
use allama_http::{CredentialPlacement, CredentialSlot};
// An API that takes its key in `x-nimbus-key`, and also accepts an
// `Authorization` header that a tenant key must replace.
let slot = CredentialSlot::new("nimbus", CredentialPlacement::Header("x-nimbus-key".into()))
.replaces("authorization");
assert_eq!(slot.header_name(), Some("x-nimbus-key"));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.scope: Cow<'static, str>The credential scope: credentials addressed to it are this adapter’s.
placement: CredentialPlacementWhere the scope’s Credential::api_key goes.
replaces: Vec<Cow<'static, str>>Configured authentication headers the credential replaces, besides
the placement’s own header: for example Entra ID’s authorization
on an endpoint whose keys go in api-key. Plain headers with these
names are refused, like the placement’s own header.
required: boolWhether every request must carry a credential for the scope: set
when the adapter has no configured credential (bring your own key).
A request without one fails with an authored
allama::Error::Configuration before anything is sent.
Implementations§
Source§impl CredentialSlot
impl CredentialSlot
Sourcepub fn new(
scope: impl Into<Cow<'static, str>>,
placement: CredentialPlacement,
) -> Self
pub fn new( scope: impl Into<Cow<'static, str>>, placement: CredentialPlacement, ) -> Self
A slot for scope, placed as placement, replacing nothing else and
not required.
Sourcepub fn replaces(self, name: impl Into<Cow<'static, str>>) -> Self
pub fn replaces(self, name: impl Into<Cow<'static, str>>) -> Self
Also replace the configured header name (see
replaces).