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/tracking | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'lib/gitlab/tracking')
-rw-r--r-- | lib/gitlab/tracking/standard_context.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/gitlab/tracking/standard_context.rb b/lib/gitlab/tracking/standard_context.rb index 542dc476526..05ddc7e26cc 100644 --- a/lib/gitlab/tracking/standard_context.rb +++ b/lib/gitlab/tracking/standard_context.rb @@ -7,6 +7,12 @@ module Gitlab GITLAB_RAILS_SOURCE = 'gitlab-rails' def initialize(namespace: nil, project: nil, user: nil, **extra) + if Feature.enabled?(:standard_context_type_check) + check_argument_type(:namespace, namespace, [Namespace]) + check_argument_type(:project, project, [Project, Integer]) + check_argument_type(:user, user, [User, DeployToken]) + end + @namespace = namespace @plan = namespace&.actual_plan_name @project = project @@ -54,6 +60,14 @@ module Gitlab def project_id project.is_a?(Integer) ? project : project&.id end + + def check_argument_type(argument_name, argument_value, allowed_classes) + return if argument_value.nil? || allowed_classes.any? { |allowed_class| argument_value.is_a?(allowed_class) } + + exception = "Invalid argument type passed for #{argument_name}." \ + " Should be one of #{allowed_classes.map(&:to_s)}" + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(ArgumentError.new(exception)) + end end end end |