gitlab-labkit 4.1.0 → 4.1.1
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 +4 -4
- data/lib/labkit/rate_limit/identifier.rb +26 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 809ee7b1894b9ff60755556cb95f69d9dca501297077e5eb1ddadac9d5d2b492
|
|
4
|
+
data.tar.gz: 48d5598c40eefcd144ed435f0e0fafa7a2e1dffa305830e6f7bf1a4ce5e71d1e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7081e60adc3b7d3929b83949710758c6af3ed04dca87337006637d7c4a1f90e6261c817bf0eae1a2ca5644763b25ee9896f06ff440670fadd1e675a64effec29
|
|
7
|
+
data.tar.gz: eb903367e7296978188ca66f9affb82a543ee9342938934f8ea817f49bb7a843920e570279d03d727ae68d2cb8f73d3627b3c62715d806bac2c2f337a668e965
|
|
@@ -6,6 +6,9 @@ module Labkit
|
|
|
6
6
|
# describe the caller (e.g. user, ip, endpoint).
|
|
7
7
|
# Endpoint values are normalised at construction time (query string stripped).
|
|
8
8
|
class Identifier
|
|
9
|
+
InvalidKeyError = Class.new(ArgumentError)
|
|
10
|
+
DuplicateNormalizedKeyError = Class.new(InvalidKeyError)
|
|
11
|
+
|
|
9
12
|
# Normalize an endpoint value: strip query string.
|
|
10
13
|
def self.normalize_endpoint(value)
|
|
11
14
|
return value unless value.is_a?(String)
|
|
@@ -16,7 +19,29 @@ module Labkit
|
|
|
16
19
|
attr_reader :attributes
|
|
17
20
|
|
|
18
21
|
def initialize(attributes = {})
|
|
19
|
-
normalised =
|
|
22
|
+
normalised = {}
|
|
23
|
+
original_keys = {}
|
|
24
|
+
|
|
25
|
+
attributes.each do |key, value|
|
|
26
|
+
unless key.respond_to?(:to_sym)
|
|
27
|
+
# Reject keys such as nil, 42, and [] instead of leaking NoMethodError;
|
|
28
|
+
# identifiers must have a canonical symbol key for matching and serialization.
|
|
29
|
+
raise InvalidKeyError, "Identifier key #{key.inspect} must respond to #to_sym"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
normalised_key = key.to_sym
|
|
33
|
+
if normalised.key?(normalised_key)
|
|
34
|
+
# Reject { user: 1, "user" => 2 } (and its reverse order): silently
|
|
35
|
+
# choosing a value would make the rate-limit bucket insertion-order dependent.
|
|
36
|
+
raise DuplicateNormalizedKeyError,
|
|
37
|
+
"Identifier keys normalize to the same key #{normalised_key.inspect}: " \
|
|
38
|
+
"#{original_keys[normalised_key].inspect} and #{key.inspect}"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
original_keys[normalised_key] = key
|
|
42
|
+
normalised[normalised_key] = value
|
|
43
|
+
end
|
|
44
|
+
|
|
20
45
|
normalised[:endpoint] = self.class.normalize_endpoint(normalised[:endpoint]) if normalised.key?(:endpoint)
|
|
21
46
|
@attributes = normalised.freeze
|
|
22
47
|
end
|