aboutsummaryrefslogtreecommitdiff
path: root/src/storage
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-12-21 21:54:36 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-12-21 21:54:36 +0100
commit012c6ad6724b6a6e155ee717e6d558e1fe199e43 (patch)
tree986377de04024911c1c460e41828dde546d5a6a6 /src/storage
parent4b8b48b48572115b943efdf6356a191871d46a55 (diff)
downloadaerogramme-012c6ad6724b6a6e155ee717e6d558e1fe199e43.tar.gz
aerogramme-012c6ad6724b6a6e155ee717e6d558e1fe199e43.zip
initialize aws sdk with our info
Diffstat (limited to 'src/storage')
-rw-r--r--src/storage/garage.rs24
-rw-r--r--src/storage/in_memory.rs3
-rw-r--r--src/storage/mod.rs3
3 files changed, 25 insertions, 5 deletions
diff --git a/src/storage/garage.rs b/src/storage/garage.rs
index f202067..5d00ed6 100644
--- a/src/storage/garage.rs
+++ b/src/storage/garage.rs
@@ -1,5 +1,6 @@
use crate::storage::*;
use serde::Serialize;
+use aws_sdk_s3 as s3;
#[derive(Clone, Debug, Serialize)]
pub struct GarageConf {
@@ -26,9 +27,26 @@ impl GarageBuilder {
}
}
+#[async_trait]
impl IBuilder for GarageBuilder {
- fn build(&self) -> Result<Store, StorageError> {
- unimplemented!();
+ async fn build(&self) -> Result<Store, StorageError> {
+ let creds = s3::config::Credentials::new(
+ self.conf.aws_access_key_id.clone(),
+ self.conf.aws_secret_access_key.clone(),
+ None,
+ None,
+ "aerogramme"
+ );
+
+ let config = aws_config::from_env()
+ .region(aws_config::Region::new(self.conf.region.clone()))
+ .credentials_provider(creds)
+ .endpoint_url(self.conf.s3_endpoint.clone())
+ .load()
+ .await;
+
+ let s3_client = aws_sdk_s3::Client::new(&config);
+ Ok(Box::new(GarageStore { s3: s3_client }))
}
fn unique(&self) -> UnicityBuffer {
UnicityBuffer(self.unicity.clone())
@@ -36,7 +54,7 @@ impl IBuilder for GarageBuilder {
}
pub struct GarageStore {
- dummy: String,
+ s3: s3::Client,
}
#[async_trait]
diff --git a/src/storage/in_memory.rs b/src/storage/in_memory.rs
index fb6e599..723bca0 100644
--- a/src/storage/in_memory.rs
+++ b/src/storage/in_memory.rs
@@ -106,8 +106,9 @@ impl MemBuilder {
}
}
+#[async_trait]
impl IBuilder for MemBuilder {
- fn build(&self) -> Result<Store, StorageError> {
+ async fn build(&self) -> Result<Store, StorageError> {
Ok(Box::new(MemStore {
row: self.row.clone(),
blob: self.blob.clone(),
diff --git a/src/storage/mod.rs b/src/storage/mod.rs
index 0fedfab..10149e9 100644
--- a/src/storage/mod.rs
+++ b/src/storage/mod.rs
@@ -157,8 +157,9 @@ pub trait IStore {
#[derive(Clone,Debug,PartialEq,Eq,Hash)]
pub struct UnicityBuffer(Vec<u8>);
+#[async_trait]
pub trait IBuilder: std::fmt::Debug {
- fn build(&self) -> Result<Store, StorageError>;
+ async fn build(&self) -> Result<Store, StorageError>;
/// Returns an opaque buffer that uniquely identifies this builder
fn unique(&self) -> UnicityBuffer;