22
33use crate :: config;
44use crate :: db:: { ConnectionConfig , connection_url, make_manager_config} ;
5+ use std:: collections:: HashMap ;
56use std:: sync:: Arc ;
67
78use crate :: email:: Emails ;
89use crate :: metrics:: { InstanceMetrics , ServiceMetrics } ;
9- use crate :: rate_limiter:: RateLimiter ;
10+ use crate :: rate_limiter:: { LimitedAction , RateLimiter , RateLimiterConfig } ;
1011use crate :: storage:: { Storage , StorageConfig } ;
1112use axum:: extract:: { FromRef , FromRequestParts , State } ;
1213use bon:: Builder ;
@@ -152,6 +153,16 @@ impl<S: app_builder::State> AppBuilder<S> {
152153 {
153154 self . storage ( Arc :: new ( Storage :: from_config ( config) ) )
154155 }
156+
157+ pub fn rate_limiter_from_config (
158+ self ,
159+ config : HashMap < LimitedAction , RateLimiterConfig > ,
160+ ) -> AppBuilder < app_builder:: SetRateLimiter < S > >
161+ where
162+ S :: RateLimiter : app_builder:: IsUnset ,
163+ {
164+ self . rate_limiter ( RateLimiter :: new ( config) )
165+ }
155166}
156167
157168impl App {
@@ -169,7 +180,7 @@ impl App {
169180 . github_oauth_from_config ( & config)
170181 . emails ( emails)
171182 . storage_from_config ( & config. storage )
172- . rate_limiter ( RateLimiter :: new ( config. rate_limiter . clone ( ) ) )
183+ . rate_limiter_from_config ( config. rate_limiter . clone ( ) )
173184 . config ( Arc :: new ( config) )
174185 . build ( )
175186 }
0 commit comments