pub struct ApiKeyManager { /* private fields */ }Expand description
API key registry and validator.
Implementations§
Source§impl ApiKeyManager
impl ApiKeyManager
Sourcepub fn new(master_token: Option<&str>) -> Self
pub fn new(master_token: Option<&str>) -> Self
Create a new manager. If a master token is provided, it becomes the initial admin key.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether key management is enabled.
Sourcepub fn create_key(
&mut self,
name: &str,
token: &str,
role: KeyRole,
rate_limit: Option<u32>,
) -> bool
pub fn create_key( &mut self, name: &str, token: &str, role: KeyRole, rate_limit: Option<u32>, ) -> bool
Create a new API key. Returns true if created (false if token already exists).
Sourcepub fn validate(&mut self, token: &str) -> ValidationResult
pub fn validate(&mut self, token: &str) -> ValidationResult
Validate a token and record usage. Returns validation result.
Sourcepub fn peek(&self, token: &str) -> ValidationResult
pub fn peek(&self, token: &str) -> ValidationResult
Validate without recording usage (peek).
Sourcepub fn revoke(&mut self, token: &str) -> bool
pub fn revoke(&mut self, token: &str) -> bool
Revoke a key by token. Returns true if found and revoked.
Sourcepub fn revoke_by_name(&mut self, name: &str) -> bool
pub fn revoke_by_name(&mut self, name: &str) -> bool
Revoke a key by name. Returns true if found and revoked.
Sourcepub fn rotate(&mut self, old_token: &str, new_token: &str) -> Option<String>
pub fn rotate(&mut self, old_token: &str, new_token: &str) -> Option<String>
Rotate a key: revoke old token, create new one with same name/role. Returns the new token if successful.
Sourcepub fn list(&self) -> Vec<ApiKeySummary>
pub fn list(&self) -> Vec<ApiKeySummary>
List all keys (active and revoked). Tokens are masked.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active keys.
Sourcepub fn total_count(&self) -> usize
pub fn total_count(&self) -> usize
Total keys (including revoked).
Auto Trait Implementations§
impl Freeze for ApiKeyManager
impl RefUnwindSafe for ApiKeyManager
impl Send for ApiKeyManager
impl Sync for ApiKeyManager
impl Unpin for ApiKeyManager
impl UnsafeUnpin for ApiKeyManager
impl UnwindSafe for ApiKeyManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.