pub struct ApiKeyStore { /* private fields */ }Expand description
Thread-safe token store, keyed by opaque bearer-token string.
Implementations§
Source§impl ApiKeyStore
impl ApiKeyStore
Sourcepub fn new(config: AuthConfig) -> Self
pub fn new(config: AuthConfig) -> Self
Create a new token store.
Sourcepub fn add_key(&self, key: impl Into<String>)
pub fn add_key(&self, key: impl Into<String>)
Add a legacy full-control API key.
Backward-compatibility path (spec §4): a bare key with no declared
capabilities maps to a full-control token holding the wildcard, so any
existing --api-key / --require-auth consumer is unaffected and can
never trigger a 403.
Sourcepub fn add_token(&self, key: impl Into<String>, record: TokenRecord)
pub fn add_token(&self, key: impl Into<String>, record: TokenRecord)
Register a token string with an explicit capability record.
Sourcepub fn add_key_with_capabilities(
&self,
key: impl Into<String>,
capabilities: CapabilitySet,
label: impl Into<String>,
)
pub fn add_key_with_capabilities( &self, key: impl Into<String>, capabilities: CapabilitySet, label: impl Into<String>, )
Register a token with the given capabilities and label.
Sourcepub fn remove_key(&self, key: &str) -> bool
pub fn remove_key(&self, key: &str) -> bool
Remove a token.
Sourcepub fn capabilities(&self, key: &str) -> Option<CapabilitySet>
pub fn capabilities(&self, key: &str) -> Option<CapabilitySet>
Look up the capabilities a token grants, if it is registered.
This is the store surface the scope-aware middleware consumes
(spec §5 step 2): token → TokenRecord → capability check.
Sourcepub fn identity(&self, key: &str) -> Option<Identity>
pub fn identity(&self, key: &str) -> Option<Identity>
Identify a token for the audit trail, without revealing it.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if authentication is enabled.
Sourcepub fn extract_key(&self, header_value: &str) -> Option<String>
pub fn extract_key(&self, header_value: &str) -> Option<String>
Extract API key from authorization header.