feldera_types/transport/
url.rs1use serde::{Deserialize, Serialize};
2use utoipa::ToSchema;
3
4use crate::{
5 duration::{ConfigDuration, LegacyUnit},
6 duration_setting,
7};
8
9pub const DEFAULT_PAUSE_TIMEOUT: ConfigDuration = ConfigDuration::from_secs(60);
11
12fn default_pause_linger() -> String {
14 DEFAULT_PAUSE_TIMEOUT.to_string()
15}
16
17duration_setting!(duration_pause_linger, "pause_linger", LegacyUnit::Secs);
18
19#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
22pub struct UrlInputConfig {
23 pub path: String,
25
26 #[serde(
36 default,
37 alias = "pause_timeout",
38 deserialize_with = "duration_pause_linger",
39 skip_serializing_if = "Option::is_none"
40 )]
41 #[schema(value_type = Option<String>, default = default_pause_linger)]
42 pub pause_linger: Option<ConfigDuration>,
43}
44
45impl UrlInputConfig {
46 pub fn pause_linger(&self) -> ConfigDuration {
48 self.pause_linger.unwrap_or(DEFAULT_PAUSE_TIMEOUT)
49 }
50}
51
52impl crate::sensitive::SensitiveValues for UrlInputConfig {
53 fn visit_sensitive_values(&self, visit: &mut dyn FnMut(&str, &str)) {
54 crate::sensitive::visit_url("path", &self.path, visit);
55 }
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 fn parse(json: &str) -> UrlInputConfig {
63 serde_json::from_str(json).unwrap()
64 }
65
66 #[test]
69 fn pause_linger_accepts_both_spellings() {
70 for (json, expected) in [
71 (r#"{"path": "http://x"}"#, DEFAULT_PAUSE_TIMEOUT),
72 (
73 r#"{"path": "http://x", "pause_linger": "5m"}"#,
74 ConfigDuration::from_secs(300),
75 ),
76 (
77 r#"{"path": "http://x", "pause_timeout": 10}"#,
78 ConfigDuration::from_secs(10),
79 ),
80 ] {
81 assert_eq!(parse(json).pause_linger(), expected, "parsing {json}");
82 }
83 }
84
85 #[test]
86 fn unset_fields_do_not_serialize() {
87 let json = serde_json::to_string(&parse(r#"{"path": "http://x"}"#)).unwrap();
88 assert_eq!(json, r#"{"path":"http://x"}"#);
89 }
90}