in-memory storage #32
5 changed files with 44 additions and 25 deletions
|
@ -39,7 +39,7 @@ pub type ArcLoginProvider = Arc<dyn LoginProvider + Send + Sync>;
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Credentials {
|
pub struct Credentials {
|
||||||
/// The storage credentials are used to authenticate access to the underlying storage (S3, K2V)
|
/// The storage credentials are used to authenticate access to the underlying storage (S3, K2V)
|
||||||
pub storage: AnyEngine,
|
pub storage: Engine,
|
||||||
/// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V
|
/// The cryptographic keys are used to encrypt and decrypt data stored in S3 and K2V
|
||||||
pub keys: CryptoKeys,
|
pub keys: CryptoKeys,
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ use crate::mail::unique_ident::*;
|
||||||
use crate::mail::user::User;
|
use crate::mail::user::User;
|
||||||
use crate::mail::IMF;
|
use crate::mail::IMF;
|
||||||
use crate::time::now_msec;
|
use crate::time::now_msec;
|
||||||
use crate::storage::Sto;
|
|
||||||
|
|
||||||
const INCOMING_PK: &str = "incoming";
|
const INCOMING_PK: &str = "incoming";
|
||||||
const INCOMING_LOCK_SK: &str = "lock";
|
const INCOMING_LOCK_SK: &str = "lock";
|
||||||
|
@ -140,14 +139,14 @@ async fn incoming_mail_watch_process_internal(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_incoming_mail<X: Sto>(
|
async fn handle_incoming_mail(
|
||||||
user: &Arc<User>,
|
user: &Arc<User>,
|
||||||
s3: &S3Client,
|
s3: &S3Client,
|
||||||
inbox: &Arc<Mailbox>,
|
inbox: &Arc<Mailbox>,
|
||||||
lock_held: &watch::Receiver<bool>,
|
lock_held: &watch::Receiver<bool>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let lor = ListObjectsV2Request {
|
let lor = ListObjectsV2Request {
|
||||||
bucket: user.creds.storage.engine::<X>().bucket.clone(),
|
bucket: user.creds.storage.bucket.clone(),
|
||||||
max_keys: Some(1000),
|
max_keys: Some(1000),
|
||||||
prefix: Some("incoming/".into()),
|
prefix: Some("incoming/".into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
@ -1,45 +1,46 @@
|
||||||
use crate::storage::*;
|
use crate::storage::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct GrgCreds {}
|
pub struct GrgCreds {}
|
||||||
pub struct GrgStore {}
|
pub struct GrgStore {}
|
||||||
pub struct GrgRef {}
|
pub struct GrgRef {}
|
||||||
pub struct GrgValue {}
|
pub struct GrgValue {}
|
||||||
|
|
||||||
impl IRowBuilder for GrgCreds {
|
impl IRowBuilder for GrgCreds {
|
||||||
fn row_store(&self) -> GrgStore {
|
fn row_store(&self) -> RowStore {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IRowStore for GrgStore {
|
impl IRowStore for GrgStore {
|
||||||
fn new_row(&self, partition: &str, sort: &str) -> GrgRef {
|
fn new_row(&self, partition: &str, sort: &str) -> RowRef {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IRowRef for GrgRef {
|
impl IRowRef for GrgRef {
|
||||||
fn set_value(&self, content: Vec<u8>) -> GrgValue {
|
fn set_value(&self, content: Vec<u8>) -> RowValue {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
async fn fetch(&self) -> Result<GrgValue, Error> {
|
fn fetch(&self) -> AsyncResult<RowValue> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
async fn rm(&self) -> Result<(), Error> {
|
fn rm(&self) -> AsyncResult<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
async fn poll(&self) -> Result<Option<GrgValue>, Error> {
|
fn poll(&self) -> AsyncResult<Option<RowValue>> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IRowValue for GrgValue {
|
impl IRowValue for GrgValue {
|
||||||
fn to_ref(&self) -> GrgRef {
|
fn to_ref(&self) -> RowRef {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
fn content(&self) -> ConcurrentValues {
|
fn content(&self) -> ConcurrentValues {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
async fn push(&self) -> Result<(), Error> {
|
fn push(&self) -> AsyncResult<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,46 @@
|
||||||
use crate::storage::*;
|
use crate::storage::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct MemCreds {}
|
pub struct MemCreds {}
|
||||||
pub struct MemStore {}
|
pub struct MemStore {}
|
||||||
pub struct MemRef {}
|
pub struct MemRef {}
|
||||||
pub struct MemValue {}
|
pub struct MemValue {}
|
||||||
|
|
||||||
impl IRowBuilder for MemCreds {
|
impl IRowBuilder for MemCreds {
|
||||||
fn row_store(&self) -> MemStore {
|
fn row_store(&self) -> RowStore {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IRowStore for MemStore {
|
impl IRowStore for MemStore {
|
||||||
fn new_row(&self, partition: &str, sort: &str) -> MemRef {
|
fn new_row(&self, partition: &str, sort: &str) -> RowRef {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IRowRef for MemRef {
|
impl IRowRef for MemRef {
|
||||||
fn set_value(&self, content: Vec<u8>) -> MemValue {
|
fn set_value(&self, content: Vec<u8>) -> RowValue {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
async fn fetch(&self) -> Result<MemValue, Error> {
|
fn fetch(&self) -> AsyncResult<RowValue> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
async fn rm(&self) -> Result<(), Error> {
|
fn rm(&self) -> AsyncResult<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
async fn poll(&self) -> Result<Option<MemValue>, Error> {
|
fn poll(&self) -> AsyncResult<Option<RowValue>> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IRowValue for MemValue {
|
impl IRowValue for MemValue {
|
||||||
fn to_ref(&self) -> MemRef {
|
fn to_ref(&self) -> RowRef {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
fn content(&self) -> ConcurrentValues {
|
fn content(&self) -> ConcurrentValues {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
async fn push(&self) -> Result<(), Error> {
|
fn push(&self) -> AsyncResult<()> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
* into the object system so it is not exposed.
|
* into the object system so it is not exposed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use futures::future::BoxFuture;
|
||||||
|
|
||||||
pub mod in_memory;
|
pub mod in_memory;
|
||||||
pub mod garage;
|
pub mod garage;
|
||||||
|
|
||||||
|
@ -32,13 +34,29 @@ pub struct Engine {
|
||||||
pub bucket: String,
|
pub bucket: String,
|
||||||
pub row: RowBuilder,
|
pub row: RowBuilder,
|
||||||
}
|
}
|
||||||
|
impl Clone for Engine {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
Engine {
|
||||||
|
bucket: "test".into(),
|
||||||
|
row: Box::new(in_memory::MemCreds{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A result
|
||||||
|
pub type AsyncResult<'a, T> = BoxFuture<'a, Result<T, Error>>;
|
||||||
|
|
||||||
// ------ Row Builder
|
// ------ Row Builder
|
||||||
pub trait IRowBuilder
|
pub trait IRowBuilder
|
||||||
{
|
{
|
||||||
fn row_store(&self) -> RowStore;
|
fn row_store(&self) -> RowStore;
|
||||||
}
|
}
|
||||||
pub type RowBuilder = Box<dyn IRowBuilder>;
|
pub type RowBuilder = Box<dyn IRowBuilder + Send + Sync>;
|
||||||
|
|
||||||
// ------ Row Store
|
// ------ Row Store
|
||||||
pub trait IRowStore
|
pub trait IRowStore
|
||||||
|
@ -51,9 +69,9 @@ type RowStore = Box<dyn IRowStore>;
|
||||||
pub trait IRowRef
|
pub trait IRowRef
|
||||||
{
|
{
|
||||||
fn set_value(&self, content: Vec<u8>) -> RowValue;
|
fn set_value(&self, content: Vec<u8>) -> RowValue;
|
||||||
async fn fetch(&self) -> Result<RowValue, Error>;
|
fn fetch(&self) -> AsyncResult<RowValue>;
|
||||||
async fn rm(&self) -> Result<(), Error>;
|
fn rm(&self) -> AsyncResult<()>;
|
||||||
async fn poll(&self) -> Result<Option<RowValue>, Error>;
|
fn poll(&self) -> AsyncResult<Option<RowValue>>;
|
||||||
}
|
}
|
||||||
type RowRef = Box<dyn IRowRef>;
|
type RowRef = Box<dyn IRowRef>;
|
||||||
|
|
||||||
|
@ -61,6 +79,6 @@ pub trait IRowValue
|
||||||
{
|
{
|
||||||
fn to_ref(&self) -> RowRef;
|
fn to_ref(&self) -> RowRef;
|
||||||
fn content(&self) -> ConcurrentValues;
|
fn content(&self) -> ConcurrentValues;
|
||||||
async fn push(&self) -> Result<(), Error>;
|
fn push(&self) -> AsyncResult<()>;
|
||||||
}
|
}
|
||||||
type RowValue = Box<dyn IRowValue>;
|
type RowValue = Box<dyn IRowValue>;
|
||||||
|
|
Loading…
Reference in a new issue