mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
switch to using train
This commit is contained in:
parent
11a7c9f0da
commit
2982fba946
3 changed files with 22 additions and 15 deletions
4
Rakefile
4
Rakefile
|
@ -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
|
||||
|
||||
|
|
20
tasks/command_simulator.rb
Normal file
20
tasks/command_simulator.rb
Normal 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
|
|
@ -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
|
Loading…
Reference in a new issue