2018-10-06 19:10:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-05-08 08:14:56 -04:00
|
|
|
require "base64"
|
|
|
|
|
2015-02-12 23:31:55 -05:00
|
|
|
class VersionCheck
|
2021-12-02 01:15:23 -05:00
|
|
|
include ReactiveCaching
|
|
|
|
|
|
|
|
self.reactive_cache_work_type = :external_dependency
|
|
|
|
self.reactive_cache_worker_finder = ->(_id, *args) { from_cache }
|
|
|
|
|
2018-12-14 12:47:49 -05:00
|
|
|
def self.data
|
2015-05-08 08:14:56 -04:00
|
|
|
{ version: Gitlab::VERSION }
|
2015-02-12 23:31:55 -05:00
|
|
|
end
|
|
|
|
|
2021-12-02 01:15:23 -05:00
|
|
|
def self.headers
|
|
|
|
{ "REFERER": Gitlab.config.gitlab.url }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.url
|
|
|
|
encoded_data = Base64.urlsafe_encode64(data.to_json)
|
|
|
|
|
|
|
|
"#{host}/check.json?gitlab_info=#{encoded_data}"
|
|
|
|
end
|
|
|
|
|
2018-12-14 12:47:49 -05:00
|
|
|
def self.host
|
2021-05-17 14:10:42 -04:00
|
|
|
'https://version.gitlab.com'
|
2015-02-12 23:31:55 -05:00
|
|
|
end
|
2021-12-02 01:15:23 -05:00
|
|
|
|
|
|
|
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
|
2015-02-12 23:31:55 -05:00
|
|
|
end
|
2021-05-17 14:10:42 -04:00
|
|
|
|
|
|
|
VersionCheck.prepend_mod
|