use vector_lib::configurable::configurable_component;
use serde_with::serde_as;
#[serde_as]
#[configurable_component]
#[derive(Copy, Clone, Debug, Derivative)]
#[derivative(Default)]
#[serde(deny_unknown_fields)]
pub struct AwsTimeout {
#[configurable(metadata(docs::examples = 20))]
#[configurable(metadata(docs::human_name = "Connect Timeout"))]
#[configurable(metadata(docs::type_unit = "seconds"))]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "connect_timeout_seconds")]
connect_timeout: Option<u64>,
#[configurable(metadata(docs::examples = 20))]
#[configurable(metadata(docs::human_name = "Operation Timeout"))]
#[configurable(metadata(docs::type_unit = "seconds"))]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "operation_timeout_seconds")]
operation_timeout: Option<u64>,
#[configurable(metadata(docs::examples = 20))]
#[configurable(metadata(docs::human_name = "Read Timeout"))]
#[configurable(metadata(docs::type_unit = "seconds"))]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "read_timeout_seconds")]
read_timeout: Option<u64>,
}
impl AwsTimeout {
pub const fn connect_timeout(&self) -> Option<u64> {
self.connect_timeout
}
pub const fn operation_timeout(&self) -> Option<u64> {
self.operation_timeout
}
pub const fn read_timeout(&self) -> Option<u64> {
self.read_timeout
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parsing_timeout_configuration() {
let config = toml::from_str::<AwsTimeout>(
r"
connect_timeout_seconds = 20
operation_timeout_seconds = 20
read_timeout_seconds = 60
",
)
.unwrap();
assert_eq!(config.connect_timeout, Some(20));
assert_eq!(config.operation_timeout, Some(20));
assert_eq!(config.read_timeout, Some(60));
}
}