pub struct OpenAiKeyTable { /* private fields */ }Expand description
Thread-safe table of gateway API keys indexed by secret hash.
Keys are stored in a SIM table behind a shared mutex so the same table can be cloned across route state; an anonymous capability ceiling applies to requests that present no recognized key.
Implementations§
Source§impl OpenAiKeyTable
impl OpenAiKeyTable
Sourcepub fn with_anonymous(anonymous: CapabilitySet) -> Result<Self>
pub fn with_anonymous(anonymous: CapabilitySet) -> Result<Self>
Returns an empty key table whose unauthenticated requests get anonymous.
Sourcepub fn add_secret(
&self,
secret: &str,
capabilities: CapabilitySet,
) -> Result<OpenAiGatewayKey>
pub fn add_secret( &self, secret: &str, capabilities: CapabilitySet, ) -> Result<OpenAiGatewayKey>
Hashes secret, registers it with capabilities, and returns the new key.
Sourcepub fn add_key(&self, key: OpenAiGatewayKey) -> Result<()>
pub fn add_key(&self, key: OpenAiGatewayKey) -> Result<()>
Inserts an already-constructed key, indexing it by its secret hash.
Sourcepub fn key_for_secret(&self, secret: &str) -> Result<Option<OpenAiGatewayKey>>
pub fn key_for_secret(&self, secret: &str) -> Result<Option<OpenAiGatewayKey>>
Returns the registered key matching secret, or None if unknown.
Sourcepub fn key_for_request(
&self,
request: &GatewayRequest,
) -> Result<Option<OpenAiGatewayKey>>
pub fn key_for_request( &self, request: &GatewayRequest, ) -> Result<Option<OpenAiGatewayKey>>
Returns the key authenticating request, reading its bearer/api-key header.
Sourcepub fn list_keys(&self) -> Result<Vec<OpenAiGatewayKey>>
pub fn list_keys(&self) -> Result<Vec<OpenAiGatewayKey>>
Returns all registered keys.
Sourcepub fn effective_capabilities(
&self,
request: &GatewayRequest,
) -> Result<CapabilitySet>
pub fn effective_capabilities( &self, request: &GatewayRequest, ) -> Result<CapabilitySet>
Returns the capabilities request may exercise.
The result is the key’s ceiling (or the anonymous ceiling when no key is presented), intersected with any capabilities the request body explicitly requests, so a request can only narrow – never widen – its key’s grant.
Sourcepub fn with_effective_capabilities<T>(
&self,
cx: &mut Cx,
request: &GatewayRequest,
f: impl FnOnce(&mut Cx) -> Result<T>,
) -> Result<T>
pub fn with_effective_capabilities<T>( &self, cx: &mut Cx, request: &GatewayRequest, f: impl FnOnce(&mut Cx) -> Result<T>, ) -> Result<T>
Runs f with cx scoped to the request’s effective capabilities.
Trait Implementations§
Source§impl Clone for OpenAiKeyTable
impl Clone for OpenAiKeyTable
Source§fn clone(&self) -> OpenAiKeyTable
fn clone(&self) -> OpenAiKeyTable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more