#[derive(Debug, Clone)]
pub struct S3Config {
pub access_key: String,
pub secret_key: String,
pub session_token: Option<String>,
pub bucket: String,
pub region: String,
pub endpoint: Option<String>,
pub force_path_style: bool,
pub use_https: bool,
}
impl S3Config {
pub fn new(
access_key: impl Into<String>,
secret_key: impl Into<String>,
bucket: impl Into<String>,
) -> Self {
S3Config {
access_key: access_key.into(),
secret_key: secret_key.into(),
session_token: None,
bucket: bucket.into(),
region: "us-east-1".to_string(),
endpoint: None,
force_path_style: false,
use_https: true,
}
}
pub fn region(mut self, region: impl Into<String>) -> Self {
self.region = region.into();
self
}
pub fn endpoint(mut self, host: impl Into<String>) -> Self {
self.endpoint = Some(host.into());
self
}
pub fn force_path_style(mut self, on: bool) -> Self {
self.force_path_style = on;
self
}
pub fn session_token(mut self, token: impl Into<String>) -> Self {
self.session_token = Some(token.into());
self
}
pub fn use_https(mut self, on: bool) -> Self {
self.use_https = on;
self
}
pub(crate) fn scheme(&self) -> &'static str {
if self.use_https {
"https"
} else {
"http"
}
}
pub(crate) fn endpoint_host(&self) -> String {
match &self.endpoint {
Some(e) => e.clone(),
None => format!("s3.{}.amazonaws.com", self.region),
}
}
}