diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /lib/version_check.rb | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'lib/version_check.rb')
-rw-r--r-- | lib/version_check.rb | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/lib/version_check.rb b/lib/version_check.rb index a8b7c7371ca..e5a4c244c7a 100644 --- a/lib/version_check.rb +++ b/lib/version_check.rb @@ -2,22 +2,60 @@ require "base64" -# This class is used to build image URL to -# check if it is a new version for update class VersionCheck + include ReactiveCaching + + self.reactive_cache_work_type = :external_dependency + self.reactive_cache_worker_finder = ->(_id, *args) { from_cache } + def self.data { version: Gitlab::VERSION } end - def self.url + def self.headers + { "REFERER": Gitlab.config.gitlab.url } + end + + # This is temporary and will be removed when the new UI is hooked up + # to the version_check.json endpoint. + def self.image_url encoded_data = Base64.urlsafe_encode64(data.to_json) "#{host}/check.svg?gitlab_info=#{encoded_data}" end + def self.url + encoded_data = Base64.urlsafe_encode64(data.to_json) + + "#{host}/check.json?gitlab_info=#{encoded_data}" + end + def self.host 'https://version.gitlab.com' end + + def self.from_cache(*) + new + end + + def id + Gitlab::VERSION + end + + def calculate_reactive_cache(*) + response = Gitlab::HTTP.try_get(self.class.url, headers: self.class.headers) + + case response&.code + when 200 + response.body + end + end + + def response + with_reactive_cache do |data| + Gitlab::Json.parse(data) if data + end + end end VersionCheck.prepend_mod |