Merge pull request #5901 from inspec/revert-5875-nm/base_resource_id

CFINSPEC-70 Revert - Added resource_id attribute for the custom resources in the base class
This commit is contained in:
Clinton Wolfe 2022-03-04 00:32:57 -05:00 committed by GitHub
commit 631ecd0b59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 12 additions and 65 deletions

View file

@ -423,7 +423,6 @@ The `run_data` object contains all data from the Chef InSpec run. Here is an ove
|`run_data.profiles[0].controls[0].results[0].resource`| Undocumented and usually unpopulated; try exploring resource_title |
|`run_data.profiles[0].controls[0].results[0].resource_name`| String, name of the resource used in the test|
|`run_data.profiles[0].controls[0].results[0].resource_title`| Anonymous Class, the actual instance of the Resource. Responds to to_s with the name of the resource.|
|`run_data.profiles[0].controls[0].results[0].resource_title.resource_id`| String, unique identifier of each resource node.|
|`run_data.profiles[0].controls[0].results[0].run_time`| Float, execution time in seconds for the test|
|`run_data.profiles[0].controls[0].results[0].skip_message`| String, if the test was skipped, explains why (user provided)|
|`run_data.profiles[0].controls[0].results[0].start_time`| DateTime, time the test started executing|

View file

@ -54,17 +54,6 @@ The following methods are available to the resource:
- inspec - Contains a registry of all other resources to interact with the operating system or target in general.
- skip_resource - A resource may call this method to indicate that requirements aren't met. All tests that use this resource will be marked as skipped.
The additional methods may be defined within the resource:
- resource_id - An instance method. Place logic here to determine the unique identifier for a resource, and set it using the superclass method. Following is an example of its usage in an InSpec test:
```
# example_config resource can have unique conf file path as an identifier.
describe example_config do
its("resource_id") { should eq PATH_OF_CONF_FILE }
end
```
The following example shows a full resource using attributes and methods
to provide simple access to a configuration file:
@ -99,11 +88,6 @@ class ExampleConfig < Inspec.resource(1)
@params[name]
end
def resource_id
value = example_method_to_determine_resource_id # define logic to determine resource_id value
super(value)
end
private
def read_content

View file

@ -36,18 +36,17 @@ module Inspec::Reporters
def profile_results(control)
(control[:results] || []).map { |r|
{
status: r[:status],
code_desc: r[:code_desc],
run_time: r[:run_time],
start_time: r[:start_time],
resource: r[:resource],
skip_message: r[:skip_message],
message: r[:message],
exception: r[:exception],
backtrace: r[:backtrace],
resource_class: r[:resource_class],
status: r[:status],
code_desc: r[:code_desc],
run_time: r[:run_time],
start_time: r[:start_time],
resource: r[:resource],
skip_message: r[:skip_message],
message: r[:message],
exception: r[:exception],
backtrace: r[:backtrace],
resource_class: r[:resource_class],
resource_params: r[:resource_params].to_s,
resource_id: r[:resource_title].resource_id,
}.reject { |_k, v| v.nil? }
}
end

View file

@ -34,12 +34,6 @@ module Inspec
Inspec::Resource.support_registry[key].push(criteria)
end
def resource_id(value = nil)
@resource_id = value if value
@resource_id = "" if @resource_id.nil?
@resource_id
end
# TODO: this is pretty terrible and is only here to work around
# the idea that we've trained resource authors to make initialize
# methods w/o calling super.

View file

@ -57,7 +57,6 @@ module Inspec
"run_time" => { "type" => "number" },
"start_time" => { "type" => "string" },
"resource_class" => { "type" => "string", "optional" => true },
"resource_id" => { "type" => "string", "optional" => true },
"skip_message" => { "type" => "string", "optional" => true },
"resource" => { "type" => "string", "optional" => true },
"message" => { "type" => "string", "optional" => true },

View file

@ -38,7 +38,6 @@ module Inspec
"message" => Primitives.desc(Primitives::STRING, "An explanation of the test status - usually only provided when the test fails."),
"skip_message" => Primitives.desc(Primitives::STRING, "An explanation of the test status if the status was 'skipped."),
"exception" => Primitives.desc(Primitives::STRING, "The type of exception if an exception was thrown."),
"resource_id" => Primitives.desc(Primitives::STRING, "The unique identifier of the resource."),
"backtrace" => {
"anyOf" => [
Primitives.array(Primitives::STRING),

View file

@ -19,12 +19,4 @@ describe "inspec schema" do
assert_exit_code 0, out
end
end
describe "validate schema of exec-json" do
it "contains resource_id key" do
out = inspec("schema exec-json")
json_output = JSON.parse(out.stdout)
_(json_output["definitions"]["Control_Result"]["properties"]["resource_id"]).wont_be_nil
end
end
end

View file

@ -44,12 +44,12 @@ describe Inspec::Resource do
end
describe "#example" do
it "will register a example" do
it "will register a description" do
expected = rand.to_s
_(create { example expected }.example).must_equal expected
end
it "can change the example" do
it "can change the description" do
c = create { example rand.to_s }
c.example(x = rand.to_s)
_(c.example).must_equal x
@ -94,23 +94,4 @@ describe Inspec::Resource do
Inspec::Resource.support_registry["os"] = nil
end
end
describe "resource_id" do
it "can set instance variable resource_id and use it" do
cls = create {}
cls_obj = cls.new(nil, "notSoRandomName")
cls_obj.resource_id(x = rand.to_s)
_(cls_obj.resource_id).must_equal x
_(cls_obj.instance_variable_get("@resource_id")).must_equal x
end
it "can change the resource_id value and use it" do
cls = create {}
cls_obj = cls.new(nil, "notSoRandomName")
cls_obj.resource_id(x = rand.to_s)
_(cls_obj.resource_id).must_equal x
cls_obj.resource_id(y = rand.to_s)
_(cls_obj.resource_id).must_equal y
end
end
end