bearcat 1.5.0.beta2 → 1.5.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ce46eee834b48d1cdcf925b6d4894b3852a963542c6ba4f3675a2abce0b4e42
|
4
|
+
data.tar.gz: a2f0cf50121f5fe2ae41a6ffcecff2ef69dbdebcf028250fc2300e2f60eb9e85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4070053e47e7b13cb78cebf9e33b6729d9702fa095dbcd02144b1383a705a8d8319c6cafda1bd20db23703a545569f54c5717fcbfa710bd353d971a186e91c4b
|
7
|
+
data.tar.gz: 463cc154f6d8df0fccd3cfaf4e571f5110e5712572db3a1313455319b055076bd6fd93f558a21bc0bb0daa54956c095243fa4be2fdb73def7085b8704d879009
|
data/bearcat.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.summary = %q{Canvas API}
|
18
18
|
|
19
19
|
gem.files = %w[Rakefile bearcat.gemspec]
|
20
|
-
gem.files += Dir.glob("lib
|
20
|
+
gem.files += Dir.glob("lib/**/*")
|
21
21
|
gem.files += Dir.glob("spec/**/*")
|
22
22
|
gem.test_files = Dir.glob("spec/**/*")
|
23
23
|
gem.name = "bearcat"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!lua name=bearcat_rate_limiting
|
2
|
+
|
3
|
+
local function checkin_time(keys, args)
|
4
|
+
local return_time = args[1]
|
5
|
+
local true_remaining = args[2]
|
6
|
+
|
7
|
+
local hash = keys[1]
|
8
|
+
return redis.call('HGET', hash, '_last_modified_')
|
9
|
+
end
|
10
|
+
|
11
|
+
redis.register_function('my_hset', my_hset)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
local cache_key = KEYS[1]
|
2
|
+
|
3
|
+
local amount = tonumber(ARGV[1])
|
4
|
+
local current_time = tonumber(ARGV[2])
|
5
|
+
local outflow = tonumber(ARGV[3])
|
6
|
+
local maximum = tonumber(ARGV[4])
|
7
|
+
|
8
|
+
local leak = function(count, last_touched, current_time, outflow)
|
9
|
+
if count > 0 then
|
10
|
+
local timespan = current_time - last_touched
|
11
|
+
local loss = outflow * timespan
|
12
|
+
if loss > 0 then
|
13
|
+
count = count - loss
|
14
|
+
end
|
15
|
+
end
|
16
|
+
return count, last_touched
|
17
|
+
end
|
18
|
+
|
19
|
+
local count, last_touched = unpack(redis.call('HMGET', cache_key, 'count', 'timestamp'))
|
20
|
+
count = tonumber(count or 0)
|
21
|
+
last_touched = tonumber(last_touched or current_time)
|
22
|
+
|
23
|
+
count, last_touched = leak(count, last_touched, current_time, outflow)
|
24
|
+
if count < 0 then count = 0 end
|
25
|
+
|
26
|
+
count = count + amount
|
27
|
+
if count < 0 then count = 0 end
|
28
|
+
if count > maximum then count = maximum end
|
29
|
+
|
30
|
+
redis.call('HMSET', cache_key, 'count', count, 'timestamp', current_time)
|
31
|
+
redis.call('EXPIRE', cache_key, 600)
|
32
|
+
|
33
|
+
return { tostring(count), tostring(current_time) }
|
data/lib/bearcat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bearcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.0.
|
4
|
+
version: 1.5.0.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Mills, Jake Sorce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -180,6 +180,8 @@ files:
|
|
180
180
|
- lib/bearcat/client/users.rb
|
181
181
|
- lib/bearcat/client_module.rb
|
182
182
|
- lib/bearcat/rate_limiting.rb
|
183
|
+
- lib/bearcat/rate_limiting/functions.lua
|
184
|
+
- lib/bearcat/rate_limiting/increment_bucket.lua
|
183
185
|
- lib/bearcat/rate_limiting/redis_script.rb
|
184
186
|
- lib/bearcat/spec_helpers.rb
|
185
187
|
- lib/bearcat/version.rb
|