diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /lib/gitlab/application_context.rb | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'lib/gitlab/application_context.rb')
-rw-r--r-- | lib/gitlab/application_context.rb | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/gitlab/application_context.rb b/lib/gitlab/application_context.rb index 6ef5a1e2cd8..3e095585b18 100644 --- a/lib/gitlab/application_context.rb +++ b/lib/gitlab/application_context.rb @@ -20,7 +20,8 @@ module Gitlab :pipeline_id, :related_class, :feature_category, - :artifact_size + :artifact_size, + :root_caller_id ].freeze private_constant :KNOWN_KEYS @@ -34,7 +35,8 @@ module Gitlab Attribute.new(:job, ::Ci::Build), Attribute.new(:related_class, String), Attribute.new(:feature_category, String), - Attribute.new(:artifact, ::Ci::JobArtifact) + Attribute.new(:artifact, ::Ci::JobArtifact), + Attribute.new(:root_caller_id, String) ].freeze def self.known_keys @@ -84,10 +86,11 @@ module Gitlab hash[:project] = -> { project_path } if include_project? hash[:root_namespace] = -> { root_namespace_path } if include_namespace? hash[:client_id] = -> { client } if include_client? - hash[:caller_id] = caller_id if set_values.include?(:caller_id) - hash[:remote_ip] = remote_ip if set_values.include?(:remote_ip) - hash[:related_class] = related_class if set_values.include?(:related_class) - hash[:feature_category] = feature_category if set_values.include?(:feature_category) + assign_hash_if_value(hash, :caller_id) + assign_hash_if_value(hash, :root_caller_id) + assign_hash_if_value(hash, :remote_ip) + assign_hash_if_value(hash, :related_class) + assign_hash_if_value(hash, :feature_category) hash[:pipeline_id] = -> { job&.pipeline_id } if set_values.include?(:job) hash[:job_id] = -> { job&.id } if set_values.include?(:job) hash[:artifact_size] = -> { artifact&.size } if set_values.include?(:artifact) @@ -108,6 +111,14 @@ module Gitlab lazy_attr_reader attr.name, type: attr.type end + def assign_hash_if_value(hash, attribute_name) + raise ArgumentError unless KNOWN_KEYS.include?(attribute_name) + + # rubocop:disable GitlabSecurity/PublicSend + hash[attribute_name] = public_send(attribute_name) if set_values.include?(attribute_name) + # rubocop:enable GitlabSecurity/PublicSend + end + def assign_attributes(values) values.slice(*APPLICATION_ATTRIBUTES.map(&:name)).each do |name, value| instance_variable_set("@#{name}", value) |