Class: Proxy::OpenSCAP::ShellWrapper

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/smart_proxy_openscap/shell_wrapper.rb

Direct Known Subclasses

OpenscapHtmlGenerator, PolicyParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#script_nameObject (readonly)

Returns the value of attribute script_name.



8
9
10
# File 'lib/smart_proxy_openscap/shell_wrapper.rb', line 8

def script_name
  @script_name
end

Instance Method Details



37
38
39
40
41
42
# File 'lib/smart_proxy_openscap/shell_wrapper.rb', line 37

def close_unlink(*files)
  files.compact.each do |file|
    file.close
    file.unlink
  end
end

#command(in_file, out_file) ⇒ Object

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/smart_proxy_openscap/shell_wrapper.rb', line 64

def command(in_file, out_file)
  raise NotImplementedError, "Must be implemented"
end

#exception_messageObject



72
73
74
# File 'lib/smart_proxy_openscap/shell_wrapper.rb', line 72

def exception_message
  failure_message
end

#execute_shell_command(in_file_content = nil) ⇒ Object

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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
    `#{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_messageObject

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/smart_proxy_openscap/shell_wrapper.rb', line 68

def failure_message
  raise NotImplementedError, "Must be implemented"
end

#in_filenameObject



52
53
54
# File 'lib/smart_proxy_openscap/shell_wrapper.rb', line 52

def in_filename
  @in_filename ||= unique_filename
end

#out_filenameObject



56
57
58
# File 'lib/smart_proxy_openscap/shell_wrapper.rb', line 56

def out_filename
  @out_filename ||= unique_filename
end

#prepare_in_file(in_file_content) ⇒ Object



44
45
46
47
48
49
50
# 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_locationObject

Raises:

  • (NotImplementedError)


10
11
12
13
14
15
# 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_filenameObject



60
61
62
# File 'lib/smart_proxy_openscap/shell_wrapper.rb', line 60

def unique_filename
  SecureRandom.uuid
end