integration to login with an enum
Albatros default Details

This commit is contained in:
Quentin 2023-11-01 15:36:06 +01:00
parent 92fea414d9
commit 3026b21777
Signed by: quentin
GPG Key ID: E9602264D639FF68
2 changed files with 25 additions and 5 deletions

View File

@ -15,6 +15,9 @@ use rusoto_credential::{AwsCredentials, StaticProvider};
use rusoto_s3::S3Client;
use crate::cryptoblob::*;
use crate::storage::*;
use crate::storage::in_memory::MemTypes;
use crate::storage::garage::GrgTypes;
/// The trait LoginProvider defines the interface for a login provider that allows
/// to retrieve storage and cryptographic credentials for access to a user account
@ -23,12 +26,17 @@ use crate::cryptoblob::*;
pub trait LoginProvider {
/// The login method takes an account's password as an input to decypher
/// decryption keys and obtain full access to the user's account.
async fn login(&self, username: &str, password: &str) -> Result<Credentials>;
async fn login(&self, username: &str, password: &str) -> Result<AnyCredentials>;
/// The public_login method takes an account's email address and returns
/// public credentials for adding mails to the user's inbox.
async fn public_login(&self, email: &str) -> Result<PublicCredentials>;
}
pub enum AnyCredentials {
InMemory(Credentials<MemTypes>),
Garage(Credentials<GrgTypes>),
}
/// ArcLoginProvider is simply an alias on a structure that is used
/// in many places in the code
pub type ArcLoginProvider = Arc<dyn LoginProvider + Send + Sync>;
@ -36,9 +44,9 @@ pub type ArcLoginProvider = Arc<dyn LoginProvider + Send + Sync>;
/// The struct Credentials represent all of the necessary information to interact
/// with a user account's data after they are logged in.
#[derive(Clone, Debug)]
pub struct Credentials {
pub struct Credentials<T: StorageEngine> {
/// The storage credentials are used to authenticate access to the underlying storage (S3, K2V)
pub storage: StorageCredentials,
pub storage: T::Builder,
/// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V
pub keys: CryptoKeys,
}
@ -106,6 +114,7 @@ impl Region {
// ----
/*
impl Credentials {
pub fn k2v_client(&self) -> Result<K2vClient> {
self.storage.k2v_client()
@ -116,6 +125,14 @@ impl Credentials {
pub fn bucket(&self) -> &str {
self.storage.bucket.as_str()
}
}*/
impl<T: StorageEngine> From<AnyCredentials> for Credentials<T> {
fn from(ac: AnyCredentials) -> Self {
match ac {
AnyCredentials::InMemory(c) => c,
AnyCredentials::Garage(c) => c,
}
}
}
impl StorageCredentials {

View File

@ -8,8 +8,8 @@
* into the object system so it is not exposed.
*/
mod in_memory;
mod garage;
pub mod in_memory;
pub mod garage;
pub enum Selector<'a> {
Range{ begin: &'a str, end: &'a str },
@ -29,11 +29,14 @@ pub enum Error {
}
pub trait RowRealization: Sized {
type Builder: RowBuilder<Self>;
type Store: RowStore<Self>;
type Ref: RowRef<Self>;
type Value: RowValue<Self>;
}
pub trait StorageEngine: RowRealization {}
// ------ Row Builder
pub trait RowBuilder<R: RowRealization>
{