|
1 |
| -use std::net::SocketAddr; |
2 |
| -use std::path::PathBuf; |
3 |
| -use std::time::Duration; |
4 |
| - |
5 | 1 | use config::{Environment, File};
|
6 | 2 | use derivative::Derivative;
|
7 | 3 | use serde::Deserialize;
|
| 4 | +use std::cmp::min; |
| 5 | +use std::fmt::{Debug, Formatter}; |
| 6 | +use std::net::SocketAddr; |
| 7 | +use std::path::PathBuf; |
| 8 | +use std::time::Duration; |
8 | 9 | use url::Url;
|
9 | 10 |
|
10 | 11 | #[derive(Deserialize, Derivative, Clone, PartialEq)]
|
11 | 12 | #[derivative(Debug)]
|
12 | 13 | pub struct Config {
|
13 | 14 | pub listen_address: SocketAddr,
|
14 | 15 | pub relayer_urls: Vec<Url>,
|
15 |
| - pub authorization_token: Option<String>, |
| 16 | + pub authorization_token: Option<AuthorizationToken>, |
16 | 17 | #[derivative(Debug = "ignore")]
|
17 | 18 | pub publish_keypair_path: PathBuf,
|
18 | 19 | #[serde(with = "humantime_serde", default = "default_publish_interval")]
|
19 | 20 | pub publish_interval_duration: Duration,
|
20 | 21 | pub history_service_url: Option<Url>,
|
21 | 22 | }
|
22 | 23 |
|
| 24 | +#[derive(Deserialize, Derivative, Clone, PartialEq)] |
| 25 | +pub struct AuthorizationToken(pub String); |
| 26 | + |
| 27 | +impl Debug for AuthorizationToken { |
| 28 | + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 29 | + let token_string = self.0.to_ascii_lowercase(); |
| 30 | + #[allow(clippy::string_slice, reason = "false positive")] |
| 31 | + let last_chars = &token_string[token_string.len() - min(4, token_string.len())..]; |
| 32 | + write!(f, "\"...{last_chars}\"") |
| 33 | + } |
| 34 | +} |
| 35 | + |
23 | 36 | fn default_publish_interval() -> Duration {
|
24 | 37 | Duration::from_micros(500)
|
25 | 38 | }
|
|
0 commit comments