gitlab-labkit 4.0.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: c872947164d25ef7f75203c6195fe04bbc8c9002639d59fadf10672d47201862
4
- data.tar.gz: d0308016fd538669e466d2e499aa283d47e82bb4d53bd530c07bce74162b16b4
3
+ metadata.gz: 809ee7b1894b9ff60755556cb95f69d9dca501297077e5eb1ddadac9d5d2b492
4
+ data.tar.gz: 48d5598c40eefcd144ed435f0e0fafa7a2e1dffa305830e6f7bf1a4ce5e71d1e
5
5
  SHA512:
6
- metadata.gz: e6cb4000c77a3ebe764b61e0d536db95dbe3c79378a1d95744747e7eff2509cb435561eba2963ae83107eea37364f5515e3a64bd9491c799c2b9508c9293c793
7
- data.tar.gz: 64cc36f40cb6140b09fc54d873a102098a7fe05b2e967960317c782dc53b224c513fe676e6435dae48b6b0fc33e9e95dd8f32f10230900dea809bbef8bdd03e0
6
+ metadata.gz: 7081e60adc3b7d3929b83949710758c6af3ed04dca87337006637d7c4a1f90e6261c817bf0eae1a2ca5644763b25ee9896f06ff440670fadd1e675a64effec29
7
+ data.tar.gz: eb903367e7296978188ca66f9affb82a543ee9342938934f8ea817f49bb7a843920e570279d03d727ae68d2cb8f73d3627b3c62715d806bac2c2f337a668e965
data/.gitlab-ci.yml CHANGED
@@ -19,13 +19,13 @@ include:
19
19
  # It includes standard checks, gitlab-scanners, validations and release processes
20
20
  # common to all projects using this template library.
21
21
  # see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/templates/standard.md
22
- - component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/standard-build@v4.22
22
+ - component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/standard-build@v4.36
23
23
 
24
24
  # Runs rspec tests and rubocop on the project
25
25
  # see https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/templates/ruby.md
26
- - component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/ruby-build@v4.22
26
+ - component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/ruby-build@v4.36
27
27
 
28
- - component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/danger@v4.22
28
+ - component: $CI_SERVER_FQDN/gitlab-com/gl-infra/common-ci-tasks/danger@v4.36
29
29
 
30
30
  # Attach a redis service to the rspec job from common-ci-tasks/ruby-build.
31
31
  # GitLab merges keys when a local job has the same name as an included one,
@@ -25,7 +25,7 @@ repos:
25
25
  # Documentation available at
26
26
  # https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/blob/main/docs/pre-commit.md
27
27
  - repo: https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks
28
- rev: v4.22 # renovate:managed
28
+ rev: v4.36 # renovate:managed
29
29
 
30
30
  hooks:
31
31
  - id: shellcheck # Run shellcheck for changed Shell files
data/lib/labkit/fields.rb CHANGED
@@ -192,7 +192,7 @@ module Labkit
192
192
 
193
193
  MAPPINGS = {
194
194
  Fields::CORRELATION_ID => %w[tags.correlation_id],
195
- Fields::GL_USER_ID => %w[user_id userid extra.user_id extra.current_user_id meta.user_id],
195
+ Fields::GL_USER_ID => %w[user_id userid extra.user_id extra.current_user_id meta.user_id gitlab_user_id],
196
196
  Fields::GL_USER_NAME => %w[username extra.user meta.user],
197
197
  Fields::ERROR_MESSAGE => %w[error err error.message exception.message graphql_errors],
198
198
  Fields::HTTP_STATUS_CODE => %w[status_code extra.status status_text http_status],
@@ -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.0.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate