Merge pull request #5893 from inspec/nm/automate-version-fix

CFINSPEC-123 Automate version command fix
This commit is contained in:
Clinton Wolfe 2022-03-03 10:03:19 -05:00 committed by GitHub
commit 8ec9bd040c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View file

@ -84,7 +84,7 @@ module InspecPlugins
return {} if data.nil? || data.empty?
parsed = JSON.parse(data)
return {} unless parsed.key?("version") && !parsed["version"].empty?
return {} unless parsed.key?("build_timestamp") && !parsed["build_timestamp"].empty?
parsed
end

View file

@ -219,9 +219,10 @@ module InspecPlugins
def version
config = InspecPlugins::Compliance::Configuration.new
info = InspecPlugins::Compliance::API.version(config)
if !info.nil? && info["version"]
puts "Name: #{info["api"]}"
puts "Version: #{info["version"]}"
if !info.nil? && info["build_timestamp"]
# key info["api"] is not longer available in latest version api response
puts "Name: automate"
puts "Version: #{info["build_timestamp"]}"
else
puts "Could not determine server version."
exit 1

View file

@ -110,9 +110,9 @@ describe InspecPlugins::Compliance::API do
it "should return an empty hash" do
response = mock
response.stubs(:code).returns("200")
response.stubs(:body).returns('{"api":"compliance","version":"1.2.3"}')
response.stubs(:body).returns('{"build_timestamp": "20220223121207"}')
InspecPlugins::Compliance::HTTP.expects(:get).with("myserver/version", "test-headers", true).returns(response)
_(InspecPlugins::Compliance::API.version(config)).must_equal({ "version" => "1.2.3", "api" => "compliance" })
_(InspecPlugins::Compliance::API.version(config)).must_equal({ "build_timestamp" => "20220223121207" })
end
end
end