cat_gateway/settings/
rbac.rs

1//! Command line and environment variable settings for RBAC.
2
3use super::str_env_var::StringEnvVar;
4
5/// A default value of `persistent_chains_cache_size`.
6const DEFAULT_PERSISTENT_CHAINS_CACHE_SIZE: u64 = 1000;
7
8/// A default value of `persistent_transactions_cache_size`.
9const DEFAULT_PERSISTENT_TRANSACTIONS_CACHE_SIZE: u64 = 1000;
10
11/// A default value of `volatile_transactions_cache_size`.
12const DEFAULT_VOLATILE_TRANSACTIONS_CACHE_SIZE: u64 = 200;
13
14/// A default value of `persistent_stake_addresses_cache_size`.
15const DEFAULT_PERSISTENT_STAKE_ADDRESSES_CACHE_SIZE: u64 = 1000;
16
17/// A default value of `volatile_stake_addresses_cache_size`.
18const DEFAULT_VOLATILE_STAKE_ADDRESSES_CACHE_SIZE: u64 = 200;
19
20/// A default value of `persistent_pub_keys_cache_size`.
21const DEFAULT_PERSISTENT_PUB_KEYS_CACHE_SIZE: u64 = 1000;
22
23/// A default value of `volatile_pub_keys_cache_size`.
24const DEFAULT_VOLATILE_PUB_KEYS_CACHE_SIZE: u64 = 200;
25
26/// RBAC related configuration options.
27// TODO: Remove when used.
28#[allow(unused)]
29#[allow(clippy::struct_field_names)]
30#[derive(Clone)]
31pub struct EnvVars {
32    /// A maximum size of the persistent RBAC registration chains cache.
33    pub persistent_chains_cache_size: u64,
34
35    /// A maximum size of the persistent RBAC transactions cache.
36    pub persistent_transactions_cache_size: u64,
37
38    /// A maximum size of the volatile RBAC transactions cache.
39    pub volatile_transactions_cache_size: u64,
40
41    /// A maximum size of the persistent stake addresses cache.
42    pub persistent_stake_addresses_cache_size: u64,
43
44    /// A maximum size of the volatile stake addresses cache.
45    pub volatile_stake_addresses_cache_size: u64,
46
47    /// A maximum size of the persistent public keys cache.
48    pub persistent_pub_keys_cache_size: u64,
49
50    /// A maximum size of the volatile public keys cache.
51    pub volatile_pub_keys_cache_size: u64,
52}
53
54impl EnvVars {
55    /// Create a config for Catalyst Signed Document validation configuration.
56    pub(super) fn new() -> Self {
57        let persistent_chains_cache_size = StringEnvVar::new_as_int(
58            "RBAC_PERSISTENT_CHAINS_CACHE_SIZE",
59            DEFAULT_PERSISTENT_CHAINS_CACHE_SIZE,
60            0,
61            u64::MAX,
62        );
63
64        let persistent_transactions_cache_size = StringEnvVar::new_as_int(
65            "RBAC_PERSISTENT_TRANSACTIONS_CACHE_SIZE",
66            DEFAULT_PERSISTENT_TRANSACTIONS_CACHE_SIZE,
67            0,
68            u64::MAX,
69        );
70        let volatile_transactions_cache_size = StringEnvVar::new_as_int(
71            "RBAC_VOLATILE_TRANSACTIONS_CACHE_SIZE",
72            DEFAULT_VOLATILE_TRANSACTIONS_CACHE_SIZE,
73            0,
74            u64::MAX,
75        );
76
77        let persistent_stake_addresses_cache_size = StringEnvVar::new_as_int(
78            "RBAC_PERSISTENT_STAKE_ADDRESSES_CACHE_SIZE",
79            DEFAULT_PERSISTENT_STAKE_ADDRESSES_CACHE_SIZE,
80            0,
81            u64::MAX,
82        );
83        let volatile_stake_addresses_cache_size = StringEnvVar::new_as_int(
84            "RBAC_VOLATILE_STAKE_ADDRESSES_CACHE_SIZE",
85            DEFAULT_VOLATILE_STAKE_ADDRESSES_CACHE_SIZE,
86            0,
87            u64::MAX,
88        );
89
90        let persistent_pub_keys_cache_size = StringEnvVar::new_as_int(
91            "RBAC_PERSISTENT_PUB_KEYS_CACHE_SIZE",
92            DEFAULT_PERSISTENT_PUB_KEYS_CACHE_SIZE,
93            0,
94            u64::MAX,
95        );
96        let volatile_pub_keys_cache_size = StringEnvVar::new_as_int(
97            "RBAC_VOLATILE_PUB_KEYS_CACHE_SIZE",
98            DEFAULT_VOLATILE_PUB_KEYS_CACHE_SIZE,
99            0,
100            u64::MAX,
101        );
102
103        Self {
104            persistent_chains_cache_size,
105            persistent_transactions_cache_size,
106            volatile_transactions_cache_size,
107            persistent_stake_addresses_cache_size,
108            volatile_stake_addresses_cache_size,
109            persistent_pub_keys_cache_size,
110            volatile_pub_keys_cache_size,
111        }
112    }
113}