Skip to content

Commit

Permalink
Move zip file loading into its own class
Browse files Browse the repository at this point in the history
  • Loading branch information
silug committed Nov 12, 2024
1 parent 8a75dc6 commit 2b78a3e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
17 changes: 6 additions & 11 deletions lib/compliance_engine/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,18 @@ def reset_collection
# @param [String] path The Puppet environment archive file
# @return [NilClass]
def open_environment_zip(path)
require 'zip/filesystem'

self.modulepath = path

Zip::File.open(path) do |zipfile|
dir = zipfile.dir
file = zipfile.file

open(ComplianceEngine::EnvironmentLoader.new(path, root: '/'.dup, fileclass: file, dirclass: dir))
end
environment = ComplianceEngine::EnvironmentLoader::Zip.new(path)
self.modulepath = environment.modulepath
open(environment)
end

# Scan a Puppet environment
# @param [Array<String>] paths The Puppet modulepath components
# @return [NilClass]
def open_environment(*paths)
open(ComplianceEngine::EnvironmentLoader.new(*paths))
environment = ComplianceEngine::EnvironmentLoader.new(*paths)
self.modulepath = environment.modulepath
open(environment)
end

# Scan paths for compliance data files
Expand Down
2 changes: 1 addition & 1 deletion lib/compliance_engine/environment_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Load compliance engine data from a Puppet environment
class ComplianceEngine::EnvironmentLoader
def initialize(*paths, root: nil, fileclass: File, dirclass: Dir)
@modulepath = paths
@modulepath ||= paths
modules = paths.map do |path|
root ||= path
dirclass.entries(root)
Expand Down
19 changes: 19 additions & 0 deletions lib/compliance_engine/environment_loader/zip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'compliance_engine'
require 'compliance_engine/environment_loader'
require 'zip/filesystem'

# Load compliance engine data from a zip file containing a Puppet environment
class ComplianceEngine::EnvironmentLoader::Zip < ComplianceEngine::EnvironmentLoader
def initialize(path, root: '/'.dup)
@modulepath = path

::Zip::File.open(path) do |zipfile|
dir = zipfile.dir
file = zipfile.file

super(path, root: root, fileclass: file, dirclass: dir)
end
end
end

0 comments on commit 2b78a3e

Please sign in to comment.