aboutsummaryrefslogtreecommitdiff
path: root/src/mailbox.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-05-19 13:54:38 +0200
committerAlex Auvolat <alex@adnab.me>2022-05-19 13:54:38 +0200
commit1ac56a91981bee4867dfb054bd2199c6111fe1eb (patch)
tree21bcb7fa97a908f6fbd95be30f750beb3abddf92 /src/mailbox.rs
parent4bc3f70e287379991eb6e31a2a075752e85958b7 (diff)
downloadaerogramme-1ac56a91981bee4867dfb054bd2199c6111fe1eb.tar.gz
aerogramme-1ac56a91981bee4867dfb054bd2199c6111fe1eb.zip
Refactor K2V/S3 client creation
Diffstat (limited to 'src/mailbox.rs')
-rw-r--r--src/mailbox.rs32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/mailbox.rs b/src/mailbox.rs
index 8e50b80..d997691 100644
--- a/src/mailbox.rs
+++ b/src/mailbox.rs
@@ -1,8 +1,6 @@
use anyhow::Result;
use k2v_client::K2vClient;
use rand::prelude::*;
-use rusoto_core::HttpClient;
-use rusoto_credential::{ProvideAwsCredentials, StaticProvider};
use rusoto_s3::S3Client;
use rusoto_signature::Region;
@@ -24,33 +22,19 @@ pub struct Mailbox {
impl Mailbox {
pub async fn new(
- k2v_region: Region,
- s3_region: Region,
- creds: Credentials,
+ k2v_region: &Region,
+ s3_region: &Region,
+ creds: &Credentials,
name: String,
) -> Result<Self> {
- let aws_creds_provider =
- StaticProvider::new_minimal(creds.aws_access_key_id, creds.aws_secret_access_key);
- let aws_creds = aws_creds_provider.credentials().await?;
-
- let uid_index = Bayou::<UidIndex>::new(
- aws_creds.clone(),
- k2v_region.clone(),
- s3_region.clone(),
- creds.bucket.clone(),
- name.clone(),
- creds.master_key.clone(),
- )?;
-
- let k2v_client = K2vClient::new(k2v_region, creds.bucket.clone(), aws_creds, None)?;
- let s3_client = S3Client::new_with(HttpClient::new()?, aws_creds_provider, s3_region);
+ let uid_index = Bayou::<UidIndex>::new(k2v_region, s3_region, creds, name.clone())?;
Ok(Self {
- bucket: creds.bucket,
+ bucket: creds.bucket.clone(),
name,
- key: creds.master_key,
- k2v: k2v_client,
- s3: s3_client,
+ key: creds.master_key.clone(),
+ k2v: creds.k2v_client(&k2v_region)?,
+ s3: creds.s3_client(&s3_region)?,
uid_index,
})
}