Skip to content

Commit

Permalink
Merge pull request #977 from chef/vj/get-command-output
Browse files Browse the repository at this point in the history
first pass at collecting command output for demo
  • Loading branch information
chris-rock authored Aug 25, 2016
2 parents 40a7206 + 2982fba commit e91b885
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ end
desc 'Run robocop linter'
task lint: [:rubocop]

# update command output for demo
desc 'Run inspec commands and save results to www/app/responses'
task :update_demo do
commands = 'tasks/command_simulator.rb'
ruby commands
end

# run tests
task default: [:test, :lint]

Expand Down
20 changes: 20 additions & 0 deletions tasks/command_simulator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# encoding: utf-8
require 'train'

commands = { 'inspec_exec' => 'inspec exec examples/profile/controls/example.rb', 'inspec_version' => 'inspec version' }

commands.each do |keyname, command|
backend = Train.create('local')
conn = backend.connection
# loop around commands
cmd = conn.run_command(command)
cmd.stdout
conn.close

# save the result and put it in inspec/www/app/results with the keyname as filename
result = cmd.stdout
dir = 'www/app/results/'
out_file = File.new(File.join(dir, "#{keyname}.txt"), 'w')
out_file.puts(result)
out_file.close
end

0 comments on commit e91b885

Please sign in to comment.