aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-11-01 16:45:29 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-11-01 16:45:29 +0100
commit8ac3a8ce8ba268a3261e23694b8b62afa6a3ae37 (patch)
tree0ffa2cf006c592f184df693f216ebcaeb07c2876 /src
parent3026b217774a51e01cca1ae584fba8c6398754cc (diff)
downloadaerogramme-8ac3a8ce8ba268a3261e23694b8b62afa6a3ae37.tar.gz
aerogramme-8ac3a8ce8ba268a3261e23694b8b62afa6a3ae37.zip
implement an AnyCredentials
Diffstat (limited to 'src')
-rw-r--r--src/login/mod.rs33
-rw-r--r--src/mail/user.rs6
-rw-r--r--src/storage/garage.rs3
-rw-r--r--src/storage/in_memory.rs3
-rw-r--r--src/storage/mod.rs14
5 files changed, 30 insertions, 29 deletions
diff --git a/src/login/mod.rs b/src/login/mod.rs
index f403bcb..5bd976e 100644
--- a/src/login/mod.rs
+++ b/src/login/mod.rs
@@ -16,8 +16,6 @@ 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
@@ -32,19 +30,28 @@ pub trait LoginProvider {
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>;
+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
/// with a user account's data after they are logged in.
#[derive(Clone, Debug)]
-pub struct Credentials<T: StorageEngine> {
+pub struct Credentials<T: Sto> {
/// The storage credentials are used to authenticate access to the underlying storage (S3, K2V)
pub storage: T::Builder,
/// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V
@@ -114,7 +121,7 @@ impl Region {
// ----
-/*
+
impl Credentials {
pub fn k2v_client(&self) -> Result<K2vClient> {
self.storage.k2v_client()
@@ -125,14 +132,6 @@ 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 {
diff --git a/src/mail/user.rs b/src/mail/user.rs
index 5523c2a..9d94563 100644
--- a/src/mail/user.rs
+++ b/src/mail/user.rs
@@ -30,9 +30,11 @@ pub const INBOX: &str = "INBOX";
const MAILBOX_LIST_PK: &str = "mailboxes";
const MAILBOX_LIST_SK: &str = "list";
-pub struct User {
+use crate::storage::*;
+
+pub struct User<T: Sto> {
pub username: String,
- pub creds: Credentials,
+ pub creds: Credentials<T>,
pub k2v: K2vClient,
pub mailboxes: std::sync::Mutex<HashMap<UniqueIdent, Weak<Mailbox>>>,
diff --git a/src/storage/garage.rs b/src/storage/garage.rs
index 91c4fa2..b883623 100644
--- a/src/storage/garage.rs
+++ b/src/storage/garage.rs
@@ -6,7 +6,8 @@ pub struct GrgRef {}
pub struct GrgValue {}
pub struct GrgTypes {}
-impl RowRealization for GrgTypes {
+impl Sto for GrgTypes {
+ type Builder=GrgCreds;
type Store=GrgStore;
type Ref=GrgRef;
type Value=GrgValue;
diff --git a/src/storage/in_memory.rs b/src/storage/in_memory.rs
index a2e9e96..56df266 100644
--- a/src/storage/in_memory.rs
+++ b/src/storage/in_memory.rs
@@ -6,7 +6,8 @@ pub struct MemRef {}
pub struct MemValue {}
pub struct MemTypes {}
-impl RowRealization for MemTypes {
+impl Sto for MemTypes {
+ type Builder=MemCreds;
type Store=MemStore;
type Ref=MemRef;
type Value=MemValue;
diff --git a/src/storage/mod.rs b/src/storage/mod.rs
index bc26379..2e4f757 100644
--- a/src/storage/mod.rs
+++ b/src/storage/mod.rs
@@ -28,29 +28,27 @@ pub enum Error {
Internal,
}
-pub trait RowRealization: Sized {
- type Builder: RowBuilder<Self>;
+pub trait Sto: Sized {
+ type Builder: RowStore<Self>;
type Store: RowStore<Self>;
type Ref: RowRef<Self>;
type Value: RowValue<Self>;
}
-pub trait StorageEngine: RowRealization {}
-
// ------ Row Builder
-pub trait RowBuilder<R: RowRealization>
+pub trait RowBuilder<R: Sto>
{
fn row_store(&self) -> R::Store;
}
// ------ Row Store
-pub trait RowStore<R: RowRealization>
+pub trait RowStore<R: Sto>
{
fn new_row(&self, partition: &str, sort: &str) -> R::Ref;
}
// ------- Row Item
-pub trait RowRef<R: RowRealization>
+pub trait RowRef<R: Sto>
{
fn set_value(&self, content: Vec<u8>) -> R::Value;
async fn fetch(&self) -> Result<R::Value, Error>;
@@ -58,7 +56,7 @@ pub trait RowRef<R: RowRealization>
async fn poll(&self) -> Result<Option<R::Value>, Error>;
}
-pub trait RowValue<R: RowRealization>
+pub trait RowValue<R: Sto>
{
fn to_ref(&self) -> R::Ref;
fn content(&self) -> ConcurrentValues;