Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Feb 3, 2024
1 parent caebde4 commit d719c6c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/utils/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ use std::time::Duration;
use crate::env;

use aws_config::meta::region::RegionProviderChain;
use aws_sdk_s3::Client;
use aws_sdk_s3::{Region, Endpoint};
use aws_sdk_s3::presigning::config::PresigningConfig;
use aws_sdk_s3::Client;
use aws_sdk_s3::{Endpoint, Region};

pub async fn create_storage_client() -> Result<Client, aws_sdk_s3::Error> {
let shared_config = aws_config::from_env()
.region(RegionProviderChain::default_provider().or_else("eu-central-1"))
.load().await;
.load()
.await;

if let Ok(endpoint_str) = env::var("CUSTOM_ENDPOINT") {
let region = shared_config.region().cloned().unwrap_or_else(|| Region::new("eu-central-1"));
let region = shared_config
.region()
.cloned()
.unwrap_or_else(|| Region::new("eu-central-1"));
let credentials_provider = shared_config.credentials_provider().unwrap().clone();
let endpoint = Endpoint::immutable(endpoint_str.parse().expect("Invalid URI"));

let client_config = aws_sdk_s3::Config::builder()
.region(region)
.endpoint_resolver(endpoint)
.credentials_provider(credentials_provider)
.build();
.region(region)
.endpoint_resolver(endpoint)
.credentials_provider(credentials_provider)
.build();

return Ok(Client::from_conf(client_config));
}
Expand Down Expand Up @@ -49,4 +53,4 @@ pub async fn put_object(
Ok(presigned_request) => Ok(presigned_request.uri().to_string()),
Err(e) => Err(format!("Failed to create presigned URL: {}", e)),
}
}
}

0 comments on commit d719c6c

Please sign in to comment.