pub struct ApiKeyManager { /* private fields */ }Expand description
API key manager
Implementations§
Source§impl ApiKeyManager
impl ApiKeyManager
Sourcepub fn new(config: ApiKeyConfig) -> Self
pub fn new(config: ApiKeyConfig) -> Self
Create a new API key manager
Sourcepub fn generate_key(
&self,
identity: Identity,
name: String,
scopes: Vec<String>,
expires_in: Option<Duration>,
rate_limit: Option<u32>,
) -> Result<(ApiKey, String), ApiKeyError>
pub fn generate_key( &self, identity: Identity, name: String, scopes: Vec<String>, expires_in: Option<Duration>, rate_limit: Option<u32>, ) -> Result<(ApiKey, String), ApiKeyError>
Generate a new API key
Sourcepub fn validate_to_identity(&self, key: &str) -> Result<Identity, ApiKeyError>
pub fn validate_to_identity(&self, key: &str) -> Result<Identity, ApiKeyError>
Validate key and convert to identity
Sourcepub fn validate_with_scopes(
&self,
key: &str,
required_scopes: &[&str],
) -> Result<ApiKey, ApiKeyError>
pub fn validate_with_scopes( &self, key: &str, required_scopes: &[&str], ) -> Result<ApiKey, ApiKeyError>
Validate key with required scopes
Sourcepub fn validate_with_ip(
&self,
key: &str,
client_ip: &IpAddr,
) -> Result<ApiKey, ApiKeyError>
pub fn validate_with_ip( &self, key: &str, client_ip: &IpAddr, ) -> Result<ApiKey, ApiKeyError>
Validate key with IP check
Sourcepub fn list_by_user(&self, user_id: &str) -> Vec<ApiKey>
pub fn list_by_user(&self, user_id: &str) -> Vec<ApiKey>
List all API keys for a user
Sourcepub fn list_active(&self) -> Vec<ApiKey>
pub fn list_active(&self) -> Vec<ApiKey>
List all active API keys
Sourcepub fn update_metadata(
&self,
key_id: &str,
metadata: HashMap<String, String>,
) -> Result<(), ApiKeyError>
pub fn update_metadata( &self, key_id: &str, metadata: HashMap<String, String>, ) -> Result<(), ApiKeyError>
Update API key metadata
Sourcepub fn update_scopes(
&self,
key_id: &str,
scopes: Vec<String>,
) -> Result<(), ApiKeyError>
pub fn update_scopes( &self, key_id: &str, scopes: Vec<String>, ) -> Result<(), ApiKeyError>
Update API key scopes
Sourcepub fn update_allowed_ips(
&self,
key_id: &str,
ips: Vec<IpAddr>,
) -> Result<(), ApiKeyError>
pub fn update_allowed_ips( &self, key_id: &str, ips: Vec<IpAddr>, ) -> Result<(), ApiKeyError>
Update API key allowed IPs
Sourcepub fn rotate(&self, key_id: &str) -> Result<String, ApiKeyError>
pub fn rotate(&self, key_id: &str) -> Result<String, ApiKeyError>
Rotate an API key (generate new key value, same ID)
Sourcepub fn stats(&self) -> ApiKeyStats
pub fn stats(&self) -> ApiKeyStats
Get key statistics
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Cleanup expired keys
Sourcepub fn key_prefix(&self) -> &str
pub fn key_prefix(&self) -> &str
Get the key prefix
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 more