pub struct ApiKeyManager<'a> { /* private fields */ }Expand description
API key manager
Implementations§
Source§impl<'a> ApiKeyManager<'a>
impl<'a> ApiKeyManager<'a>
Sourcepub fn new(conn: &'a Connection) -> Self
pub fn new(conn: &'a Connection) -> Self
Create a new API key manager
Sourcepub fn create_api_key(
&self,
user_id: &UserId,
name: &str,
permissions: PermissionSet,
namespace: Option<String>,
expires_in_days: Option<i64>,
) -> Result<(ApiKey, String)>
pub fn create_api_key( &self, user_id: &UserId, name: &str, permissions: PermissionSet, namespace: Option<String>, expires_in_days: Option<i64>, ) -> Result<(ApiKey, String)>
Generate a new API key Returns (ApiKey, raw_key) - raw_key should only be shown once
Sourcepub fn validate_key(&self, raw_key: &str) -> Result<Option<TokenClaims>>
pub fn validate_key(&self, raw_key: &str) -> Result<Option<TokenClaims>>
Validate an API key and return claims
Sourcepub fn get_key(&self, id: &str) -> Result<Option<ApiKey>>
pub fn get_key(&self, id: &str) -> Result<Option<ApiKey>>
Get API key by ID (without the raw key)
Sourcepub fn revoke_key(&self, id: &str) -> Result<bool>
pub fn revoke_key(&self, id: &str) -> Result<bool>
Revoke an API key
Sourcepub fn delete_key(&self, id: &str) -> Result<bool>
pub fn delete_key(&self, id: &str) -> Result<bool>
Delete an API key
Auto Trait Implementations§
impl<'a> Freeze for ApiKeyManager<'a>
impl<'a> !RefUnwindSafe for ApiKeyManager<'a>
impl<'a> !Send for ApiKeyManager<'a>
impl<'a> !Sync for ApiKeyManager<'a>
impl<'a> Unpin for ApiKeyManager<'a>
impl<'a> UnsafeUnpin for ApiKeyManager<'a>
impl<'a> !UnwindSafe for ApiKeyManager<'a>
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.