aerogramme/src/storage/garage.rs

100 lines
2.7 KiB
Rust
Raw Normal View History

2023-11-01 14:15:57 +00:00
use crate::storage::*;
2023-12-18 16:09:44 +00:00
use serde::Serialize;
2023-12-21 20:54:36 +00:00
use aws_sdk_s3 as s3;
2023-11-01 14:15:57 +00:00
2023-12-18 16:09:44 +00:00
#[derive(Clone, Debug, Serialize)]
pub struct GarageConf {
2023-11-23 16:19:35 +00:00
pub region: String,
pub s3_endpoint: String,
pub k2v_endpoint: String,
pub aws_access_key_id: String,
pub aws_secret_access_key: String,
pub bucket: String,
}
2023-11-01 14:15:57 +00:00
2023-12-18 16:09:44 +00:00
#[derive(Clone, Debug)]
pub struct GarageBuilder {
conf: GarageConf,
unicity: Vec<u8>,
}
impl GarageBuilder {
pub fn new(conf: GarageConf) -> anyhow::Result<Arc<Self>> {
let mut unicity: Vec<u8> = vec![];
unicity.extend_from_slice(file!().as_bytes());
unicity.append(&mut rmp_serde::to_vec(&conf)?);
Ok(Arc::new(Self { conf, unicity }))
}
}
2023-12-21 20:54:36 +00:00
#[async_trait]
2023-12-16 10:13:32 +00:00
impl IBuilder for GarageBuilder {
2023-12-21 20:54:36 +00:00
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 }))
2023-11-01 14:15:57 +00:00
}
2023-12-18 16:09:44 +00:00
fn unique(&self) -> UnicityBuffer {
UnicityBuffer(self.unicity.clone())
}
2023-12-16 10:13:32 +00:00
}
2023-12-16 10:13:32 +00:00
pub struct GarageStore {
2023-12-21 20:54:36 +00:00
s3: s3::Client,
2023-11-01 14:15:57 +00:00
}
2023-12-16 10:13:32 +00:00
#[async_trait]
impl IStore for GarageStore {
async fn row_fetch<'a>(&self, select: &Selector<'a>) -> Result<Vec<RowVal>, StorageError> {
2023-11-01 14:15:57 +00:00
unimplemented!();
}
2023-12-16 10:13:32 +00:00
async fn row_rm<'a>(&self, select: &Selector<'a>) -> Result<(), StorageError> {
unimplemented!();
}
2023-12-16 10:13:32 +00:00
async fn row_insert(&self, values: Vec<RowVal>) -> Result<(), StorageError> {
unimplemented!();
2023-11-17 09:46:13 +00:00
}
2023-12-18 16:09:44 +00:00
async fn row_poll(&self, value: &RowRef) -> Result<RowVal, StorageError> {
2023-11-02 14:28:19 +00:00
unimplemented!();
}
2023-12-19 18:02:22 +00:00
async fn row_rm_single(&self, entry: &RowRef) -> Result<(), StorageError> {
unimplemented!();
}
2023-12-16 10:13:32 +00:00
async fn blob_fetch(&self, blob_ref: &BlobRef) -> Result<BlobVal, StorageError> {
unimplemented!();
2023-11-01 14:15:57 +00:00
}
2023-12-19 18:02:22 +00:00
async fn blob_insert(&self, blob_val: &BlobVal) -> Result<(), StorageError> {
2023-12-18 16:09:44 +00:00
unimplemented!();
}
2023-12-19 18:02:22 +00:00
async fn blob_copy(&self, src: &BlobRef, dst: &BlobRef) -> Result<(), StorageError> {
2023-11-01 14:15:57 +00:00
unimplemented!();
2023-11-17 11:15:44 +00:00
}
2023-12-16 10:13:32 +00:00
async fn blob_list(&self, prefix: &str) -> Result<Vec<BlobRef>, StorageError> {
2023-11-01 14:15:57 +00:00
unimplemented!();
}
2023-12-16 10:13:32 +00:00
async fn blob_rm(&self, blob_ref: &BlobRef) -> Result<(), StorageError> {
2023-11-01 14:15:57 +00:00
unimplemented!();
}
}