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!(toml::from_str::<RegionOrEndpoint>(indoc! {"
59 "})
60 .is_ok());
61 }
62
63 #[test]
64 fn region_optional() {
65 assert!(toml::from_str::<RegionOrEndpoint>(indoc! {r#"
66 endpoint = "http://localhost:8080"
67 "#})
68 .is_ok());
69 }
70
71 #[test]
72 fn endpoint_optional() {
73 assert!(toml::from_str::<RegionOrEndpoint>(indoc! {r#"
74 region = "us-east-1"
75 "#})
76 .is_ok());
77 }
78}