Class: ComplianceEngine::ModuleLoader
- Inherits:
-
Object
- Object
- ComplianceEngine::ModuleLoader
- Defined in:
- lib/compliance_engine/module_loader.rb
Overview
Load compliance engine data from a Puppet module
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#zipfile_path ⇒ Object
readonly
Returns the value of attribute zipfile_path.
Instance Method Summary collapse
-
#initialize(path, fileclass: File, dirclass: Dir, zipfile_path: nil) ⇒ ModuleLoader
constructor
Initialize a ModuleLoader from a Puppet module path.
Constructor Details
#initialize(path, fileclass: File, dirclass: Dir, zipfile_path: nil) ⇒ ModuleLoader
Initialize a ModuleLoader from a Puppet module path
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/compliance_engine/module_loader.rb', line 15 def initialize(path, fileclass: File, dirclass: Dir, zipfile_path: nil) raise ComplianceEngine::Error, "#{path} is not a directory" unless fileclass.directory?(path) @name = nil @version = nil @files = [] @zipfile_path = zipfile_path # Read the Puppet module's metadata.json = File.join(path.to_s, 'metadata.json') if fileclass.exist?() begin = ComplianceEngine::DataLoader::Json.new(, fileclass: fileclass) @name = .data['name'] @version = .data['version'] rescue => e ComplianceEngine.log.warn "Could not parse #{}: #{e.}" end end # In this directory, we want to look for all yaml and json files # under SIMP/compliance_profiles and simp/compliance_profiles. globs = ['SIMP/compliance_profiles', 'simp/compliance_profiles'] .select { |dir| fileclass.directory?(File.join(path, dir)) } .map { |dir| ['yaml', 'json'].map { |type| File.join(path, dir, '**', "*.#{type}") } }.flatten # Using .each here to make mocking with rspec easier. globs.each do |glob| dirclass.glob(glob).sort.each do |file| key = if @zipfile_path File.join(@zipfile_path, '.', file.to_s) else file.to_s end loader = if File.extname(file.to_s) == '.json' ComplianceEngine::DataLoader::Json.new(file.to_s, fileclass: fileclass, key: key) else ComplianceEngine::DataLoader::Yaml.new(file.to_s, fileclass: fileclass, key: key) end @files << loader rescue => e ComplianceEngine.log.warn "Could not load #{file}: #{e.}" end end end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
62 63 64 |
# File 'lib/compliance_engine/module_loader.rb', line 62 def files @files end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
62 63 64 |
# File 'lib/compliance_engine/module_loader.rb', line 62 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
62 63 64 |
# File 'lib/compliance_engine/module_loader.rb', line 62 def version @version end |
#zipfile_path ⇒ Object (readonly)
Returns the value of attribute zipfile_path.
62 63 64 |
# File 'lib/compliance_engine/module_loader.rb', line 62 def zipfile_path @zipfile_path end |