cat_gateway/settings/signed_doc.rs
1//! Command line and environment variable settings for the Catalyst Signed Docs
2
3use std::time::Duration;
4
5use super::str_env_var::StringEnvVar;
6
7/// Default number value of `future_threshold`, 30 seconds.
8const DEFAULT_FUTURE_THRESHOLD: Duration = Duration::from_secs(30);
9
10/// Default number value of `past_threshold`, 10 minutes.
11const DEFAULT_PAST_THRESHOLD: Duration = Duration::from_secs(60 * 10);
12
13/// Configuration for the Catalyst Signed Documents validation configuration.
14#[derive(Clone)]
15pub(crate) struct EnvVars {
16 /// The Catalyst Signed Document threshold, document cannot be too far in the future.
17 future_threshold: Duration,
18
19 /// The Catalyst Signed Document threshold, document cannot be too far behind.
20 past_threshold: Duration,
21}
22
23impl EnvVars {
24 /// Create a config for Catalyst Signed Document validation configuration.
25 pub(super) fn new() -> Self {
26 let future_threshold =
27 StringEnvVar::new_as_duration("SIGNED_DOC_FUTURE_THRESHOLD", DEFAULT_FUTURE_THRESHOLD);
28
29 let past_threshold =
30 StringEnvVar::new_as_duration("SIGNED_DOC_PAST_THRESHOLD", DEFAULT_PAST_THRESHOLD);
31
32 Self {
33 future_threshold,
34 past_threshold,
35 }
36 }
37
38 /// The Catalyst Signed Document threshold, document cannot be too far in the future
39 /// (in seconds).
40 pub(crate) fn future_threshold(&self) -> Duration {
41 self.future_threshold
42 }
43
44 /// The Catalyst Signed Document threshold, document cannot be too far behind
45 /// (in seconds).
46 pub(crate) fn past_threshold(&self) -> Duration {
47 self.past_threshold
48 }
49}