use std::time::Duration;
pub(super) const DEFAULT_REGION: &str = "us-east-1";
pub const DEFAULT_MAX_READ_BYTES: u64 = 10 * 1024 * 1024;
pub const DEFAULT_MAX_OBJECTS_SCANNED: usize = 500;
pub const DEFAULT_MAX_GREP_BYTES_PER_OBJECT: u64 = 1024 * 1024;
pub const DEFAULT_SEARCH_CONCURRENCY: usize = 8;
#[derive(Debug, Clone)]
pub struct S3BackendConfig {
pub endpoint: Option<String>,
pub region: Option<String>,
pub access_key_id: String,
pub secret_access_key: String,
pub session_token: Option<String>,
pub bucket: String,
pub prefix: String,
pub force_path_style: bool,
pub request_timeout: Option<Duration>,
pub max_read_bytes: Option<u64>,
pub search_enabled: bool,
pub max_objects_scanned: Option<usize>,
pub max_grep_bytes_per_object: Option<u64>,
pub search_concurrency: Option<usize>,
}
impl S3BackendConfig {
pub fn new(
bucket: impl Into<String>,
prefix: impl Into<String>,
access_key_id: impl Into<String>,
secret_access_key: impl Into<String>,
) -> Self {
Self {
endpoint: None,
region: None,
access_key_id: access_key_id.into(),
secret_access_key: secret_access_key.into(),
session_token: None,
bucket: bucket.into(),
prefix: prefix.into(),
force_path_style: false,
request_timeout: None,
max_read_bytes: None,
search_enabled: false,
max_objects_scanned: None,
max_grep_bytes_per_object: None,
search_concurrency: None,
}
}
pub fn endpoint(mut self, endpoint: impl Into<String>) -> Self {
self.endpoint = Some(endpoint.into());
self
}
pub fn region(mut self, region: impl Into<String>) -> Self {
self.region = Some(region.into());
self
}
pub fn session_token(mut self, token: impl Into<String>) -> Self {
self.session_token = Some(token.into());
self
}
pub fn force_path_style(mut self, enabled: bool) -> Self {
self.force_path_style = enabled;
self
}
pub fn request_timeout(mut self, timeout: Duration) -> Self {
self.request_timeout = Some(timeout);
self
}
pub fn max_read_bytes(mut self, bytes: u64) -> Self {
self.max_read_bytes = Some(bytes);
self
}
pub fn enable_search(mut self, enabled: bool) -> Self {
self.search_enabled = enabled;
self
}
pub fn max_objects_scanned(mut self, n: usize) -> Self {
self.max_objects_scanned = Some(n);
self
}
pub fn max_grep_bytes_per_object(mut self, bytes: u64) -> Self {
self.max_grep_bytes_per_object = Some(bytes);
self
}
pub fn search_concurrency(mut self, n: usize) -> Self {
self.search_concurrency = Some(n);
self
}
}