added new method to s3clientconfig struct, added from_env to be default

This commit is contained in:
2025-07-14 18:21:13 -04:00
parent a64b8fdceb
commit 29011c8f48

View File

@@ -18,6 +18,22 @@ pub struct S3Client {
} }
impl S3ClientConfig { impl S3ClientConfig {
pub fn new(
access_key: &str,
secret_key: &str,
endpoint: &str,
bucket: &str,
region: &str,
) -> Result<Self, Box<dyn std::error::Error>> {
Ok(S3ClientConfig {
access_key: access_key.to_owned(),
secret_key: secret_key.to_owned(),
endpoint: endpoint.to_owned(),
bucket: bucket.to_owned(),
region: region.to_owned(),
})
}
pub fn from_env() -> Result<Self, Box<dyn std::error::Error>> { pub fn from_env() -> Result<Self, Box<dyn std::error::Error>> {
Ok(S3ClientConfig { Ok(S3ClientConfig {
access_key: env::var("S3_ACCESS_KEY") access_key: env::var("S3_ACCESS_KEY")
@@ -99,3 +115,9 @@ impl ObjectStorageClient for S3Client {
todo!("not impl") todo!("not impl")
} }
} }
impl Default for S3ClientConfig {
fn default() -> Self {
S3ClientConfig::from_env().unwrap()
}
}