Merge pull request #1365 from chef/chris-rock/outdated

display if inspec version is outdated
This commit is contained in:
Dominik Richter 2017-01-03 12:21:28 +01:00 committed by GitHub
commit 823b140dd7
2 changed files with 26 additions and 0 deletions

View file

@ -9,6 +9,7 @@ require 'thor'
require 'json'
require 'pp'
require 'utils/json_log'
require 'utils/latest_version'
require 'inspec/base_cli'
require 'inspec/plugins'
require 'inspec/runner_mock'
@ -223,6 +224,11 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
desc 'version', 'prints the version of this tool'
def version
puts Inspec::VERSION
# display outdated version
latest = LatestInSpecVersion.new.latest
if Gem::Version.new(Inspec::VERSION) < Gem::Version.new(latest)
puts "\nYour version of InSpec is out of date! The latest version is #{latest}."
end
end
private

View file

@ -0,0 +1,20 @@
# 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') {|http|
http.read_timeout = 0.5
http.get(uri.path)
}
inspec_info = JSON.parse(res.body)
inspec_info['version']
rescue Exception # rubocop:disable Lint/RescueException
nil
end
end