class RuboCop::Cop::Chef::Correctness::ConditionalRubyShellout
Don’t use Ruby
to shellout in a ‘only_if` / `not_if` conditional. Any string value used in an `only_if` / `not_if` is executed in your system’s shell and the return code of the command is the result for the ‘not_if` / `only_if` determination.
@example
### incorrect cookbook_file '/logs/foo/error.log' do source 'error.log' only_if { system('wget https://www.bar.com/foobar.txt -O /dev/null') } end cookbook_file '/logs/foo/error.log' do source 'error.log' only_if { shell_out('wget https://www.bar.com/foobar.txt -O /dev/null').exitstatus == 0 } end ### correct cookbook_file '/logs/foo/error.log' do source 'error.log' only_if 'wget https://www.bar.com/foobar.txt -O /dev/null' end
Constants
- MSG
Public Instance Methods
Source
# File lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb, line 58 def on_block(node) conditional_shellout?(node) do |type, val| add_offense(node, severity: :refactor) do |corrector| corrector.replace(node, "#{type} #{val.source}") end end end