mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-23 08:00:45 +00:00
9ff8a85af6
* refactor: extract windmill-api into 4 subcrates (api-auth, store, api-sse, api-jobs) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: eliminate refresh_token OnceLock bridge in windmill-store Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: eliminate FromRequestParts OnceLock bridge in windmill-api-auth Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: wire subcrates into workspace and clean up unused re-exports Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: resolve cargo check --all-features errors in subcrate wiring Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * sqlx * all * chore: update ee-repo-ref for warning fixes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: extract windmill-trigger crate and expand windmill-api-jobs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: extract windmill-trigger-kafka crate from windmill-api Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: extract windmill-trigger-postgres crate from windmill-api Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: extract windmill-trigger-websocket and windmill-trigger-mqtt crates Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: extract windmill-trigger-nats, sqs, gcp, and email crates Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: extract windmill-trigger-http crate from windmill-api Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: move token creation and permission helpers to windmill-api-auth Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: extract windmill-native-triggers crate from windmill-api Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * sqlx * all * refactor: extract windmill-api-embeddings crate and fix CI warnings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: resolve type mismatch in oauth2_oss and remaining warnings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: use correct HTTP_CLIENT config in embeddings crate (30s timeout, cert override) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * all * fix: gate oauth_refresh_ee on oauth2 feature to fix warnings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * all --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
/*
|
|
* Author: Windmill Labs, Inc
|
|
* Copyright: Windmill Labs, Inc 2024
|
|
* This file and its contents are licensed under the AGPLv3 License.
|
|
* Please see the included NOTICE for copyright information and
|
|
* LICENSE-AGPL for a copy of the license.
|
|
*/
|
|
|
|
use chrono::Utc;
|
|
use dashmap::DashMap;
|
|
use hyper::StatusCode;
|
|
use std::sync::LazyLock;
|
|
use windmill_common::error::{Error, Result};
|
|
|
|
struct RateLimitEntry {
|
|
count: i32,
|
|
minute_bucket: i64,
|
|
}
|
|
|
|
static RATE_LIMIT_COUNTER: LazyLock<DashMap<String, RateLimitEntry>> = LazyLock::new(DashMap::new);
|
|
|
|
pub fn check_and_increment(workspace_id: &str, limit: i32) -> Result<()> {
|
|
let current_minute = Utc::now().timestamp() / 60;
|
|
|
|
let mut entry = RATE_LIMIT_COUNTER
|
|
.entry(workspace_id.to_string())
|
|
.or_insert(RateLimitEntry { count: 0, minute_bucket: current_minute });
|
|
|
|
if entry.minute_bucket != current_minute {
|
|
entry.count = 0;
|
|
entry.minute_bucket = current_minute;
|
|
}
|
|
|
|
if entry.count >= limit {
|
|
return Err(Error::Generic(
|
|
StatusCode::TOO_MANY_REQUESTS,
|
|
format!(
|
|
"Rate limit exceeded for public app executions in workspace '{}'. \
|
|
Limit: {} per minute per server.",
|
|
workspace_id, limit
|
|
),
|
|
));
|
|
}
|
|
|
|
entry.count += 1;
|
|
Ok(())
|
|
}
|