diff --git a/backend/deps.edn b/backend/deps.edn index b9d837bab..efdc4ed55 100644 --- a/backend/deps.edn +++ b/backend/deps.edn @@ -29,9 +29,6 @@ {:local/root "vendor/sodi" :deps/manifest :pom} - io.github.resilience4j/resilience4j-core {:mvn/version "1.2.0"} - io.github.resilience4j/resilience4j-ratelimiter {:mvn/version "1.2.0"} - lambdaisland/uri {:mvn/version "1.1.0"} danlentz/clj-uuid {:mvn/version "0.1.9"} diff --git a/backend/src/uxbox/http.clj b/backend/src/uxbox/http.clj index f4098841a..56401e141 100644 --- a/backend/src/uxbox/http.clj +++ b/backend/src/uxbox/http.clj @@ -16,7 +16,6 @@ [uxbox.http.session :as session] [uxbox.http.handlers :as handlers] [uxbox.http.debug :as debug] - [uxbox.http.ratelimit :as rl] [uxbox.http.ws :as ws] [vertx.core :as vc] [vertx.http :as vh] @@ -38,12 +37,6 @@ interceptors/format-response-body (vxi/errors errors/handle)] - login-handler (rl/ratelimit handlers/login-handler - {:limit 10 - :period 1000 - :timeout 200 - :name "login-handler"}) - routes [["/sub/:file-id" {:interceptors [(vxi/cookies) (vxi/cors cors-opts) interceptors/format-response-body @@ -52,7 +45,7 @@ ["/api" {:interceptors interceptors} ["/echo" {:all handlers/echo-handler}] - ["/login" {:post login-handler}] + ["/login" {:post handlers/login-handler}] ["/logout" {:post handlers/logout-handler}] ["/debug" ["/emails" {:get debug/emails-list}] diff --git a/backend/src/uxbox/http/ratelimit.clj b/backend/src/uxbox/http/ratelimit.clj deleted file mode 100644 index f465c81c4..000000000 --- a/backend/src/uxbox/http/ratelimit.clj +++ /dev/null @@ -1,50 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; This Source Code Form is "Incompatible With Secondary Licenses", as -;; defined by the Mozilla Public License, v. 2.0. -;; -;; Copyright (c) 2016-2019 Andrey Antukh - -(ns uxbox.http.ratelimit - "Rate limit" - (:require - [clojure.spec.alpha :as s] - [uxbox.common.exceptions :as ex] - [uxbox.core :refer [system]] - [vertx.core :as vc] - [promesa.core :as p] - [promesa.exec :as pe]) - (:import - io.github.resilience4j.ratelimiter.RateLimiter - io.github.resilience4j.ratelimiter.RateLimiterConfig - io.github.resilience4j.ratelimiter.RateLimiterRegistry - java.util.concurrent.CompletableFuture - java.util.function.Supplier - java.time.Duration)) - -;; --- Rate Limiter - -(def ^:private registry (RateLimiterRegistry/ofDefaults)) - -(defn- opts->rate-limiter-config - [{:keys [limit period timeout] :as opts}] - (let [custom (RateLimiterConfig/custom)] - (.limitRefreshPeriod custom (Duration/ofMillis period)) - (.limitForPeriod custom limit) - (.timeoutDuration custom (Duration/ofMillis timeout)) - (.build custom))) - -(defn ratelimit - [f {:keys [name] :as opts}] - (let [config (opts->rate-limiter-config opts) - rl (.rateLimiter registry name config)] - (fn [& args] - (let [ctx (vc/get-or-create-context system)] - (-> (pe/run! #(when-not (.acquirePermission rl 1) - (ex/raise :type :ratelimit - :code :timeout - :context {:name name}))) - (vc/handle-on-context) - (p/bind (fn [_] (p/do! (apply f args)))))))))