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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2006ee9fbf6cdd11b7e35588aa56f475349a03bbe56ce7f02a32e8f2bb62b82b
4
- data.tar.gz: 8d9210051eeeb0316d03a3883600dc166d88b0131f01ddafd3f93ea4213055bc
3
+ metadata.gz: 809ee7b1894b9ff60755556cb95f69d9dca501297077e5eb1ddadac9d5d2b492
4
+ data.tar.gz: 48d5598c40eefcd144ed435f0e0fafa7a2e1dffa305830e6f7bf1a4ce5e71d1e
5
5
  SHA512:
6
- metadata.gz: 98a57b3f123c8c0e1338079e427bd6a03c50493dff5b3ef9c738138cb9132d389ad5170458b0dc4814dd450d603856e859f200be2e473c7b8031f56a45626614
7
- data.tar.gz: fe6a91ad6fa0db7f44dc6954240a5137a6f7f88e17fee2fd14c4eafa283a3b8f04516a05a451d94c9d772eb0aa4a1265e5d5bd38b40a2595ec9d5a81b2d89e59
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 = attributes.transform_keys(&:to_sym)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-labkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate