changed key storage interface
This commit is contained in:
parent
cff93d4c3d
commit
91bfb08652
5 changed files with 257 additions and 131 deletions
|
|
@ -30,7 +30,11 @@ where
|
|||
}
|
||||
|
||||
pub trait ApiKey: Sync + Send {
|
||||
type IdType: PartialEq + Eq + std::hash::Hash;
|
||||
|
||||
fn value(&self) -> &str;
|
||||
|
||||
fn id(&self) -> Self::IdType;
|
||||
}
|
||||
|
||||
pub trait KeyDomain: Clone + std::fmt::Debug + Send + Sync {
|
||||
|
|
@ -39,6 +43,15 @@ pub trait KeyDomain: Clone + std::fmt::Debug + Send + Sync {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum KeySelector<K>
|
||||
where
|
||||
K: ApiKey,
|
||||
{
|
||||
Key(String),
|
||||
Id(K::IdType),
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait KeyPoolStorage {
|
||||
type Key: ApiKey;
|
||||
|
|
@ -62,27 +75,27 @@ pub trait KeyPoolStorage {
|
|||
domains: Vec<Self::Domain>,
|
||||
) -> Result<Self::Key, Self::Error>;
|
||||
|
||||
async fn read_key(&self, key: String) -> Result<Self::Key, Self::Error>;
|
||||
async fn read_key(&self, key: KeySelector<Self::Key>) -> Result<Self::Key, Self::Error>;
|
||||
|
||||
async fn read_user_keys(&self, user_id: i32) -> Result<Vec<Self::Key>, Self::Error>;
|
||||
|
||||
async fn remove_key(&self, key: String) -> Result<Self::Key, Self::Error>;
|
||||
async fn remove_key(&self, key: KeySelector<Self::Key>) -> Result<Self::Key, Self::Error>;
|
||||
|
||||
async fn add_domain_to_key(
|
||||
&self,
|
||||
key: String,
|
||||
key: KeySelector<Self::Key>,
|
||||
domain: Self::Domain,
|
||||
) -> Result<Self::Key, Self::Error>;
|
||||
|
||||
async fn remove_domain_from_key(
|
||||
&self,
|
||||
key: String,
|
||||
key: KeySelector<Self::Key>,
|
||||
domain: Self::Domain,
|
||||
) -> Result<Self::Key, Self::Error>;
|
||||
|
||||
async fn set_domains_for_key(
|
||||
&self,
|
||||
key: String,
|
||||
key: KeySelector<Self::Key>,
|
||||
domains: Vec<Self::Domain>,
|
||||
) -> Result<Self::Key, Self::Error>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue