implement equality+cmp for builders based on url
Some checks reported errors
Albatros default

This commit is contained in:
Quentin 2023-11-02 12:18:43 +01:00
parent 553ea25f18
commit 3b363b2a78
Signed by: quentin
GPG key ID: E9602264D639FF68
5 changed files with 46 additions and 33 deletions

View file

@ -39,7 +39,7 @@ pub type ArcLoginProvider = Arc<dyn LoginProvider + Send + Sync>;
#[derive(Clone, Debug)]
pub struct Credentials {
/// The storage credentials are used to authenticate access to the underlying storage (S3, K2V)
pub storage: Engine,
pub storage: Builders,
/// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V
pub keys: CryptoKeys,
}
@ -109,14 +109,11 @@ impl Region {
impl Credentials {
pub fn k2v_client(&self) -> Result<RowStore> {
self.storage.row.row_store()
pub fn row_client(&self) -> Result<RowStore> {
Ok(self.storage.row_store()?)
}
pub fn s3_client(&self) -> Result<S3Client> {
self.storage.s3_client()
}
pub fn bucket(&self) -> &str {
self.storage.bucket.as_str()
pub fn blob_client(&self) -> Result<BlobStore> {
Ok(self.storage.blob_store()?)
}
}

View file

@ -13,6 +13,7 @@ use crate::mail::incoming::incoming_mail_watch_process;
use crate::mail::mailbox::Mailbox;
use crate::mail::uidindex::ImapUidvalidity;
use crate::mail::unique_ident::{gen_ident, UniqueIdent};
use crate::storage;
use crate::time::now_msec;
pub const MAILBOX_HIERARCHY_DELIMITER: char = '.';
@ -455,6 +456,6 @@ enum CreatedMailbox {
// ---- User cache ----
lazy_static! {
static ref USER_CACHE: std::sync::Mutex<HashMap<(String, StorageCredentials), Weak<User>>> =
static ref USER_CACHE: std::sync::Mutex<HashMap<(String, storage::Builders), Weak<User>>> =
std::sync::Mutex::new(HashMap::new());
}

View file

@ -1,12 +1,12 @@
use crate::storage::*;
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Hash)]
pub struct GrgCreds {}
pub struct GrgStore {}
pub struct GrgRef {}
pub struct GrgValue {}
impl IBuilder for GrgCreds {
impl IBuilders for GrgCreds {
fn row_store(&self) -> Result<RowStore, StorageError> {
unimplemented!();
}
@ -14,6 +14,10 @@ impl IBuilder for GrgCreds {
fn blob_store(&self) -> Result<BlobStore, StorageError> {
unimplemented!();
}
fn url(&self) -> &str {
return "grg://unimplemented;"
}
}
impl IRowStore for GrgStore {

View file

@ -1,13 +1,13 @@
use futures::FutureExt;
use crate::storage::*;
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Hash)]
pub struct FullMem {}
pub struct MemStore {}
pub struct MemRef {}
pub struct MemValue {}
impl IBuilder for FullMem {
impl IBuilders for FullMem {
fn row_store(&self) -> Result<RowStore, StorageError> {
unimplemented!();
}
@ -15,6 +15,10 @@ impl IBuilder for FullMem {
fn blob_store(&self) -> Result<BlobStore, StorageError> {
unimplemented!();
}
fn url(&self) -> &str {
return "mem://unimplemented;"
}
}
impl IRowStore for MemStore {

View file

@ -8,6 +8,7 @@
* into the object system so it is not exposed.
*/
use std::hash::{Hash, Hasher};
use futures::future::BoxFuture;
pub mod in_memory;
@ -40,32 +41,38 @@ impl std::fmt::Display for StorageError {
}
impl std::error::Error for StorageError {}
pub struct Engine {
pub bucket: String,
pub builders: Builder,
}
impl Clone for Engine {
fn clone(&self) -> Self {
Engine {
bucket: "test".into(),
builders: Box::new(in_memory::FullMem{})
}
}
}
impl std::fmt::Debug for Engine {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Engine").field("bucket", &self.bucket).finish()
}
}
// Utils
pub type AsyncResult<'a, T> = BoxFuture<'a, Result<T, StorageError>>;
pub trait IBuilder {
// ----- Builders
pub trait IBuilders {
fn row_store(&self) -> Result<RowStore, StorageError>;
fn blob_store(&self) -> Result<BlobStore, StorageError>;
fn url(&self) -> &str;
}
pub type Builders = Box<dyn IBuilders + Send + Sync>;
impl Clone for Builders {
fn clone(&self) -> Self {
// @FIXME write a real implementation with a box_clone function
Box::new(in_memory::FullMem{})
}
}
impl std::fmt::Debug for Builders {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("aerogramme::storage::Builder")
}
}
impl PartialEq for Builders {
fn eq(&self, other: &Self) -> bool {
self.url() == other.url()
}
}
impl Eq for Builders {}
impl Hash for Builders {
fn hash<H: Hasher>(&self, state: &mut H) {
self.url().hash(state);
}
}
pub type Builder = Box<dyn IBuilder + Send + Sync>;
// ------ Row
pub trait IRowStore