Skip to content

Commit 9453122

Browse files
committed
feat(config): add rate limit configuration parameters
- Introduce new environment variables for request-code and data API rate limiting - Implement getters for rate limit parameters with default values - Add documentation for new configuration options
1 parent f09468f commit 9453122

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/src/config/environment_config.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,37 @@ abstract final class EnvironmentConfig {
139139
/// This is used to set or replace the single administrator account on startup.
140140
/// Returns `null` if the `OVERRIDE_ADMIN_EMAIL` is not set.
141141
static String? get overrideAdminEmail => _env['OVERRIDE_ADMIN_EMAIL'];
142+
143+
/// Retrieves the request limit for the request-code endpoint.
144+
///
145+
/// Defaults to 3 if not set or if parsing fails.
146+
static int get rateLimitRequestCodeLimit {
147+
return int.tryParse(_env['RATE_LIMIT_REQUEST_CODE_LIMIT'] ?? '3') ?? 3;
148+
}
149+
150+
/// Retrieves the time window for the request-code endpoint rate limit.
151+
///
152+
/// Defaults to 24 hours if not set or if parsing fails.
153+
static Duration get rateLimitRequestCodeWindow {
154+
final hours =
155+
int.tryParse(_env['RATE_LIMIT_REQUEST_CODE_WINDOW_HOURS'] ?? '24') ??
156+
24;
157+
return Duration(hours: hours);
158+
}
159+
160+
/// Retrieves the request limit for the data API endpoints.
161+
///
162+
/// Defaults to 1000 if not set or if parsing fails.
163+
static int get rateLimitDataApiLimit {
164+
return int.tryParse(_env['RATE_LIMIT_DATA_API_LIMIT'] ?? '1000') ?? 1000;
165+
}
166+
167+
/// Retrieves the time window for the data API rate limit.
168+
///
169+
/// Defaults to 60 minutes if not set or if parsing fails.
170+
static Duration get rateLimitDataApiWindow {
171+
final minutes =
172+
int.tryParse(_env['RATE_LIMIT_DATA_API_WINDOW_MINUTES'] ?? '60') ?? 60;
173+
return Duration(minutes: minutes);
174+
}
142175
}

0 commit comments

Comments
 (0)