pub struct ApiKeysStore { /* private fields */ }Expand description
Manages API keys with machine-specific encryption stored in SQLite.
Implementations§
Source§impl ApiKeysStore
impl ApiKeysStore
pub fn new(pool: Arc<Pool<SqliteConnectionManager>>) -> Self
Sourcepub fn initialize_schema(&self) -> Result<()>
pub fn initialize_schema(&self) -> Result<()>
Create the api_keys table if it does not yet exist.
Sourcepub fn save_key(&self, key_type: ApiKeyType, plaintext: &str) -> Result<()>
pub fn save_key(&self, key_type: ApiKeyType, plaintext: &str) -> Result<()>
Save or update an API key.
Encrypts the plaintext value using machine-specific encryption and stores the encrypted value directly in SQLite.
Sourcepub fn get_key_plaintext(&self, key_type: &ApiKeyType) -> Result<Option<String>>
pub fn get_key_plaintext(&self, key_type: &ApiKeyType) -> Result<Option<String>>
Retrieve the plaintext value of an API key.
Decrypts the stored encrypted value using machine-specific encryption.
Sourcepub fn get_key_metadata(
&self,
key_type: &ApiKeyType,
) -> Result<Option<ApiKeyRecord>>
pub fn get_key_metadata( &self, key_type: &ApiKeyType, ) -> Result<Option<ApiKeyRecord>>
Get the raw SQLite metadata record (does not decrypt).
Sourcepub fn get_all_keys(&self) -> Result<Vec<ApiKeyRecord>>
pub fn get_all_keys(&self) -> Result<Vec<ApiKeyRecord>>
Get all API keys (encrypted values).
Sourcepub fn get_all_keys_with_values(&self) -> Result<Vec<(ApiKeyRecord, String)>>
pub fn get_all_keys_with_values(&self) -> Result<Vec<(ApiKeyRecord, String)>>
Get all API keys with their plaintext values (decrypted).
Sourcepub fn key_exists(&self, key_type: &ApiKeyType) -> Result<bool>
pub fn key_exists(&self, key_type: &ApiKeyType) -> Result<bool>
Check if an API key exists (without decrypting it).
Sourcepub fn mark_used(&self, key_type: ApiKeyType, mode: &str) -> Result<()>
pub fn mark_used(&self, key_type: ApiKeyType, mode: &str) -> Result<()>
Mark an API key as used (update last_used_at and usage_count).
Sourcepub fn delete_key(&self, key_type: ApiKeyType) -> Result<bool>
pub fn delete_key(&self, key_type: ApiKeyType) -> Result<bool>
Delete an API key from storage.
Auto Trait Implementations§
impl Freeze for ApiKeysStore
impl !RefUnwindSafe for ApiKeysStore
impl Send for ApiKeysStore
impl Sync for ApiKeysStore
impl Unpin for ApiKeysStore
impl UnsafeUnpin for ApiKeysStore
impl !UnwindSafe for ApiKeysStore
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