Skip to content

Commit

Permalink
drop hidden_patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni authored and ekohl committed Oct 21, 2024
1 parent d3020de commit 31ac520
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
21 changes: 6 additions & 15 deletions lib/foreman_maintain/utils/command_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ class CommandRunner
attr_reader :logger, :command

def initialize(logger, command, options)
options.validate_options!(:stdin, :hidden_patterns, :interactive, :valid_exit_statuses,
:env)
options.validate_options!(:stdin, :interactive, :valid_exit_statuses, :env)
options[:valid_exit_statuses] ||= [0]
options[:env] ||= {}
@logger = logger
@command = command
@stdin = options[:stdin]
@hidden_patterns = Array(options[:hidden_patterns]).compact
@interactive = options[:interactive]
@options = options
@valid_exit_statuses = options[:valid_exit_statuses]
Expand All @@ -24,13 +22,13 @@ def initialize(logger, command, options)
end

def run
logger&.debug(hide_strings("Running command #{@command} with stdin #{@stdin.inspect}"))
logger&.debug("Running command #{@command} with stdin #{@stdin.inspect}")
if @interactive
run_interactively
else
run_non_interactively
end
logger&.debug("output of the command:\n #{hide_strings(output)}")
logger&.debug("output of the command:\n #{output}")
end

def interactive?
Expand All @@ -52,10 +50,10 @@ def success?
end

def execution_error
raise Error::ExecutionError.new(hide_strings(@command),
raise Error::ExecutionError.new(@command,
exit_status,
hide_strings(@stdin),
@interactive ? nil : hide_strings(@output))
@stdin,
@interactive ? nil : @output)
end

private
Expand Down Expand Up @@ -97,13 +95,6 @@ def run_non_interactively
def full_command
"#{@command} 2>&1"
end

def hide_strings(string)
return unless string
@hidden_patterns.reduce(string) do |result, hidden_pattern|
result.gsub(hidden_pattern, '[FILTERED]')
end
end
end
end
end
16 changes: 0 additions & 16 deletions test/lib/utils/command_runner_test.rb

This file was deleted.

0 comments on commit 31ac520

Please sign in to comment.