From 3026b217774a51e01cca1ae584fba8c6398754cc Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 1 Nov 2023 15:36:06 +0100 Subject: integration to login with an enum --- src/login/mod.rs | 23 ++++++++++++++++++++--- src/storage/mod.rs | 7 +++++-- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/login/mod.rs b/src/login/mod.rs index 3fab90a..f403bcb 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -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; + async fn login(&self, username: &str, password: &str) -> Result; /// 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; } +pub enum AnyCredentials { + InMemory(Credentials), + Garage(Credentials), +} + /// ArcLoginProvider is simply an alias on a structure that is used /// in many places in the code pub type ArcLoginProvider = Arc; @@ -36,9 +44,9 @@ pub type ArcLoginProvider = Arc; /// 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 { /// 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 { self.storage.k2v_client() @@ -116,6 +125,14 @@ impl Credentials { pub fn bucket(&self) -> &str { self.storage.bucket.as_str() } +}*/ +impl From for Credentials { + fn from(ac: AnyCredentials) -> Self { + match ac { + AnyCredentials::InMemory(c) => c, + AnyCredentials::Garage(c) => c, + } + } } impl StorageCredentials { diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 4ef2d61..bc26379 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -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; type Store: RowStore; type Ref: RowRef; type Value: RowValue; } +pub trait StorageEngine: RowRealization {} + // ------ Row Builder pub trait RowBuilder { -- cgit v1.2.3