summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-09 12:08:03 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-09 12:08:03 +0000
commitcddaddb86bf6d4d277d206c42a9138a2d660ea56 (patch)
tree92da110e04602b7ea62835e41327e552150279f5 /lib
parent5afd8575506372dd64c238203bd05b4826f3ae2e (diff)
downloadgitlab-ce-cddaddb86bf6d4d277d206c42a9138a2d660ea56.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/auth/auth_finders.rb11
-rw-r--r--lib/gitlab/auth/request_authenticator.rb11
-rw-r--r--lib/gitlab/ci/snippets/review_app_default.yml9
-rw-r--r--lib/gitlab/metrics.rb6
-rw-r--r--lib/gitlab/metrics/prometheus.rb10
-rw-r--r--lib/gitlab/patch/action_dispatch_journey_formatter.rb34
6 files changed, 75 insertions, 6 deletions
diff --git a/lib/gitlab/auth/auth_finders.rb b/lib/gitlab/auth/auth_finders.rb
index 33cbb070c2f..fe61d9fe8ca 100644
--- a/lib/gitlab/auth/auth_finders.rb
+++ b/lib/gitlab/auth/auth_finders.rb
@@ -25,9 +25,10 @@ module Gitlab
PRIVATE_TOKEN_HEADER = 'HTTP_PRIVATE_TOKEN'
PRIVATE_TOKEN_PARAM = :private_token
- JOB_TOKEN_HEADER = "HTTP_JOB_TOKEN".freeze
+ JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN'.freeze
JOB_TOKEN_PARAM = :job_token
RUNNER_TOKEN_PARAM = :token
+ RUNNER_JOB_TOKEN_PARAM = :token
# Check the Rails session for valid authentication details
def find_user_from_warden
@@ -57,11 +58,13 @@ module Gitlab
def find_user_from_job_token
return unless route_authentication_setting[:job_token_allowed]
- token = (params[JOB_TOKEN_PARAM] || env[JOB_TOKEN_HEADER]).to_s
- return unless token.present?
+ token = current_request.params[JOB_TOKEN_PARAM].presence ||
+ current_request.params[RUNNER_JOB_TOKEN_PARAM].presence ||
+ current_request.env[JOB_TOKEN_HEADER].presence
+ return unless token
job = ::Ci::Build.find_by_token(token)
- raise ::Gitlab::Auth::UnauthorizedError unless job
+ raise UnauthorizedError unless job
@current_authenticated_job = job # rubocop:disable Gitlab/ModuleWithInstanceVariables
diff --git a/lib/gitlab/auth/request_authenticator.rb b/lib/gitlab/auth/request_authenticator.rb
index 34ccff588f4..c6216fa9cad 100644
--- a/lib/gitlab/auth/request_authenticator.rb
+++ b/lib/gitlab/auth/request_authenticator.rb
@@ -33,7 +33,8 @@ module Gitlab
find_user_from_web_access_token(request_format) ||
find_user_from_feed_token(request_format) ||
find_user_from_static_object_token(request_format) ||
- find_user_from_basic_auth_job
+ find_user_from_basic_auth_job ||
+ find_user_from_job_token
rescue Gitlab::Auth::AuthenticationError
nil
end
@@ -45,6 +46,14 @@ module Gitlab
rescue Gitlab::Auth::AuthenticationError
false
end
+
+ private
+
+ def route_authentication_setting
+ @route_authentication_setting ||= {
+ job_token_allowed: api_request?
+ }
+ end
end
end
end
diff --git a/lib/gitlab/ci/snippets/review_app_default.yml b/lib/gitlab/ci/snippets/review_app_default.yml
new file mode 100644
index 00000000000..b6db08ef537
--- /dev/null
+++ b/lib/gitlab/ci/snippets/review_app_default.yml
@@ -0,0 +1,9 @@
+deploy_review:
+ stage: deploy
+ script:
+ - echo "Deploy a review app"
+ environment:
+ name: review/$CI_COMMIT_REF_NAME
+ url: https://$CI_ENVIRONMENT_SLUG.example.com
+ only:
+ - branches
diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb
index 61ed20ad623..d759ae24051 100644
--- a/lib/gitlab/metrics.rb
+++ b/lib/gitlab/metrics.rb
@@ -5,8 +5,14 @@ module Gitlab
include Gitlab::Metrics::InfluxDb
include Gitlab::Metrics::Prometheus
+ @error = false
+
def self.enabled?
influx_metrics_enabled? || prometheus_metrics_enabled?
end
+
+ def self.error?
+ @error
+ end
end
end
diff --git a/lib/gitlab/metrics/prometheus.rb b/lib/gitlab/metrics/prometheus.rb
index cab1edab48f..f7480a8789e 100644
--- a/lib/gitlab/metrics/prometheus.rb
+++ b/lib/gitlab/metrics/prometheus.rb
@@ -61,6 +61,14 @@ module Gitlab
safe_provide_metric(:histogram, name, docstring, base_labels, buckets)
end
+ def error_detected!
+ clear_memoization(:prometheus_metrics_enabled)
+
+ PROVIDER_MUTEX.synchronize do
+ @error = true
+ end
+ end
+
private
def safe_provide_metric(method, name, *args)
@@ -81,7 +89,7 @@ module Gitlab
end
def prometheus_metrics_enabled_unmemoized
- metrics_folder_present? && Gitlab::CurrentSettings.prometheus_metrics_enabled || false
+ !error? && metrics_folder_present? && Gitlab::CurrentSettings.prometheus_metrics_enabled || false
end
end
end
diff --git a/lib/gitlab/patch/action_dispatch_journey_formatter.rb b/lib/gitlab/patch/action_dispatch_journey_formatter.rb
new file mode 100644
index 00000000000..2d3b7bb9923
--- /dev/null
+++ b/lib/gitlab/patch/action_dispatch_journey_formatter.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Patch
+ module ActionDispatchJourneyFormatter
+ def self.prepended(mod)
+ mod.alias_method(:old_missing_keys, :missing_keys)
+ mod.remove_method(:missing_keys)
+ end
+
+ private
+
+ def missing_keys(route, parts)
+ missing_keys = nil
+ tests = route.path.requirements_for_missing_keys_check
+ route.required_parts.each do |key|
+ case tests[key]
+ when nil
+ unless parts[key]
+ missing_keys ||= []
+ missing_keys << key
+ end
+ else
+ unless tests[key].match?(parts[key])
+ missing_keys ||= []
+ missing_keys << key
+ end
+ end
+ end
+ missing_keys
+ end
+ end
+ end
+end