1- use crate :: rate_limiter :: { LimitedAction , RateLimiterConfig } ;
1+ use crate :: publish_rate_limit :: PublishRateLimit ;
22use crate :: { env, env_optional, uploaders:: Uploader , Env } ;
3- use std:: collections:: HashMap ;
4- use std:: time:: Duration ;
53
64mod base;
75mod database_pools;
@@ -18,6 +16,7 @@ pub struct Server {
1816 pub gh_base_url : String ,
1917 pub max_upload_size : u64 ,
2018 pub max_unpack_size : u64 ,
19+ pub publish_rate_limit : PublishRateLimit ,
2120 pub blocked_traffic : Vec < ( String , Vec < String > ) > ,
2221 pub max_allowed_page_offset : u32 ,
2322 pub page_offset_ua_blocklist : Vec < String > ,
@@ -28,7 +27,6 @@ pub struct Server {
2827 pub metrics_authorization_token : Option < String > ,
2928 pub use_test_database_pool : bool ,
3029 pub instance_metrics_log_every_seconds : Option < u64 > ,
31- pub rate_limiter : HashMap < LimitedAction , RateLimiterConfig > ,
3230}
3331
3432impl Default for Server {
@@ -66,34 +64,12 @@ impl Default for Server {
6664 . split ( ',' )
6765 . map ( ToString :: to_string)
6866 . collect ( ) ;
69-
7067 let page_offset_ua_blocklist = match env_optional :: < String > ( "WEB_PAGE_OFFSET_UA_BLOCKLIST" )
7168 {
7269 None => vec ! [ ] ,
7370 Some ( s) if s. is_empty ( ) => vec ! [ ] ,
7471 Some ( s) => s. split ( ',' ) . map ( String :: from) . collect ( ) ,
7572 } ;
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-
9773 Server {
9874 db : DatabasePools :: full_from_environment ( ) ,
9975 base : Base :: from_environment ( ) ,
@@ -103,6 +79,7 @@ impl Default for Server {
10379 gh_base_url : "https://api.github.com" . to_string ( ) ,
10480 max_upload_size : 10 * 1024 * 1024 , // 10 MB default file upload size limit
10581 max_unpack_size : 512 * 1024 * 1024 , // 512 MB max when decompressed
82+ publish_rate_limit : Default :: default ( ) ,
10683 blocked_traffic : blocked_traffic ( ) ,
10784 max_allowed_page_offset : env_optional ( "WEB_MAX_ALLOWED_PAGE_OFFSET" ) . unwrap_or ( 200 ) ,
10885 page_offset_ua_blocklist,
@@ -119,7 +96,6 @@ impl Default for Server {
11996 metrics_authorization_token : dotenv:: var ( "METRICS_AUTHORIZATION_TOKEN" ) . ok ( ) ,
12097 use_test_database_pool : false ,
12198 instance_metrics_log_every_seconds : env_optional ( "INSTANCE_METRICS_LOG_EVERY_SECONDS" ) ,
122- rate_limiter,
12399 }
124100 }
125101}
0 commit comments