bugfix: sudo-detection for target execution

When running `inspec exec` without the `target` option but against remote endpoints OR when executing it with the `localhost://` target AND having `--sudo` active it would abort the execution. `--target` is a helper to set the Train parameters for `backend`, `host`, `user`, `port`, and potentially `password`. The detection would fail on providing any of these separately without specifying `--target`. The same holds true for the `localhost` train backend or just `localhost://` target.

This type of detection has since moved to Train. The driving reason was to have this very useful check for localhost vs sudo run for any type of inspec (or for that matter: train) execution.

This PR depends on https://github.com/chef/train/pull/179 and the next release of train.

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2017-05-25 13:22:45 -05:00 committed by Christoph Hartmann
parent 1f647e1100
commit e0e5aee6a4
2 changed files with 1 additions and 8 deletions

View file

@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.1'
spec.add_dependency 'train', '>=0.22.0', '<1.0'
spec.add_dependency 'train', '>=0.24.0', '<1.0'
spec.add_dependency 'thor', '~> 0.19'
spec.add_dependency 'json', '>= 1.8', '< 3.0'
spec.add_dependency 'rainbow', '~> 2'

View file

@ -155,13 +155,6 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
configure_logger(opts)
o = opts.dup
# print error if user passed --sudo but with no --target
if opts[:sudo] && opts[:target].nil?
Inspec::Log.error('--sudo is only valid when running against a remote host using --target')
Inspec::Log.error('To run InSpec locally with elevated privileges, run `sudo inspec exec ...`')
exit 1
end
# run tests
run_tests(targets, o)
rescue StandardError => e