class Proxy::OpenSCAP::ShellWrapper

Attributes

script_name[R]

Public Instance Methods

command(in_file, out_file) click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 64
def command(in_file, out_file)
  raise NotImplementedError, "Must be implemented"
end
exception_message() click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 72
def exception_message
  failure_message
end
execute_shell_command(in_file_content = nil) click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 17
def execute_shell_command(in_file_content = nil)
  out_file = Tempfile.new(out_filename, "/var/tmp")
  in_file = prepare_in_file in_file_content
  comm = command(in_file, out_file)
  logger.debug "Executing: #{comm}"
  output = nil
  begin
    %x#{comm}`
    output = out_file.read
  rescue => e
    logger.debug failure_message
    logger.debug e.message
    logger.debug e.backtrace.join("\n\t")
  ensure
    close_unlink out_file, in_file
  end
  raise OpenSCAPException, exception_message if output.nil? || output.empty?
  output
end
failure_message() click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 68
def failure_message
  raise NotImplementedError, "Must be implemented"
end
in_filename() click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 52
def in_filename
  @in_filename ||= unique_filename
end
out_filename() click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 56
def out_filename
  @out_filename ||= unique_filename
end
prepare_in_file(in_file_content) click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 44
def prepare_in_file(in_file_content)
  return unless in_file_content
  file = Tempfile.new(in_filename, "/var/tmp")
  file.write in_file_content
  file.rewind
  file
end
script_location() click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 10
def script_location
  raise NotImplementedError, 'Must have @script_name' unless script_name
  path = File.join(File.dirname(File.expand_path(__FILE__)), '../../bin', script_name)
  return path if File.exist? path
  script_name
end
unique_filename() click to toggle source
# File lib/smart_proxy_openscap/shell_wrapper.rb, line 60
def unique_filename
  SecureRandom.uuid
end