Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
86b0e0ab
Commit
86b0e0ab
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
3429fb62
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/api/common/throttle.clj
+5
-5
5 additions, 5 deletions
src/metabase/api/common/throttle.clj
with
5 additions
and
5 deletions
src/metabase/api/common/throttle.clj
+
5
−
5
View file @
86b0e0ab
...
...
@@ -51,7 +51,7 @@
(
defrecord
Throttler
[
;; Name of the API field/value being checked. Used to generate appropriate API error messages, so they'll be displayed in the
;; right part of the screen
^
Keyword
field-
name
^
Keyword
exception-
field-
key
;; [Internal] List of attempt entries. These are pairs of [key timestamp (ms)], e.g. ["cam@metabase.com" 1438045261132]
^
Atom
attempts
;; Amount of time to keep an entry in ATTEMPTS before dropping it.
...
...
@@ -91,9 +91,9 @@
(require '[metabase.api.common.throttle :as throttle])
(def email-throttler (throttle/make-throttler :attempts-threshold 10))"
[
field-
name
&
{
:as
kwargs
}]
[
exception-
field-
key
&
{
:as
kwargs
}]
(
map->Throttler
(
merge
throttler-defaults
kwargs
{
:attempts
(
atom
'
())
:
field-name
field-
name
})))
:
exception-field-key
exception-
field-
key
})))
(
defn
check
"Throttle an API call based on values of KEYY. Each call to this function will record KEYY to THROTTLER's internal list;
...
...
@@ -102,7 +102,7 @@
(defendpoint POST [:as {{:keys [email]} :body}]
(throttle/check email-throttler email)
...)"
[
^
Throttler
{
:keys
[
attempts
field-
name
]
,
:as
throttler
}
keyy
]
[
^
Throttler
{
:keys
[
attempts
exception-
field-
key
]
,
:as
throttler
}
keyy
]
{
:pre
[(
or
(
=
(
type
throttler
)
Throttler
)
(
println
"THROTTLER IS: "
(
type
throttler
)))
keyy
]}
...
...
@@ -111,7 +111,7 @@
(
when-let
[
delay-ms
(
calculate-delay
throttler
keyy
)]
(
let
[
message
(
format
"Too many attempts! You must wait %d seconds before trying again."
(
int
(
math/round
(
/
delay-ms
1000
))))]
(
throw
(
ex-info
message
{
:status-code
400
:errors
{
field-
name
message
}}))))
:errors
{
exception-
field-
key
message
}}))))
(
swap!
attempts
conj
[
keyy
(
System/currentTimeMillis
)]))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment