Making it more flexible

This commit is contained in:
2026-08-06 12:45:24 -04:00
parent dd5ec8a5be
commit 0f5730f242
2 changed files with 23 additions and 1 deletions
+3
View File
@@ -1,5 +1,8 @@
#[derive(Default)]
pub struct Config { pub struct Config {
pub url: String, pub url: String,
pub bucket: String, pub bucket: String,
pub region: String, pub region: String,
pub access_key_id: String,
pub secret_key: String
} }
+20 -1
View File
@@ -1,5 +1,7 @@
pub mod config; pub mod config;
use aws_sdk_s3::config::{Credentials, Region};
#[derive(Default)] #[derive(Default)]
pub struct Data { pub struct Data {
pub filepath: String, pub filepath: String,
@@ -25,7 +27,24 @@ impl Labyrinth {
file_key: &str, file_key: &str,
data: &Data, data: &Data,
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> { ) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
let config = aws_config::load_from_env().await; // 1. Create credentials
let credentials = Credentials::new(
self.config.access_key_id.clone(),
self.config.secret_key.clone(),
None, // session_token - None for long-term credentials
None, // expires_after - None for long-term credentials
"maze", // provider_name - just a label
);
// 2. Create region
let region = Region::new(self.config.region.to_string());
let config = aws_config::from_env()
.region(region)
.credentials_provider(credentials)
.load()
.await;
// let config = aws_config::load_from_env().await;
let client = aws_sdk_s3::Client::new(&config); let client = aws_sdk_s3::Client::new(&config);
let data_content = if data.raw_data.is_empty() { let data_content = if data.raw_data.is_empty() {