Skip to main content

OpenAiKeyTable

Struct OpenAiKeyTable 

Source
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

Source

pub fn new() -> Result<Self>

Returns an empty key table with no anonymous capabilities.

Source

pub fn with_anonymous(anonymous: CapabilitySet) -> Result<Self>

Returns an empty key table whose unauthenticated requests get anonymous.

Source

pub fn add_secret( &self, secret: &str, capabilities: CapabilitySet, ) -> Result<OpenAiGatewayKey>

Hashes secret, registers it with capabilities, and returns the new key.

Source

pub fn add_key(&self, key: OpenAiGatewayKey) -> Result<()>

Inserts an already-constructed key, indexing it by its secret hash.

Source

pub fn key_for_secret(&self, secret: &str) -> Result<Option<OpenAiGatewayKey>>

Returns the registered key matching secret, or None if unknown.

Source

pub fn key_for_request( &self, request: &GatewayRequest, ) -> Result<Option<OpenAiGatewayKey>>

Returns the key authenticating request, reading its bearer/api-key header.

Source

pub fn list_keys(&self) -> Result<Vec<OpenAiGatewayKey>>

Returns all registered keys.

Source

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.

Source

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

Source§

fn clone(&self) -> OpenAiKeyTable

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for OpenAiKeyTable

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.