class R10K::Forge::ModuleRelease

Download, unpack, and install modules from the Puppet Forge

Attributes

download_path[RW]

@!attribute [rw] #download_path

@return [Pathname] Where the module tarball will be downloaded to.
forge_release[R]

@!attribute [r] #forge_release

@api private
@return [PuppetForge::V3::ModuleRelease] The Forge V3 API module
  release object used for downloading and verifying the module
  release.
unpack_path[RW]

@!attribute [rw] #unpack_path

@return [Pathname] Where the module will be unpacked to.

Public Class Methods

new(full_name, version) click to toggle source

@param full_name [String] The hyphen separated name of the module @param version [String] The version of the module

# File lib/r10k/forge/module_release.rb, line 36
def initialize(full_name, version)
  @full_name = PuppetForge::V3.normalize_name(full_name)
  @version   = version

  # Copy the PuppetForge base connection to the release class; the connection
  # objects are created in the class instances and thus are not shared with
  # subclasses.
  PuppetForge::V3::Release.conn = PuppetForge::V3::Base.conn
  @forge_release = PuppetForge::V3::Release.new({ :name => @full_name, :version => @version, :slug => "#{@full_name}-#{@version}" })

  @download_path = Pathname.new(Dir.mktmpdir) + (@forge_release.slug + '.tar.gz')
  @unpack_path   = Pathname.new(Dir.mktmpdir) + @forge_release.slug
end

Public Instance Methods

cleanup() click to toggle source

Remove all files created while downloading and unpacking the module.

# File lib/r10k/forge/module_release.rb, line 108
def cleanup
  cleanup_unpack_path
  cleanup_download_path
end
cleanup_download_path() click to toggle source

Remove the downloaded module release.

# File lib/r10k/forge/module_release.rb, line 121
def cleanup_download_path
  if download_path.exist?
    download_path.delete
  end
end
cleanup_unpack_path() click to toggle source

Remove the temporary directory used for unpacking the module.

# File lib/r10k/forge/module_release.rb, line 114
def cleanup_unpack_path
  if unpack_path.exist?
    unpack_path.rmtree
  end
end
download() click to toggle source

Download the module release to {#download_path}

@return [void]

# File lib/r10k/forge/module_release.rb, line 71
def download
  logger.debug1 "Downloading #{@forge_release.slug} from #{PuppetForge::Release.conn.url_prefix} to #{@download_path}"
  @forge_release.download(download_path)
end
install(target_dir) click to toggle source

Download, unpack, and install this module release to the target directory.

@example

environment_path = Pathname.new('/etc/puppetlabs/puppet/environments/production')
target_dir = environment_path + 'eight_hundred'
mod = R10K::Forge::ModuleRelease.new('branan-eight_hundred', '8.0.0')
mod.install(target_dir)

@param target_dir [Pathname] The full path to where the module should be installed. @return [void]

# File lib/r10k/forge/module_release.rb, line 60
def install(target_dir)
  download
  verify
  unpack(target_dir)
ensure
  cleanup
end
unpack(target_dir) click to toggle source

Unpack the module release at {#download_path} into the given target_dir

@param target_dir [Pathname] The final path where the module release

should be unpacked/installed into.

@return [void]

# File lib/r10k/forge/module_release.rb, line 93
def unpack(target_dir)
  logger.debug1 "Unpacking #{download_path} to #{target_dir} (with tmpdir #{unpack_path})"
  file_lists = PuppetForge::Unpacker.unpack(download_path.to_s, target_dir.to_s, unpack_path.to_s)
  logger.debug2 "Valid files unpacked: #{file_lists[:valid]}"
  if !file_lists[:invalid].empty?
    logger.warn "These files existed in the module's tar file, but are invalid filetypes and were not " +
                "unpacked: #{file_lists[:invalid]}"
  end
  if !file_lists[:symlinks].empty?
    raise R10K::Error, "Symlinks are unsupported and were not unpacked from the module tarball. " + 
                       "#{@forge_release.slug} contained these ignored symlinks: #{file_lists[:symlinks]}"
  end
end
verify() click to toggle source

Verify the module release downloaded to {#download_path} against the module release checksum given by the Puppet Forge

@raise [PuppetForge::V3::Release::ChecksumMismatch] The

downloaded module release checksum doesn't match the expected Forge
module release checksum.

@return [void]

# File lib/r10k/forge/module_release.rb, line 83
def verify
  logger.debug1 "Verifying that #{download_path} matches checksum #{@forge_release.file_md5}"
  @forge_release.verify(download_path)
end