Module: Proxy::OpenSCAP

Extended by:
Log
Defined in:
lib/smart_proxy_openscap/helpers.rb,
lib/smart_proxy_openscap/version.rb,
lib/smart_proxy_openscap/arf_html.rb,
lib/smart_proxy_openscap/arf_parser.rb,
lib/smart_proxy_openscap/fetch_file.rb,
lib/smart_proxy_openscap/storage_fs.rb,
lib/smart_proxy_openscap/openscap_api.rb,
lib/smart_proxy_openscap/openscap_lib.rb,
lib/smart_proxy_openscap/policy_guide.rb,
lib/smart_proxy_openscap/content_parser.rb,
lib/smart_proxy_openscap/fetch_scap_file.rb,
lib/smart_proxy_openscap/openscap_plugin.rb,
lib/smart_proxy_openscap/profiles_parser.rb,
lib/smart_proxy_openscap/spool_forwarder.rb,
lib/smart_proxy_openscap/foreman_forwarder.rb,
lib/smart_proxy_openscap/storage_fs_common.rb,
lib/smart_proxy_openscap/validate_settings.rb,
lib/smart_proxy_openscap/openscap_exception.rb,
lib/smart_proxy_openscap/openscap_import_api.rb,
lib/smart_proxy_openscap/foreman_arf_forwarder.rb,
lib/smart_proxy_openscap/openscap_html_generator.rb,
lib/smart_proxy_openscap/storage.rb,
lib/smart_proxy_openscap.rb

Overview

lib/helpers.rb

Defined Under Namespace

Modules: Helpers, StorageFsCommon Classes: Api, ArfHtml, ArfParser, ContentParser, FetchFile, FetchScapFile, FileNotFound, ForemanArfForwarder, ForemanForwarder, ImportApi, OpenSCAPException, OpenscapHtmlGenerator, Plugin, PolicyGuide, ProfilesParser, ReportDecompressError, ReportUploadError, SpoolForwarder, Storage, StorageFs, StoreCorruptedError, StoreFailedError, StoreReportError, StoreSpoolError, ValidateSettings

Constant Summary collapse

VERSION =
'0.12.0'
HTTP_ERRORS =
[
  EOFError,
  Errno::ECONNRESET,
  Errno::EINVAL,
  Errno::ECONNREFUSED,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  Timeout::Error
]

Class Method Summary collapse

Class Method Details

.common_name(request) ⇒ Object

Raises:

  • (Proxy::Error::Unauthorized)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/smart_proxy_openscap/openscap_lib.rb', line 42

def self.common_name(request)
  client_cert = request.env['SSL_CLIENT_CERT']
  raise Proxy::Error::Unauthorized, "Client certificate required!" if client_cert.to_s.empty?

  begin
    client_cert = OpenSSL::X509::Certificate.new(client_cert)
  rescue OpenSSL::OpenSSLError => e
    raise Proxy::Error::Unauthorized, e.message
  end
  cn = client_cert.subject.to_a.detect { |name, value| name == 'CN' }
  cn = cn[1] unless cn.nil?
  raise Proxy::Error::Unauthorized, "Common Name not found in the certificate" unless cn
  cn
end

.execute!(*cmd) ⇒ Object



68
69
70
71
72
# File 'lib/smart_proxy_openscap/openscap_lib.rb', line 68

def self.execute!(*cmd)
  out, err, status = Open3.capture3(*cmd)
  raise "'#{cmd.join(' ')} exited with #{status.exitstatus}: #{err}" unless status.success?
  [out, err, status]
end

.fullpath(path = Proxy::OpenSCAP::Plugin.settings.contentdir) ⇒ Object



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

def self.fullpath(path = Proxy::OpenSCAP::Plugin.settings.contentdir)
  pathname = Pathname.new(path)
  pathname.relative? ? pathname.expand_path(Sinatra::Base.root).to_s : path
end

.plugin_settingsObject



33
34
35
# File 'lib/smart_proxy_openscap/openscap_lib.rb', line 33

def self.plugin_settings
  @@settings ||= OpenStruct.new(read_settings)
end

.read_settingsObject



37
38
39
40
# File 'lib/smart_proxy_openscap/openscap_lib.rb', line 37

def self.read_settings
  ::Proxy::OpenSCAP::Plugin.default_settings.merge(
    YAML.load_file(File.join(::Proxy::SETTINGS.settings_directory, ::Proxy::OpenSCAP::Plugin.settings_file)))
end

.send_spool_to_foreman(loaded_settings) ⇒ Object



57
58
59
60
61
# File 'lib/smart_proxy_openscap/openscap_lib.rb', line 57

def self.send_spool_to_foreman(loaded_settings)
  arf_dir = File.join(loaded_settings.spooldir, "/arf")
  return unless File.exist? arf_dir
  SpoolForwarder.new(loaded_settings).post_arf_from_spool(arf_dir)
end