mirror of
https://github.com/inspec/inspec
synced 2025-02-16 22:18:38 +00:00
Fix CLI version command test to be resilient on a bad network.
Also switched out LatestInSpecVersion.latest to be much cleaner using open-uri. Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
parent
747d16bd7d
commit
443f4a16d7
2 changed files with 3 additions and 9 deletions
|
@ -362,7 +362,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|||
else
|
||||
puts Inspec::VERSION
|
||||
# display outdated version
|
||||
latest = LatestInSpecVersion.new.latest
|
||||
latest = LatestInSpecVersion.new.latest || Inspec::VERSION
|
||||
if Gem::Version.new(Inspec::VERSION) < Gem::Version.new(latest)
|
||||
puts "\nYour version of #{Inspec::Dist::PRODUCT_NAME} is out of date! The latest version is #{latest}."
|
||||
end
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
require 'json'
|
||||
require 'net/http'
|
||||
require 'open-uri'
|
||||
|
||||
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 = JSON.parse(uri.read(open_timeout: 1.5, read_timeout: 1.5))
|
||||
inspec_info['version']
|
||||
rescue StandardError
|
||||
nil
|
||||
|
|
Loading…
Add table
Reference in a new issue