inspec/lib/utils/latest_version.rb
Makoto Nozaki f913b56ffc Avoid connection timeout of "inspec version" (#1538)
* Add open_timeout to NET::HTTP.start call
Signed-off-by: Makoto Nozaki <makoto.nozaki@twosigma.com>

* Code cleanup based on the discussion at #1538
Signed-off-by: Makoto Nozaki <makoto.nozaki@twosigma.com>
2017-03-06 09:23:42 -07:00

21 lines
585 B
Ruby

# encoding: utf-8
# author: Christoph Hartmann
require 'json'
require 'net/http'
class LatestInSpecVersion
# fetches the latest version from rubygems server
def latest
uri = URI('https://rubygems.org/api/v1/gems/inspec.json')
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https',
open_timeout: 0.5, read_timeout: 0.5
) {|http|
http.get(uri.path)
}
inspec_info = JSON.parse(res.body)
inspec_info['version']
rescue Exception # rubocop:disable Lint/RescueException
nil
end
end