Module: ComplianceEngine

Defined in:
lib/compliance_engine.rb,
lib/compliance_engine/version.rb,
lib/compliance_engine/tolerance.rb,
lib/compliance_engine/puppet_logger.rb

Overview

Work with compliance data

Defined Under Namespace

Modules: Tolerance Classes: CLI, Ce, Ces, Check, Checks, Collection, Component, Control, Controls, Data, DataLoader, DataVersion, EnvironmentLoader, Error, ModuleLoader, Profile, Profiles, PuppetLogger

Constant Summary collapse

VERSION =
'0.5.0'

Class Method Summary collapse

Class Method Details

.install_puppet_loggervoid

This method returns an undefined value.

Install a PuppetLogger unless a logger has already been explicitly configured. Extracted so the behaviour can be unit-tested without reloading enforcement.rb.



88
89
90
91
92
93
# File 'lib/compliance_engine.rb', line 88

def self.install_puppet_logger
  return unless @log.nil?

  require_relative 'compliance_engine/puppet_logger'
  @log = PuppetLogger.new
end

.logLogger, ComplianceEngine::PuppetLogger

Get the logger

Returns:



31
32
33
34
35
36
37
# File 'lib/compliance_engine.rb', line 31

def self.log
  return @log unless @log.nil?

  @log = Logger.new($stderr)
  @log.level = Logger::WARN
  @log
end

.log=(value) ⇒ Object

Set the logger

Parameters:



42
43
44
# File 'lib/compliance_engine.rb', line 42

def self.log=(value)
  @log = value
end

.new(*paths) ⇒ ComplianceEngine::Data

Open compliance data

Parameters:

  • paths (Array<String>)

    The paths to the compliance data files

Returns:



24
25
26
# File 'lib/compliance_engine.rb', line 24

def self.new(*paths)
  Data.new(*paths)
end

.open(*paths) ⇒ ComplianceEngine::Data

Open compliance data

Parameters:

  • paths (Array<String>)

    The paths to the compliance data files

Returns:



16
17
18
# File 'lib/compliance_engine.rb', line 16

def self.open(*paths)
  Data.new(*paths)
end

.schemaHash

Return the parsed JSON schema for SCE data files

Returns:

  • (Hash)

    the parsed JSON schema



56
57
58
59
60
61
62
63
64
# File 'lib/compliance_engine.rb', line 56

def self.schema
  require 'json'
  @schema ||= begin
    path = schema_path
    deep_freeze(JSON.parse(File.read(path, encoding: 'UTF-8')))
  rescue Errno::ENOENT, JSON::ParserError => e
    raise Error, "Failed to load schema from #{path}: #{e.class}: #{e.message}"
  end
end

.schema_pathString

Return the path to the bundled JSON schema for SCE data files

Returns:

  • (String)

    absolute path to sce-schema.json



49
50
51
# File 'lib/compliance_engine.rb', line 49

def self.schema_path
  File.expand_path(File.join(__dir__, 'compliance_engine', 'sce-schema.json'))
end