diff options
author | Reuben Pereira <rpereira@gitlab.com> | 2019-02-27 14:20:40 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2019-02-27 14:20:40 +0000 |
commit | 515bb4e6dd601ffc938cb519e7dfa7105c2c023d (patch) | |
tree | 82da80bed6cfea8cd00f60d393a716c9bf0a0d76 /app | |
parent | ae54a129088f78fcee07478c2ba323ee6a2545f5 (diff) | |
download | gitlab-ce-515bb4e6dd601ffc938cb519e7dfa7105c2c023d.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')
-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? |