Change profile skip_message to status_message

Keep a duplicate of the message in skip_message for the JSON reporters, for backwards compaibility.

Signed-off-by: James Stocks <jstocks@chef.io>
This commit is contained in:
James Stocks 2020-06-30 15:09:15 +01:00
parent 41087c5ec6
commit fd4c501c70
11 changed files with 41 additions and 21 deletions

View file

@ -446,9 +446,9 @@ The `run_data` object contains all data from the Chef InSpec run. Here is an ove
|`run_data.profiles[0].depends[0].name`| name (assigned alias) of dependent profile|
|`run_data.profiles[0].depends[0].path`| location of dependent profile if it was a local reference|
|`run_data.profiles[0].depends[0].relative_path`| relative path within clone if it was a git reference|
|`run_data.profiles[0].depends[0].skip_message`| Reason if status is "skipped"|
|`run_data.profiles[0].depends[0].status_message`| Reason if status is "failed" or "skipped"|
|`run_data.profiles[0].depends[0].supermarket`| String, "user/profilename" on Supermarket server if it was a Supermarket reference|
|`run_data.profiles[0].depends[0].status`| String, one of "loaded" or "skipped"|
|`run_data.profiles[0].depends[0].status`| String, one of "loaded", "failed" or "skipped"|
|`run_data.profiles[0].depends[0].tag`| tag ref if it was a git reference|
|`run_data.profiles[0].depends[0].version`| semver tag if it was a git reference|
|`run_data.profiles[0].depends[0].url`| location of dependent profile if it was a URL reference|
@ -466,14 +466,14 @@ The `run_data` object contains all data from the Chef InSpec run. Here is an ove
|`run_data.profiles[0].name`| String, machine name of the profile|
|`run_data.profiles[0].parent_profile`| String, name of the parent profile if this is a dependency|
|`run_data.profiles[0].sha256`| String, checksum of the profile|
|`run_data.profiles[0].skip_message`| String, message indicating why the profile was not loaded if status is "skipped"|
|`run_data.profiles[0].status_message`| String, message indicating why the profile was not loaded if status is "failed" or "skipped"|
|`run_data.profiles[0].summary`| String, A one-line summary from the inspec.yml|
|`run_data.profiles[0].supports`| Array of Support records indicating platform support|
|`run_data.profiles[0].supports[0].platform_family`| Platform restriction by family|
|`run_data.profiles[0].supports[0].platform_name`| Platform restriction by name|
|`run_data.profiles[0].supports[0].platform`| Platform restriction by name|
|`run_data.profiles[0].supports[0].release`| Platform restriction by release|
|`run_data.profiles[0].status`| String, one of "loaded" or "skipped"|
|`run_data.profiles[0].status`| String, one of "loaded", "failed" or "skipped"|
|`run_data.statistics.controls.failed.total`| Integer, total count of failing controls|
|`run_data.statistics.controls.passed.total`| Integer, total count of passing controls|
|`run_data.statistics.controls.skipped.total`| Integer, total count of passing controls|

View file

@ -264,7 +264,8 @@ module Inspec
# TODO: NO! this is a violation of encapsulation to an extreme
metadata.dependencies[i][:status] = "skipped"
msg = "Skipping profile: '#{d.name}' on unsupported platform: '#{d.backend.platform.name}/#{d.backend.platform.release}'."
metadata.dependencies[i][:skip_message] = msg
metadata.dependencies[i][:status_message] = msg
metadata.dependencies[i][:skip_message] = msg # Repeat as skip_message for backward compatibility
next
elsif metadata.dependencies[i]
# Currently wrapper profiles will load all dependencies, and then we
@ -337,8 +338,9 @@ module Inspec
if !supports_platform?
res[:status] = "skipped"
msg = "Skipping profile: '#{name}' on unsupported platform: '#{backend.platform.name}/#{backend.platform.release}'."
res[:skip_message] = msg
res[:status_message] = msg
else
res[:status_message] = @status_message || ""
res[:status] = failed? ? "failed" : "loaded"
end
@ -465,6 +467,10 @@ module Inspec
params[:controls].values.length
end
def set_status_message(msg)
@status_message = msg.to_s
end
# generates a archive of a folder profile
# assumes that the profile was checked before
def archive(opts)

View file

@ -45,8 +45,8 @@ module Inspec::Reporters
end
def profiles
run_data[:profiles].map { |p|
{
run_data[:profiles].map do |p|
res = {
name: p[:name],
version: p[:version],
sha256: p[:sha256],
@ -64,10 +64,15 @@ module Inspec::Reporters
groups: profile_groups(p),
controls: profile_controls(p),
status: p[:status],
skip_message: p[:skip_message],
status_message: p[:status_message],
waiver_data: p[:waiver_data],
}.reject { |_k, v| v.nil? }
}
# For backwards compatibility
res[:skip_message] = res[:status_message] if res[:status] == 'skipped'
res
end
end
def profile_groups(profile)

View file

@ -47,7 +47,7 @@ module Inspec
# core reporters have been migrated to plugins. It is probable that new data elements
# and new Hash compatibility behavior will be added during the core reporter plugin
# conversion process.
SCHEMA_VERSION = "0.1.0".freeze
SCHEMA_VERSION = "0.2.0".freeze
def self.compatible_schema?(constraints)
reqs = Gem::Requirement.create(constraints)

View file

@ -15,7 +15,7 @@ module Inspec
:summary,
:supports, # complex local
:parent_profile,
:skip_message,
:status_message,
:waiver_data, # Undocumented but used in JSON reporter - should not be?
:title,
:version
@ -40,7 +40,7 @@ module Inspec
title
version
parent_profile
skip_message
status_message
waiver_data
}.each do |field|
self[field] = raw_prof_data[field]
@ -51,11 +51,11 @@ module Inspec
class Profile
# Good candidate for keyword_init, but that is not in 2.4
Dependency = Struct.new(
:name, :path, :status, :skip_message, :git, :url, :compliance, :supermarket, :branch, :tag, :commit, :version, :relative_path
:name, :path, :status, :status_message, :git, :url, :compliance, :supermarket, :branch, :tag, :commit, :version, :relative_path
) do
include HashLikeStruct
def initialize(raw_dep_data)
%i{name path status skip_message git url supermarket compliance branch tag commit version relative_path}.each { |f| self[f] = raw_dep_data[f] }
%i{name path status status_message git url supermarket compliance branch tag commit version relative_path}.each { |f| self[f] = raw_dep_data[f] }
end
end

View file

@ -120,6 +120,7 @@ module Inspec
all_controls += tests unless tests.nil?
rescue Inspec::Exceptions::ProfileLoadFailed => e
Inspec::Log.error "Failed to load profile #{profile.name}: #{e}"
profile.set_status_message e.to_s
next
end
end

View file

@ -147,6 +147,8 @@ module Inspec
"license" => { "type" => "string", "optional" => true },
"summary" => { "type" => "string", "optional" => true },
"status" => { "type" => "string", "optional" => false },
"status_message" => { "type" => "string", "optional" => true },
# skip_message is deprecated, status_message should be used to store the reason for skipping
"skip_message" => { "type" => "string", "optional" => true },
"supports" => {

View file

@ -83,7 +83,7 @@ module Inspec
"required" => %w{name sha256 supports attributes groups controls},
# Name is mandatory in inspec.yml.
# supports, controls, groups, and attributes are always present, even if empty
# sha256, status, skip_message
# sha256, status, status_message
"properties" => {
# These are provided in inspec.yml
"name" => Primitives::STRING,
@ -100,10 +100,11 @@ module Inspec
"description" => Primitives::STRING,
"inspec_version" => Primitives::STRING,
# These are generated at runtime, and all except skip_message are guaranteed
# These are generated at runtime, and all except status_message and skip_message are guaranteed
"sha256" => Primitives::STRING,
"status" => Primitives::STRING,
"skip_message" => Primitives::STRING, # If skipped, why
"status_message" => Primitives::STRING, # If skipped or failed to load, why
"skip_message" => Primitives::STRING, # Deprecated field storing reason for skipping. status_message should be used instead.
"controls" => Primitives.array(CONTROL.ref),
"groups" => Primitives.array(Primitives::CONTROL_GROUP.ref),
"attributes" => Primitives.array(Primitives::INPUT),

View file

@ -160,7 +160,7 @@ module Inspec
"url" => URL,
"branch" => STRING,
"path" => STRING,
"skip_message" => STRING,
"status_message" => STRING,
"status" => STRING,
"git" => URL,
"supermarket" => STRING,

View file

@ -7,8 +7,8 @@
<% if profile.summary %>
<tr class="profile-summary"><th>Summary:</th><td><%= profile.summary %></td></tr>
<% end %>
<% if profile.skip_message %>
<tr class="profile-skip-message"><th>Skip Message:</th><td><%= profile.skip_message %></td></tr>
<% if profile.status_message %>
<tr class="profile-status-message"><th>Status Message:</th><td><%= profile.status_message %></td></tr>
<% end %>
</table>

View file

@ -100,6 +100,8 @@ describe "inspec exec with json formatter" do
_(profile["depends"].count).must_equal 2
profile["depends"].each do |d|
_(d["status"]).must_equal "skipped"
_(d["status_message"]).must_include "Skipping profile: "
# For backwards compatibility, the skip reason is also given as skip_message
_(d["skip_message"]).must_include "Skipping profile: "
end
@ -116,6 +118,7 @@ describe "inspec exec with json formatter" do
_(profile["depends"].count).must_equal 2
profile["depends"].each do |d|
_(d["status"]).must_equal "loaded"
_(d.key?("status_message")).must_equal false
_(d.key?("skip_message")).must_equal false
end
@ -131,6 +134,7 @@ describe "inspec exec with json formatter" do
data = JSON.parse(out.stdout)
profile = data["profiles"].first
_(profile["status"]).must_equal "skipped"
_(profile["status_message"]).must_include "Skipping profile: 'skippy' on unsupported platform:"
_(profile["skip_message"]).must_include "Skipping profile: 'skippy' on unsupported platform:"
_(out.stderr).must_equal ""
@ -202,6 +206,7 @@ describe "inspec exec with json formatter" do
"supports" => [{ "platform-family" => "unix" }, { "platform-family" => "windows" }],
"attributes" => [],
"status" => "loaded",
"status_message"=>"",
})
_(groups.sort_by { |x| x["id"] }).must_equal([