aboutsummaryrefslogtreecommitdiff
path: root/aero-user/src
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-04-23 10:35:43 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-04-23 10:35:43 +0200
commit4594e068dbba3d3d704728449fc6ccaaadaa82f1 (patch)
tree6a098fba87dcbcb9b7754609deaac159abb82b92 /aero-user/src
parent936f851fdb120dd0b46c4effeabe0dbb508d4d3d (diff)
downloadaerogramme-4594e068dbba3d3d704728449fc6ccaaadaa82f1.tar.gz
aerogramme-4594e068dbba3d3d704728449fc6ccaaadaa82f1.zip
PUT seems to work
Diffstat (limited to 'aero-user/src')
-rw-r--r--aero-user/src/storage/garage.rs14
-rw-r--r--aero-user/src/storage/in_memory.rs16
-rw-r--r--aero-user/src/storage/mod.rs2
3 files changed, 23 insertions, 9 deletions
diff --git a/aero-user/src/storage/garage.rs b/aero-user/src/storage/garage.rs
index 7e930c3..1164839 100644
--- a/aero-user/src/storage/garage.rs
+++ b/aero-user/src/storage/garage.rs
@@ -426,15 +426,16 @@ impl IStore for GarageStore {
tracing::debug!("Fetched {}/{}", self.bucket, blob_ref.0);
Ok(bv)
}
- async fn blob_insert(&self, blob_val: BlobVal) -> Result<(), StorageError> {
+ async fn blob_insert(&self, blob_val: BlobVal) -> Result<String, StorageError> {
tracing::trace!(entry=%blob_val.blob_ref, command="blob_insert");
let streamable_value = s3::primitives::ByteStream::from(blob_val.value);
+ let obj_key = blob_val.blob_ref.0;
let maybe_send = self
.s3
.put_object()
.bucket(self.bucket.to_string())
- .key(blob_val.blob_ref.0.to_string())
+ .key(obj_key.to_string())
.set_metadata(Some(blob_val.meta))
.body(streamable_value)
.send()
@@ -445,9 +446,12 @@ impl IStore for GarageStore {
tracing::error!("unable to send object: {}", e);
Err(StorageError::Internal)
}
- Ok(_) => {
- tracing::debug!("Inserted {}/{}", self.bucket, blob_val.blob_ref.0);
- Ok(())
+ Ok(put_output) => {
+ tracing::debug!("Inserted {}/{}", self.bucket, obj_key);
+ Ok(put_output
+ .e_tag()
+ .map(|v| format!("\"{}\"", v))
+ .unwrap_or(format!("W/\"{}\"", obj_key)))
}
}
}
diff --git a/aero-user/src/storage/in_memory.rs b/aero-user/src/storage/in_memory.rs
index a676797..9ef2721 100644
--- a/aero-user/src/storage/in_memory.rs
+++ b/aero-user/src/storage/in_memory.rs
@@ -1,9 +1,12 @@
-use crate::storage::*;
use std::collections::BTreeMap;
use std::ops::Bound::{self, Excluded, Included, Unbounded};
use std::sync::RwLock;
+
+use sodiumoxide::{hex, crypto::hash};
use tokio::sync::Notify;
+use crate::storage::*;
+
/// This implementation is very inneficient, and not completely correct
/// Indeed, when the connector is dropped, the memory is freed.
/// It means that when a user disconnects, its data are lost.
@@ -80,6 +83,12 @@ impl InternalBlobVal {
value: self.data.clone(),
}
}
+ fn etag(&self) -> String {
+ let digest = hash::hash(self.data.as_ref());
+ let buff = digest.as_ref();
+ let hexstr = hex::encode(buff);
+ format!("\"{}\"", hexstr)
+ }
}
type ArcRow = Arc<RwLock<HashMap<String, BTreeMap<String, InternalRowVal>>>>;
@@ -300,13 +309,14 @@ impl IStore for MemStore {
.ok_or(StorageError::NotFound)
.map(|v| v.to_blob_val(blob_ref))
}
- async fn blob_insert(&self, blob_val: BlobVal) -> Result<(), StorageError> {
+ async fn blob_insert(&self, blob_val: BlobVal) -> Result<String, StorageError> {
tracing::trace!(entry=%blob_val.blob_ref, command="blob_insert");
let mut store = self.blob.write().or(Err(StorageError::Internal))?;
let entry = store.entry(blob_val.blob_ref.0.clone()).or_default();
entry.data = blob_val.value.clone();
entry.metadata = blob_val.meta.clone();
- Ok(())
+
+ Ok(entry.etag())
}
async fn blob_copy(&self, src: &BlobRef, dst: &BlobRef) -> Result<(), StorageError> {
tracing::trace!(src=%src, dst=%dst, command="blob_copy");
diff --git a/aero-user/src/storage/mod.rs b/aero-user/src/storage/mod.rs
index f5eb8d3..527765f 100644
--- a/aero-user/src/storage/mod.rs
+++ b/aero-user/src/storage/mod.rs
@@ -159,7 +159,7 @@ pub trait IStore {
async fn row_poll(&self, value: &RowRef) -> Result<RowVal, StorageError>;
async fn blob_fetch(&self, blob_ref: &BlobRef) -> Result<BlobVal, StorageError>;
- async fn blob_insert(&self, blob_val: BlobVal) -> Result<(), StorageError>;
+ async fn blob_insert(&self, blob_val: BlobVal) -> Result<String, StorageError>;
async fn blob_copy(&self, src: &BlobRef, dst: &BlobRef) -> Result<(), StorageError>;
async fn blob_list(&self, prefix: &str) -> Result<Vec<BlobRef>, StorageError>;
async fn blob_rm(&self, blob_ref: &BlobRef) -> Result<(), StorageError>;