bearcat 1.5.0.beta1 → 1.5.0.beta3

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: dfa0e208c1e9c27cf47f857f4830167fe833c966cb96eebfb3df5b9edcc1d407
4
- data.tar.gz: 2a06fb44fbbf24b35be34943782aaedb6357d1a98b6031a9ce2cc24a8be91801
3
+ metadata.gz: 830e59c042dbbc2af216f866ac9256836fddd0162a8fd007d3688251a640cfd9
4
+ data.tar.gz: f7bb5edaae3618574f53e31c648e284e9b20259ab213bea0418a9b02fd91244c
5
5
  SHA512:
6
- metadata.gz: 9f78f3fe0c128b86553b7748e58fd17e4ccbe124709c6bf7d1446781f7fdb1f758577d181d4957925a7b006c6e09ec43ca7616bc6f696d5b678e7f8bd253505a
7
- data.tar.gz: 736439d3fe242e26c77389230ab7e262c98de5b7f0802cd4a5bc061f178b4f24f90b342b339c5e5852eae75c462c799202b130d67f4d16c87045508593eb76c1
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) }
@@ -16,7 +16,7 @@ module Bearcat::SpecHelpers
16
16
  # Accepts optional keyword parameters to interpolate specific values into the URL.
17
17
  # Returns a mostly-normal Webmock stub (:to_return has been overridden to allow :body to be set to a Hash)
18
18
  def stub_bearcat(endpoint, prefix: nil, method: :auto, **kwargs)
19
- cfg = _bearcat_resolve_config(endpoint, method: method)
19
+ cfg = _bearcat_resolve_config(endpoint, kwargs, method: method)
20
20
 
21
21
  url = Regexp.escape(_bearcat_resolve_prefix(prefix)) + cfg[:url]
22
22
  stub = stub_request(cfg[:method], Regexp.new(url))
@@ -1,3 +1,3 @@
1
1
  module Bearcat
2
- VERSION = '1.5.0.beta1' 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.beta1
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-02-15 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