bearcat 1.5.0.beta2 → 1.5.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eebb8dddf4346967e2667d229aaeb7f6f8e952d179374fd031409ceaf454f162
4
- data.tar.gz: fd7aa76b7318d0d884efc2e33551c3cee467ccbf81c4a8497e6c83dd4d2e3664
3
+ metadata.gz: 830e59c042dbbc2af216f866ac9256836fddd0162a8fd007d3688251a640cfd9
4
+ data.tar.gz: f7bb5edaae3618574f53e31c648e284e9b20259ab213bea0418a9b02fd91244c
5
5
  SHA512:
6
- metadata.gz: b22779cb1c4ded1d20efb675c0d554ddbc4ad773d5708b5ef3729bdc49fc5bbff9b82f4cb004fcef28a31d9648024e9fbf5a98295ba9ab7630c9c7daa28b0c80
7
- data.tar.gz: 4b135c91ed60ba46adbcb4035940afc33b862f1bb1b623c2bda7a0adfc4d907f63298be9419b7af23f79b69127d3f94a100dd931360cdf533b6bf8de4a70407a
6
+ metadata.gz: 3a8d5b6ccf14fbd6300f1779ea86910421ac0d9b3df38598327cd2b6a4fa3ac1e160f1f1324a7583f37e24de8a75deb74d14d480f1a8f89759ed6b2ce7c5dac7
7
+ data.tar.gz: e8e7aecf6176f92745c32d5e2722176654298fd67593030245da304beb605eb3165d50b7d930e5983d226e8f4ddda93a8471919a768c32613fa3cd9e66c95b89
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/**/*.rb")
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) }
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.5.0.beta2' unless defined?(Bearcat::VERSION)
2
+ VERSION = '1.5.0.beta3' unless defined?(Bearcat::VERSION)
3
3
  end
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.beta2
4
+ version: 1.5.0.beta3
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-24 00:00:00.000000000 Z
11
+ date: 2023-03-28 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