mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
Merge pull request #1365 from chef/chris-rock/outdated
display if inspec version is outdated
This commit is contained in:
commit
823b140dd7
2 changed files with 26 additions and 0 deletions
|
@ -9,6 +9,7 @@ require 'thor'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'pp'
|
require 'pp'
|
||||||
require 'utils/json_log'
|
require 'utils/json_log'
|
||||||
|
require 'utils/latest_version'
|
||||||
require 'inspec/base_cli'
|
require 'inspec/base_cli'
|
||||||
require 'inspec/plugins'
|
require 'inspec/plugins'
|
||||||
require 'inspec/runner_mock'
|
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'
|
desc 'version', 'prints the version of this tool'
|
||||||
def version
|
def version
|
||||||
puts Inspec::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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
20
lib/utils/latest_version.rb
Normal file
20
lib/utils/latest_version.rb
Normal 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
|
Loading…
Reference in a new issue