1
- use crate :: rate_limiter :: { LimitedAction , RateLimiterConfig } ;
1
+ use crate :: publish_rate_limit :: PublishRateLimit ;
2
2
use crate :: { env, env_optional, uploaders:: Uploader , Env } ;
3
- use std:: collections:: HashMap ;
4
- use std:: time:: Duration ;
5
3
6
4
mod base;
7
5
mod database_pools;
@@ -18,6 +16,7 @@ pub struct Server {
18
16
pub gh_base_url : String ,
19
17
pub max_upload_size : u64 ,
20
18
pub max_unpack_size : u64 ,
19
+ pub publish_rate_limit : PublishRateLimit ,
21
20
pub blocked_traffic : Vec < ( String , Vec < String > ) > ,
22
21
pub max_allowed_page_offset : u32 ,
23
22
pub page_offset_ua_blocklist : Vec < String > ,
@@ -28,7 +27,6 @@ pub struct Server {
28
27
pub metrics_authorization_token : Option < String > ,
29
28
pub use_test_database_pool : bool ,
30
29
pub instance_metrics_log_every_seconds : Option < u64 > ,
31
- pub rate_limiter : HashMap < LimitedAction , RateLimiterConfig > ,
32
30
}
33
31
34
32
impl Default for Server {
@@ -66,34 +64,12 @@ impl Default for Server {
66
64
. split ( ',' )
67
65
. map ( ToString :: to_string)
68
66
. collect ( ) ;
69
-
70
67
let page_offset_ua_blocklist = match env_optional :: < String > ( "WEB_PAGE_OFFSET_UA_BLOCKLIST" )
71
68
{
72
69
None => vec ! [ ] ,
73
70
Some ( s) if s. is_empty ( ) => vec ! [ ] ,
74
71
Some ( s) => s. split ( ',' ) . map ( String :: from) . collect ( ) ,
75
72
} ;
76
-
77
- // Dynamically load the configuration for all the rate limiting actions. See
78
- // `src/rate_limiter.rs` for their definition.
79
- let mut rate_limiter = HashMap :: new ( ) ;
80
- for action in LimitedAction :: VARIANTS {
81
- rate_limiter. insert (
82
- * action,
83
- RateLimiterConfig {
84
- rate : Duration :: from_secs (
85
- env_optional ( & format ! (
86
- "RATE_LIMITER_{}_RATE_SECONDS" ,
87
- action. env_var_key( )
88
- ) )
89
- . unwrap_or_else ( || action. default_rate_seconds ( ) ) ,
90
- ) ,
91
- burst : env_optional ( & format ! ( "RATE_LIMITER_{}_BURST" , action. env_var_key( ) ) )
92
- . unwrap_or_else ( || action. default_burst ( ) ) ,
93
- } ,
94
- ) ;
95
- }
96
-
97
73
Server {
98
74
db : DatabasePools :: full_from_environment ( ) ,
99
75
base : Base :: from_environment ( ) ,
@@ -103,6 +79,7 @@ impl Default for Server {
103
79
gh_base_url : "https://api.github.com" . to_string ( ) ,
104
80
max_upload_size : 10 * 1024 * 1024 , // 10 MB default file upload size limit
105
81
max_unpack_size : 512 * 1024 * 1024 , // 512 MB max when decompressed
82
+ publish_rate_limit : Default :: default ( ) ,
106
83
blocked_traffic : blocked_traffic ( ) ,
107
84
max_allowed_page_offset : env_optional ( "WEB_MAX_ALLOWED_PAGE_OFFSET" ) . unwrap_or ( 200 ) ,
108
85
page_offset_ua_blocklist,
@@ -119,7 +96,6 @@ impl Default for Server {
119
96
metrics_authorization_token : dotenv:: var ( "METRICS_AUTHORIZATION_TOKEN" ) . ok ( ) ,
120
97
use_test_database_pool : false ,
121
98
instance_metrics_log_every_seconds : env_optional ( "INSTANCE_METRICS_LOG_EVERY_SECONDS" ) ,
122
- rate_limiter,
123
99
}
124
100
}
125
101
}
0 commit comments