Skip to content

Commit d2f19a1

Browse files
committed
more feature split, ready to refactor into different modules now
1 parent 2731653 commit d2f19a1

File tree

6 files changed

+648
-505
lines changed

6 files changed

+648
-505
lines changed

questdb-rs/src/ingress/conf.rs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
*
2323
******************************************************************************/
2424

25-
use std::ops::Deref;
26-
2725
use crate::{Error, ErrorCode, Result};
26+
use std::ops::Deref;
2827

2928
/// Wraps a SenderBuilder config setting with the intent of tracking
3029
/// whether the value was user-specified or defaulted.
@@ -73,3 +72,81 @@ impl<T: PartialEq> Deref for ConfigSetting<T> {
7372
}
7473
}
7574
}
75+
76+
#[cfg(feature = "_sender-http")]
77+
#[derive(Debug, Clone)]
78+
pub(crate) struct HttpConfig {
79+
pub(crate) request_min_throughput: ConfigSetting<u64>,
80+
pub(crate) user_agent: String,
81+
pub(crate) retry_timeout: ConfigSetting<std::time::Duration>,
82+
pub(crate) request_timeout: ConfigSetting<std::time::Duration>,
83+
}
84+
85+
#[cfg(feature = "_sender-http")]
86+
impl Default for HttpConfig {
87+
fn default() -> Self {
88+
Self {
89+
request_min_throughput: ConfigSetting::new_default(102400), // 100 KiB/s
90+
user_agent: concat!("questdb/rust/", env!("CARGO_PKG_VERSION")).to_string(),
91+
retry_timeout: ConfigSetting::new_default(std::time::Duration::from_secs(10)),
92+
request_timeout: ConfigSetting::new_default(std::time::Duration::from_secs(10)),
93+
}
94+
}
95+
}
96+
97+
#[cfg(feature = "_sender-http")]
98+
#[derive(PartialEq, Debug, Clone)]
99+
pub(crate) struct BasicAuthParams {
100+
pub(crate) username: String,
101+
pub(crate) password: String,
102+
}
103+
104+
#[cfg(feature = "_sender-http")]
105+
impl BasicAuthParams {
106+
pub(crate) fn to_header_string(&self) -> String {
107+
use base64ct::{Base64, Encoding};
108+
let pair = format!("{}:{}", self.username, self.password);
109+
let encoded = Base64::encode_string(pair.as_bytes());
110+
format!("Basic {encoded}")
111+
}
112+
}
113+
114+
#[cfg(feature = "_sender-http")]
115+
#[derive(PartialEq, Debug, Clone)]
116+
pub(crate) struct TokenAuthParams {
117+
pub(crate) token: String,
118+
}
119+
120+
#[cfg(feature = "_sender-http")]
121+
impl TokenAuthParams {
122+
pub(crate) fn to_header_string(&self) -> crate::Result<String> {
123+
if self.token.contains('\n') {
124+
return Err(crate::error::fmt!(
125+
AuthError,
126+
"Bad auth token: Should not contain new-line char."
127+
));
128+
}
129+
Ok(format!("Bearer {}", self.token))
130+
}
131+
}
132+
133+
#[cfg(feature = "_sender-tcp")]
134+
#[derive(PartialEq, Debug, Clone)]
135+
pub(crate) struct EcdsaAuthParams {
136+
pub(crate) key_id: String,
137+
pub(crate) priv_key: String,
138+
pub(crate) pub_key_x: String,
139+
pub(crate) pub_key_y: String,
140+
}
141+
142+
#[derive(PartialEq, Debug, Clone)]
143+
pub(crate) enum AuthParams {
144+
#[cfg(feature = "_sender-tcp")]
145+
Ecdsa(EcdsaAuthParams),
146+
147+
#[cfg(feature = "_sender-http")]
148+
Basic(BasicAuthParams),
149+
150+
#[cfg(feature = "_sender-http")]
151+
Token(TokenAuthParams),
152+
}

0 commit comments

Comments
 (0)