Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorReuben Pereira <rpereira@gitlab.com>2019-02-27 17:20:38 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2019-02-27 17:20:38 +0300
commit5f136e46f15e61a1df42a9e84cc9530190e6dee5 (patch)
tree5a4d84aec78f8f5bf655418aec99c07960a289a6 /app
parentd277453a2300536ba09937e97319c8e3d190cc04 (diff)
Check validity of prometheus_service before query
Check validity before querying so that if the dns entry for the api_url has been changed to something invalid after the model was saved and checked for validity, it will not query. This is to solve a toctou (time of check to time of use) issue.
Diffstat (limited to 'app')
-rw-r--r--app/models/project_services/prometheus_service.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/app/models/project_services/prometheus_service.rb b/app/models/project_services/prometheus_service.rb
index 60cb2d380d5..c68a9d923c8 100644
--- a/app/models/project_services/prometheus_service.rb
+++ b/app/models/project_services/prometheus_service.rb
@@ -71,7 +71,7 @@ class PrometheusService < MonitoringService
end
def prometheus_client
- RestClient::Resource.new(api_url, max_redirects: 0) if api_url && manual_configuration? && active?
+ RestClient::Resource.new(api_url, max_redirects: 0) if should_return_client?
end
def prometheus_available?
@@ -83,6 +83,10 @@ class PrometheusService < MonitoringService
private
+ def should_return_client?
+ api_url && manual_configuration? && active? && valid?
+ end
+
def synchronize_service_state
self.active = prometheus_available? || manual_configuration?