Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json resource (et. al.): allow inspec check to succeed when using command #2317

Merged
merged 2 commits into from Nov 27, 2017

Conversation

adamleff
Copy link
Contributor

When using the json resource (or any of the resources that subclass JsonConfig), inspec check would fail if the content was supplied with the command option. This is because the command resource is mocked and an empty string would be returned for stdout. That content would be blindly passed to the parse method would which raise an exception and cause inspec check to fail.

This change refactors JsonConfig to be a bit cleaner and use some helper methods. Additionally, we use the new Exceptions to properly raise errors which are naturally caught by Inspec::Profile, etc.

@adamleff adamleff requested a review from a team as a code owner November 17, 2017 20:09
Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement @adamleff Just added a nit

"Csv #{@path}"
# used by JsonConfig to build up a full to_s method
# based on whether a file path, content, or command was supplied.
def resource_base_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a private function then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've historically had issues with to_s using private methods. Perhaps it's fixed in later Ruby versions. I'll change it and we can see what happens.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_s needs to be public, i am just talking about the resource_base_name

…mand

When using the `json` resource (or any of the resources that subclass
JsonConfig), `inspec check` would fail if the content was supplied with
the `command` option. This is because the `command` resource is mocked
and an empty string would be returned for `stdout`. That content would
be blindly passed to the `parse` method would which raise an exception
and cause `inspec check` to fail.

This change refactors JsonConfig to be a bit cleaner and use some helper
methods. Additionally, we use the new Exceptions to properly raise errors
which are naturally caught by Inspec::Profile, etc.

Signed-off-by: Adam Leff <adam@leff.co>
Signed-off-by: Adam Leff <adam@leff.co>
@adamleff adamleff force-pushed the adamleff/json-command-when-empty branch from d6ac380 to a145f25 Compare November 27, 2017 16:01
@adamleff adamleff added the Type: Bug Feature not working as expected label Nov 27, 2017
@adamleff adamleff merged commit 6c3ab70 into master Nov 27, 2017
@adamleff adamleff deleted the adamleff/json-command-when-empty branch November 27, 2017 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants