Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alan Marchiori
labtool
Commits
95587e2e
Commit
95587e2e
authored
Jan 11, 2022
by
alan
Browse files
fixed time calc
parent
3f1e5f19
Changes
2
Hide whitespace changes
Inline
Side-by-side
config/__init__.py
View file @
95587e2e
...
...
@@ -55,4 +55,4 @@ crypto_pkey = b"It's really ten years into the future."
#mongodb_pass =
# logging server
labtool_url
=
"http://localhost:3939"
\ No newline at end of file
labtool_url
=
"http://linuxremote3.bucknell.edu:3939"
\ No newline at end of file
utils/ratelimit.py
View file @
95587e2e
...
...
@@ -20,13 +20,13 @@ def reset_limits(cmd, username, labstr):
return
r
.
json
()
def
is_rate_limited
(
cmd
=
"test"
,
short
=
3
,
max
=
10
,
short_period
=
timedelta
(
minutes
=
15
),
**
kwargs
):
def
is_rate_limited
(
cmd
=
"test"
,
short
=
3
,
max
_calls
=
10
,
short_period
=
timedelta
(
minutes
=
15
),
**
kwargs
):
""""Returns true if this call exceeds the rate limits for the given kwargs
Arguments
---------
short is the maximum number of calls in the short_period.
max
is the maximum number of calls ever.
short
is the maximum number of calls in the short_period.
max
_calls
is the maximum number of calls ever.
"""
# add to kwargs
kwargs
[
'cmd'
]
=
cmd
...
...
@@ -54,19 +54,19 @@ def is_rate_limited(cmd="test", short=3, max=10, short_period=timedelta(minutes=
#print(f"have {len(dates)}, short are {len(sh_dates)}")
#print([str(now-x) for x in dates])
if
len
(
dates
)
>=
max
:
error
(
f
"Maximum
{
cmd
}
limit (
{
max
}
) reached."
)
if
len
(
dates
)
>=
max
_calls
:
error
(
f
"Maximum
{
cmd
}
limit (
{
max
_calls
}
) reached."
)
return
True
if
len
(
sh_dates
)
>=
short
:
error
(
f
"Maximum
{
cmd
}
limit (
{
short
}
) in the last
{
short_period
.
total_seconds
()
/
60
}
minutes reached."
)
error
(
f
"You can try again in
{
short_period
-
(
now
-
dates
[
0
]
)
}
."
)
error
(
f
"You can try again in
{
short_period
-
(
now
-
max
(
dates
)
)
}
."
)
return
True
if
len
(
sh_dates
)
>
0
:
warn
(
f
"You have already used
{
len
(
sh_dates
)
}
of
{
short
}
checks in the last
{
short_period
.
total_seconds
()
/
60
}
minutes!"
)
if
len
(
dates
)
>=
max
/
2
:
warn
(
f
"You have already used
{
len
(
dates
)
}
of
{
max
}
total checks!"
)
if
len
(
dates
)
>=
max
_calls
/
2
:
warn
(
f
"You have already used
{
len
(
dates
)
}
of
{
max
_calls
}
total checks!"
)
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment