switch to using train

This commit is contained in:
Victoria Jeffrey 2016-08-25 11:24:22 -04:00
parent 11a7c9f0da
commit 2982fba946
3 changed files with 22 additions and 15 deletions

View file

@ -18,9 +18,9 @@ desc 'Run robocop linter'
task lint: [:rubocop]
# update command output for demo
desc 'Running commands and saving TBD'
desc 'Run inspec commands and save results to www/app/responses'
task :update_demo do
commands = 'tasks/get_command_output.rb'
commands = 'tasks/command_simulator.rb'
ruby commands
end

View file

@ -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

View file

@ -1,13 +0,0 @@
# encoding: utf-8
require 'open3'
commands = { 'inspec_exec' => 'inspec exec examples/profile/controls/example.rb', 'inspec_version' => 'inspec version' }
commands.each do |keyname, command|
stdout, _stdeerr, _status = Open3.capture3(command)
# filename should be key.txt...and we should be saving it somewhere in www/
out_file = File.new("#{keyname}.txt", 'w')
out_file.puts(stdout)
out_file.close
end