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

Inconsistent json format caused by inconsistent hash keys #827

Closed
alexpop opened this issue Jul 13, 2016 · 0 comments
Closed

Inconsistent json format caused by inconsistent hash keys #827

alexpop opened this issue Jul 13, 2016 · 0 comments
Labels
Type: Bug Feature not working as expected

Comments

@alexpop
Copy link
Contributor

alexpop commented Jul 13, 2016

When executing a profile from inspec 0.27.0, the json formatted output shows the results of each control under profiles > PROFILE_NAME > controls > CONTROL_NAME > results. Field other_checks is []

When executing the same profile from the audit cookbook, the json formatted output is missing the results field inside the controls, with the other_checks field now containing the results.

I tracked the issue inside lib/inspec/runner.rb where options['metadata'] is nil when executing the profile via the audit cookbook. This causes profile_id to remain nil.

pry output when executing the profile using the audit cookbook:

From: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/inspec-0.27.0/lib/inspec/runner.rb @ line 115 Inspec::Runner#create_context:

    111: def create_context(options = {})
    112:   meta = options['metadata']
    113:   profile_id = nil
    114:   require 'pry'; binding.pry #############TODO: REMOVE ME
 => 115:   profile_id = meta.params[:name] unless meta.nil?
    116:   Inspec::ProfileContext.new(profile_id, @backend, @conf.merge(options))
    117: end

[1] pry(#<Inspec::Runner>)> options['metadata']
=> nil
[2] pry(#<Inspec::Runner>)> options[:metadata]
=> #<Inspec::Metadata:0x007ff9af575b38
 @logger=#<Logger:0x007ff9af575b10 @default_formatter=#<Logger::Formatter:0x007ff9af575a98 @datetime_format=nil>, @formatter=nil, @level=0, @logdev=nil, @progname=nil>,
 @missing_methods=[],
 @params=
  {:name=>"mylinux-success-failure",
   :title=>"Mylinux Success Failure",
   :maintainer=>"Chef Software, Inc.",
   :copyright=>"Chef Software, Inc.",
   :copyright_email=>"support@chef.io",
   :license=>"Apache 2 license",
   :summary=>"Demonstrates the use of InSpec Compliance Profile",
   :version=>"1.8.99",
   :supports=>[{:"os-family"=>"unix"}]},
 @ref="inspec.yml">
[3] pry(#<Inspec::Runner>)>

pry output when executing the profile from the cli:

$ /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/inspec-0.27.0/bin/inspec exec /Users/apop/git/mycompliance-profile/mylinux-success-failure --format json

Frame number: 0/12

From: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/inspec-0.27.0/lib/inspec/runner.rb @ line 115 Inspec::Runner#create_context:

    111: def create_context(options = {})
    112:   meta = options['metadata']
    113:   profile_id = nil
    114:   require 'pry'; binding.pry #############TODO: REMOVE ME
 => 115:   profile_id = meta.params[:name] unless meta.nil?
    116:   Inspec::ProfileContext.new(profile_id, @backend, @conf.merge(options))
    117: end

[1] pry(#<Inspec::Runner>)> options['metadata']
=> #<Inspec::Metadata:0x007fef888f53e8
 @logger=#<Logger:0x007fef888f52d0 @default_formatter=#<Logger::Formatter:0x007fef888f51b8 @datetime_format=nil>, @formatter=nil, @level=0, @logdev=nil, @progname=nil>,
 @missing_methods=[],
 @params=
  {:name=>"mylinux-success-failure",
   :title=>"Mylinux Success Failure",
   :maintainer=>"Chef Software, Inc.",
   :copyright=>"Chef Software, Inc.",
   :copyright_email=>"support@chef.io",
   :license=>"Apache 2 license",
   :summary=>"Demonstrates the use of InSpec Compliance Profile",
   :version=>"1.8.99",
   :supports=>[{:"os-family"=>"unix"}]},
 @ref="inspec.yml">
[2] pry(#<Inspec::Runner>)> options[:metadata]
=> #<Inspec::Metadata:0x007fef888f53e8
 @logger=#<Logger:0x007fef888f52d0 @default_formatter=#<Logger::Formatter:0x007fef888f51b8 @datetime_format=nil>, @formatter=nil, @level=0, @logdev=nil, @progname=nil>,
 @missing_methods=[],
 @params=
  {:name=>"mylinux-success-failure",
   :title=>"Mylinux Success Failure",
   :maintainer=>"Chef Software, Inc.",
   :copyright=>"Chef Software, Inc.",
   :copyright_email=>"support@chef.io",
   :license=>"Apache 2 license",
   :summary=>"Demonstrates the use of InSpec Compliance Profile",
   :version=>"1.8.99",
   :supports=>[{:"os-family"=>"unix"}]},
 @ref="inspec.yml">
[3] pry(#<Inspec::Runner>)>

Both runs work fine if I access the metadata via options[:metadata], as added in the add_profile method.

@alexpop alexpop added the Type: Bug Feature not working as expected label Jul 13, 2016
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

No branches or pull requests

1 participant