use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::config::Config;
#[derive(Default, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct S3OptionsMap(pub IndexMap<String, S3Options>);
impl S3OptionsMap {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub struct S3Options {
pub endpoint_url: Url,
pub region: String,
pub force_path_style: bool,
}
impl Config for S3OptionsMap {
fn is_default(&self) -> bool {
self.0.is_empty()
}
fn merge_config(self, other: &Self) -> Result<Self, super::MergeError> {
let mut merged = self.0.clone();
for (key, value) in &other.0 {
merged.insert(key.clone(), value.clone());
}
Ok(S3OptionsMap(merged))
}
fn validate(&self) -> Result<(), super::ValidationError> {
Ok(())
}
fn keys(&self) -> Vec<String> {
self.0.keys().map(ToString::to_string).collect()
}
}