This commit is contained in:
parent
8ac3a8ce8b
commit
cf8b9ac28d
3 changed files with 24 additions and 20 deletions
|
@ -24,7 +24,7 @@ use crate::storage::*;
|
||||||
pub trait LoginProvider {
|
pub trait LoginProvider {
|
||||||
/// The login method takes an account's password as an input to decypher
|
/// The login method takes an account's password as an input to decypher
|
||||||
/// decryption keys and obtain full access to the user's account.
|
/// decryption keys and obtain full access to the user's account.
|
||||||
async fn login(&self, username: &str, password: &str) -> Result<AnyCredentials>;
|
async fn login(&self, username: &str, password: &str) -> Result<Credentials>;
|
||||||
/// The public_login method takes an account's email address and returns
|
/// The public_login method takes an account's email address and returns
|
||||||
/// public credentials for adding mails to the user's inbox.
|
/// public credentials for adding mails to the user's inbox.
|
||||||
async fn public_login(&self, email: &str) -> Result<PublicCredentials>;
|
async fn public_login(&self, email: &str) -> Result<PublicCredentials>;
|
||||||
|
@ -34,26 +34,12 @@ pub trait LoginProvider {
|
||||||
/// in many places in the code
|
/// in many places in the code
|
||||||
pub type ArcLoginProvider = Arc<dyn LoginProvider + Send + Sync>;
|
pub type ArcLoginProvider = Arc<dyn LoginProvider + Send + Sync>;
|
||||||
|
|
||||||
pub enum AnyCredentials {
|
|
||||||
InMemory(Credentials<in_memory::MemTypes>),
|
|
||||||
Garage(Credentials<garage::GrgTypes>),
|
|
||||||
}
|
|
||||||
impl<X> AnyCredentials where X: Sto
|
|
||||||
{
|
|
||||||
fn to_gen(&self) -> Credentials<X> {
|
|
||||||
match self {
|
|
||||||
Self::InMemory(u) => u,
|
|
||||||
Self::Garage(u) => u,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The struct Credentials represent all of the necessary information to interact
|
/// The struct Credentials represent all of the necessary information to interact
|
||||||
/// with a user account's data after they are logged in.
|
/// with a user account's data after they are logged in.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Credentials<T: Sto> {
|
pub struct Credentials {
|
||||||
/// The storage credentials are used to authenticate access to the underlying storage (S3, K2V)
|
/// The storage credentials are used to authenticate access to the underlying storage (S3, K2V)
|
||||||
pub storage: T::Builder,
|
pub storage: AnyEngine,
|
||||||
/// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V
|
/// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V
|
||||||
pub keys: CryptoKeys,
|
pub keys: CryptoKeys,
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ const MAILBOX_LIST_SK: &str = "list";
|
||||||
|
|
||||||
use crate::storage::*;
|
use crate::storage::*;
|
||||||
|
|
||||||
pub struct User<T: Sto> {
|
pub struct User {
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub creds: Credentials<T>,
|
pub creds: Credentials,
|
||||||
pub k2v: K2vClient,
|
pub k2v: K2vClient,
|
||||||
pub mailboxes: std::sync::Mutex<HashMap<UniqueIdent, Weak<Mailbox>>>,
|
pub mailboxes: std::sync::Mutex<HashMap<UniqueIdent, Weak<Mailbox>>>,
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,30 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Sto: Sized {
|
pub trait Sto: Sized {
|
||||||
type Builder: RowStore<Self>;
|
type Builder: RowBuilder<Self>;
|
||||||
type Store: RowStore<Self>;
|
type Store: RowStore<Self>;
|
||||||
type Ref: RowRef<Self>;
|
type Ref: RowRef<Self>;
|
||||||
type Value: RowValue<Self>;
|
type Value: RowValue<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Engine<T: Sto> {
|
||||||
|
bucket: String,
|
||||||
|
row: T::Builder,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum AnyEngine {
|
||||||
|
InMemory(Engine<in_memory::MemTypes>),
|
||||||
|
Garage(Engine<garage::GrgTypes>),
|
||||||
|
}
|
||||||
|
impl AnyEngine {
|
||||||
|
fn engine<X: Sto>(&self) -> &Engine<X> {
|
||||||
|
match self {
|
||||||
|
Self::InMemory(x) => x,
|
||||||
|
Self::Garage(x) => x,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ------ Row Builder
|
// ------ Row Builder
|
||||||
pub trait RowBuilder<R: Sto>
|
pub trait RowBuilder<R: Sto>
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue