aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-12-21 22:30:17 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-12-21 22:30:17 +0100
commit1057661da77c3d94e5a1ff51ab7fc58ecdb6a53a (patch)
tree8ef0e232f23b357392dc62767a453f54a6d17578
parent012c6ad6724b6a6e155ee717e6d558e1fe199e43 (diff)
downloadaerogramme-1057661da77c3d94e5a1ff51ab7fc58ecdb6a53a.tar.gz
aerogramme-1057661da77c3d94e5a1ff51ab7fc58ecdb6a53a.zip
implemented blob_fetch
-rw-r--r--src/storage/garage.rs43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/storage/garage.rs b/src/storage/garage.rs
index 5d00ed6..97494f6 100644
--- a/src/storage/garage.rs
+++ b/src/storage/garage.rs
@@ -1,6 +1,10 @@
use crate::storage::*;
use serde::Serialize;
-use aws_sdk_s3 as s3;
+use aws_sdk_s3::{
+ self as s3,
+ error::SdkError,
+ operation::get_object::GetObjectError,
+};
#[derive(Clone, Debug, Serialize)]
pub struct GarageConf {
@@ -46,7 +50,10 @@ impl IBuilder for GarageBuilder {
.await;
let s3_client = aws_sdk_s3::Client::new(&config);
- Ok(Box::new(GarageStore { s3: s3_client }))
+ Ok(Box::new(GarageStore {
+ s3_bucket: self.conf.bucket.clone(),
+ s3: s3_client
+ }))
}
fn unique(&self) -> UnicityBuffer {
UnicityBuffer(self.unicity.clone())
@@ -54,6 +61,7 @@ impl IBuilder for GarageBuilder {
}
pub struct GarageStore {
+ s3_bucket: String,
s3: s3::Client,
}
@@ -79,8 +87,37 @@ impl IStore for GarageStore {
}
async fn blob_fetch(&self, blob_ref: &BlobRef) -> Result<BlobVal, StorageError> {
- unimplemented!();
+ let maybe_out = self.s3
+ .get_object()
+ .bucket(self.s3_bucket.to_string())
+ .key(blob_ref.0.to_string())
+ .send()
+ .await;
+
+ let object_output = match maybe_out {
+ Ok(output) => output,
+ Err(SdkError::ServiceError(x)) => match x.err() {
+ GetObjectError::NoSuchKey(_) => return Err(StorageError::NotFound),
+ e => {
+ tracing::warn!("Blob Fetch Error, Service Error: {}", e);
+ return Err(StorageError::Internal);
+ },
+ },
+ Err(e) => {
+ tracing::warn!("Blob Fetch Error, {}", e);
+ return Err(StorageError::Internal);
+ },
+ };
+
+ let buffer = match object_output.body.collect().await {
+ Ok(aggreg) => aggreg.to_vec(),
+ Err(e) => {
+ tracing::warn!("Fetching body failed with {}", e);
+ return Err(StorageError::Internal);
+ }
+ };
+ Ok(BlobVal::new(blob_ref.clone(), buffer))
}
async fn blob_insert(&self, blob_val: &BlobVal) -> Result<(), StorageError> {
unimplemented!();