implement an AnyCredentials
Some checks reported errors
Albatros default

This commit is contained in:
Quentin 2023-11-01 16:45:29 +01:00
parent 3026b21777
commit 8ac3a8ce8b
Signed by: quentin
GPG key ID: E9602264D639FF68
5 changed files with 30 additions and 29 deletions

View file

@ -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 {

View file

@ -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>>>,

View file

@ -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;

View file

@ -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;

View file

@ -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;