diff options
author | Reuben Pereira <rpereira@gitlab.com> | 2019-03-04 18:36:43 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2019-03-04 18:36:43 +0000 |
commit | 50591efc75e465c1b626c1bb2d4d65447ee9a726 (patch) | |
tree | 34d80a54909cd7f8fd0ee4a6a44dc46bebf893bb /app/models/project_services | |
parent | 219075fc6e187d742bf46791a778fd9a885ce8b3 (diff) | |
download | gitlab-ce-50591efc75e465c1b626c1bb2d4d65447ee9a726.tar.gz |
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/models/project_services')
-rw-r--r-- | app/models/project_services/prometheus_service.rb | 6 |
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? |