1use aws_types::region::Region;
3use vector_lib::configurable::configurable_component;
4
5#[configurable_component]
7#[derive(Clone, Debug, Default, PartialEq, Eq)]
8#[serde(default)]
9pub struct RegionOrEndpoint {
10 #[configurable(metadata(docs::examples = "us-east-1"))]
14 pub region: Option<String>,
15
16 #[configurable(metadata(docs::examples = "http://127.0.0.0:5000/path/to/service"))]
18 #[configurable(metadata(docs::advanced))]
19 pub endpoint: Option<String>,
20}
21
22impl RegionOrEndpoint {
23 pub const fn with_region(region: String) -> Self {
25 Self {
26 region: Some(region),
27 endpoint: None,
28 }
29 }
30
31 pub fn with_both(region: impl Into<String>, endpoint: impl Into<String>) -> Self {
33 Self {
34 region: Some(region.into()),
35 endpoint: Some(endpoint.into()),
36 }
37 }
38
39 pub fn endpoint(&self) -> Option<String> {
41 self.endpoint.clone()
42 }
43
44 pub fn region(&self) -> Option<Region> {
46 self.region.clone().map(Region::new)
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use indoc::indoc;
53
54 use super::*;
55
56 #[test]
57 fn optional() {
58 assert!(
59 toml::from_str::<RegionOrEndpoint>(indoc! {"
60 "})
61 .is_ok()
62 );
63 }
64
65 #[test]
66 fn region_optional() {
67 assert!(
68 toml::from_str::<RegionOrEndpoint>(indoc! {r#"
69 endpoint = "http://localhost:8080"
70 "#})
71 .is_ok()
72 );
73 }
74
75 #[test]
76 fn endpoint_optional() {
77 assert!(
78 toml::from_str::<RegionOrEndpoint>(indoc! {r#"
79 region = "us-east-1"
80 "#})
81 .is_ok()
82 );
83 }
84}