Class: ComplianceEngine::EnvironmentLoader::ZipBytes

Inherits:
ComplianceEngine::EnvironmentLoader show all
Defined in:
lib/compliance_engine/environment_loader/zip_bytes.rb

Overview

Load compliance engine data from a raw zip byte string containing a Puppet environment

Instance Attribute Summary

Attributes inherited from ComplianceEngine::EnvironmentLoader

#modulepath, #modules, #zipfile_path

Instance Method Summary collapse

Constructor Details

#initialize(bytes, root: '/'.dup, load_dotfiles: true, name: nil) ⇒ ZipBytes

Returns a new instance of ZipBytes.

Parameters:

  • bytes (String)

    raw binary zip data (e.g. from File.binread or an HTTP body)

  • root (String) (defaults to: '/'.dup)

    a directory within the zip file to use as the root of the environment

  • load_dotfiles (Boolean) (defaults to: true)

    whether to load dotfiles; defaults to true to preserve the historical zip-loader behaviour of including all files

  • name (String, nil) (defaults to: nil)

    identifier used for modulepath and downstream cache keys; defaults to “-” when no filename is available.



18
19
20
21
22
23
24
25
26
# File 'lib/compliance_engine/environment_loader/zip_bytes.rb', line 18

def initialize(bytes, root: '/'.dup, load_dotfiles: true, name: nil)
  raise ArgumentError, "bytes must be a String, got #{bytes.class}" unless bytes.is_a?(String)

  zipfile = ::Zip::File.open_buffer(bytes)
  @modulepath = name || '-'
  super(root, fileclass: zipfile.file, dirclass: zipfile.dir, zipfile_path: @modulepath, load_dotfiles: load_dotfiles)
ensure
  zipfile&.close
end