pub struct ApiKeyService { /* private fields */ }Expand description
API key service for database operations
Implementations§
Source§impl ApiKeyService
impl ApiKeyService
pub fn new(max_keys_per_user: usize) -> Self
Sourcepub fn generate_key() -> String
pub fn generate_key() -> String
Generate a new API key
Sourcepub async fn create_key(
&self,
user_id: Uuid,
name: String,
scopes: Vec<ApiKeyScope>,
expires_at: Option<DateTime<Utc>>,
rate_limit: Option<u32>,
) -> Result<ApiKeyCreated, ApiKeyError>
pub async fn create_key( &self, user_id: Uuid, name: String, scopes: Vec<ApiKeyScope>, expires_at: Option<DateTime<Utc>>, rate_limit: Option<u32>, ) -> Result<ApiKeyCreated, ApiKeyError>
Create a new API key
Sourcepub async fn list_keys(&self, user_id: Uuid) -> Result<Vec<ApiKey>, ApiKeyError>
pub async fn list_keys(&self, user_id: Uuid) -> Result<Vec<ApiKey>, ApiKeyError>
List all keys for a user (without secrets)
Sourcepub async fn revoke_key(
&self,
user_id: Uuid,
key_id: Uuid,
) -> Result<(), ApiKeyError>
pub async fn revoke_key( &self, user_id: Uuid, key_id: Uuid, ) -> Result<(), ApiKeyError>
Revoke an API key
Sourcepub async fn rotate_key(
&self,
user_id: Uuid,
key_id: Uuid,
) -> Result<ApiKeyCreated, ApiKeyError>
pub async fn rotate_key( &self, user_id: Uuid, key_id: Uuid, ) -> Result<ApiKeyCreated, ApiKeyError>
Rotate an API key (revoke old, create new with same scopes)
Sourcepub async fn validate_key(&self, raw_key: &str) -> Result<ApiKey, ApiKeyError>
pub async fn validate_key(&self, raw_key: &str) -> Result<ApiKey, ApiKeyError>
Validate an API key and return its metadata
Sourcepub async fn record_usage(&self, key_id: Uuid) -> Result<(), ApiKeyError>
pub async fn record_usage(&self, key_id: Uuid) -> Result<(), ApiKeyError>
Record key usage
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiKeyService
impl RefUnwindSafe for ApiKeyService
impl Send for ApiKeyService
impl Sync for ApiKeyService
impl Unpin for ApiKeyService
impl UnwindSafe for ApiKeyService
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