apikeys_rs/
traits.rs

1use async_trait::async_trait;
2
3use crate::{
4    errors::{ApiKeyLimiterError, ApiKeyManagerError, ApiKeyStorageError},
5    types::ApiKey,
6};
7
8#[async_trait]
9pub trait ApiKeyStorage {
10    async fn store_api_key(&mut self, key: &str, value: &ApiKey) -> Result<String, ApiKeyStorageError>;
11    async fn retrieve_api_key(&self, key: &str) -> Result<ApiKey, ApiKeyStorageError>;
12    async fn delete_api_key(&mut self, key: &str) -> Result<bool, ApiKeyStorageError>;
13}
14
15#[async_trait]
16pub trait ApiKeyLimiter {
17    async fn use_key(&self, api_key: &ApiKey) -> Result<(), ApiKeyLimiterError>;
18}
19
20#[async_trait]
21pub trait ApiKeyManager {
22    async fn get_key(&self, key: &str) -> Result<ApiKey, ApiKeyManagerError>;
23    async fn use_key(&self, key: &str) -> Result<(), ApiKeyManagerError>;
24}