summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordheerajd-msys <dheeraj.dubey@msystechnologies.com>2018-06-15 15:58:25 +0530
committerdheerajd-msys <dheeraj.dubey@msystechnologies.com>2018-06-15 19:35:51 +0530
commite6c8a07699915d5843772a951b7d9c0bc2c8ca8c (patch)
tree0db3210f4bba2e2589f98184f95ecf50c2271921 /lib
parent36da3db58fc5b2cd1b073f0458c6eec335d07d85 (diff)
downloadmixlib-shellout-e6c8a07699915d5843772a951b7d9c0bc2c8ca8c.tar.gz
add sensitive feature
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/mixlib/shellout.rb6
-rw-r--r--lib/mixlib/shellout/unix.rb11
-rw-r--r--lib/mixlib/shellout/windows.rb6
3 files changed, 15 insertions, 8 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb
index 76e6959..e95e7df 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -112,6 +112,8 @@ module Mixlib
# Runs windows process with elevated privileges. Required for Powershell commands which need elevated privileges
attr_accessor :elevated
+ attr_accessor :sensitive
+
# === Arguments:
# Takes a single command, or a list of command fragments. These are used
# as arguments to Kernel.exec. See the Kernel.exec documentation for more
@@ -176,6 +178,7 @@ module Mixlib
@terminate_reason = nil
@timeout = nil
@elevated = false
+ @sensitive = false
if command_args.last.is_a?(Hash)
parse_options(command_args.pop)
@@ -227,6 +230,7 @@ module Mixlib
# showing the exact command executed. Used by +invalid!+ to show command
# results when the command exited with an unexpected status.
def format_for_exception
+ return "Command execution failed. STDOUT/STDERR suppressed for sensitive resource" if sensitive
msg = ""
msg << "#{@terminate_reason}\n" if @terminate_reason
msg << "---- Begin output of #{command} ----\n"
@@ -345,6 +349,8 @@ module Mixlib
self.login = setting
when "elevated"
self.elevated = setting
+ when "sensitive"
+ self.sensitive = setting
else
raise InvalidCommandOption, "option '#{option.inspect}' is not a valid option for #{self.class.name}"
end
diff --git a/lib/mixlib/shellout/unix.rb b/lib/mixlib/shellout/unix.rb
index bc0fc69..881d54a 100644
--- a/lib/mixlib/shellout/unix.rb
+++ b/lib/mixlib/shellout/unix.rb
@@ -1,4 +1,4 @@
-#--
+#
# Author:: Daniel DeLeo (<dan@chef.io>)
# Copyright:: Copyright (c) 2010-2016 Chef Software, Inc.
# License:: Apache License, Version 2.0
@@ -284,7 +284,7 @@ module Mixlib
end
def read_stdout_to_buffer
- while chunk = child_stdout.read_nonblock(READ_SIZE)
+ while ( chunk = child_stdout.read_nonblock(READ_SIZE) )
@stdout << chunk
@live_stdout << chunk if @live_stdout
end
@@ -294,7 +294,7 @@ module Mixlib
end
def read_stderr_to_buffer
- while chunk = child_stderr.read_nonblock(READ_SIZE)
+ while ( chunk = child_stderr.read_nonblock(READ_SIZE) )
@stderr << chunk
@live_stderr << chunk if @live_stderr
end
@@ -304,7 +304,7 @@ module Mixlib
end
def read_process_status_to_buffer
- while chunk = child_process_status.read_nonblock(READ_SIZE)
+ while ( chunk = child_process_status.read_nonblock(READ_SIZE) )
@process_status << chunk
end
rescue Errno::EAGAIN
@@ -402,7 +402,8 @@ module Mixlib
# Try to reap the child process but don't block if it isn't dead yet.
def attempt_reap
- if results = Process.waitpid2(@child_pid, Process::WNOHANG)
+ results = Process.waitpid2(@child_pid, Process::WNOHANG)
+ if results
@reaped = true
@status = results.last
else
diff --git a/lib/mixlib/shellout/windows.rb b/lib/mixlib/shellout/windows.rb
index 226c7c4..5116d5f 100644
--- a/lib/mixlib/shellout/windows.rb
+++ b/lib/mixlib/shellout/windows.rb
@@ -1,4 +1,4 @@
-#--
+#
# Author:: Daniel DeLeo (<dan@chef.io>)
# Author:: John Keiser (<jkeiser@chef.io>)
# Author:: Ho-Sheng Hsiao (<hosh@chef.io>)
@@ -122,7 +122,7 @@ module Mixlib
wmi = WmiLite::Wmi.new
kill_process_tree(process.process_id, wmi, logger)
Process.kill(:KILL, process.process_id)
- rescue Errno::EIO, SystemCallError
+ rescue
logger.warn("Failed to kill timed out process #{process.process_id}") if logger
end
@@ -357,7 +357,7 @@ module Mixlib
].join)
end
Process.kill(:KILL, instance.wmi_ole_object.processid)
- rescue Errno::EIO, SystemCallError
+ rescue
if logger
logger.debug([
"Failed to kill child process #{child_pid}::",