Class: R10K::Forge::ModuleRelease

Inherits:
Object
  • Object
show all
Includes:
Logging, Settings::Mixin
Defined in:
lib/r10k/forge/module_release.rb

Overview

Download, unpack, and install modules from the Puppet Forge

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Methods included from Settings::Mixin

included

Constructor Details

#initialize(full_name, version) ⇒ ModuleRelease

Returns a new instance of ModuleRelease.

Parameters:

  • full_name (String)

    The hyphen separated name of the module

  • version (String)

    The version of the module



36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

Instance Attribute Details

#download_pathPathname

Returns Where the module tarball will be downloaded to.

Returns:

  • (Pathname)

    Where the module tarball will be downloaded to.



28
29
30
# File 'lib/r10k/forge/module_release.rb', line 28

def download_path
  @download_path
end

#forge_releaseObject (readonly)

Returns the value of attribute forge_release.



24
25
26
# File 'lib/r10k/forge/module_release.rb', line 24

def forge_release
  @forge_release
end

#unpack_pathPathname

Returns Where the module will be unpacked to.

Returns:

  • (Pathname)

    Where the module will be unpacked to.



32
33
34
# File 'lib/r10k/forge/module_release.rb', line 32

def unpack_path
  @unpack_path
end

Instance Method Details

#cleanupObject

Remove all files created while downloading and unpacking the module.



106
107
108
109
# File 'lib/r10k/forge/module_release.rb', line 106

def cleanup
  cleanup_unpack_path
  cleanup_download_path
end

#cleanup_download_pathObject

Remove the downloaded module release.



119
120
121
122
123
# File 'lib/r10k/forge/module_release.rb', line 119

def cleanup_download_path
  if download_path.exist?
    download_path.delete
  end
end

#cleanup_unpack_pathObject

Remove the temporary directory used for unpacking the module.



112
113
114
115
116
# File 'lib/r10k/forge/module_release.rb', line 112

def cleanup_unpack_path
  if unpack_path.exist?
    unpack_path.rmtree
  end
end

#downloadvoid

This method returns an undefined value.

Download the module release to #download_path



71
72
73
74
# 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) ⇒ void

This method returns an undefined value.

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

Examples:

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)

Parameters:

  • target_dir (Pathname)

    The full path to where the module should be installed.



60
61
62
63
64
65
66
# File 'lib/r10k/forge/module_release.rb', line 60

def install(target_dir)
  download
  verify
  unpack(target_dir)
ensure
  cleanup
end

#unpack(target_dir) ⇒ void

This method returns an undefined value.

Unpack the module release at #download_path into the given target_dir

Parameters:

  • target_dir (Pathname)

    The final path where the module release should be unpacked/installed into.



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/r10k/forge/module_release.rb', line 93

def unpack(target_dir)
  logger.debug1 _("Unpacking %{download_path} to %{target_dir} (with tmpdir %{tmp_path})") % {download_path: download_path, target_dir: target_dir, tmp_path: unpack_path}
  file_lists = PuppetForge::Unpacker.unpack(download_path.to_s, target_dir.to_s, unpack_path.to_s)
  logger.debug2 _("Valid files unpacked: %{valid_files}") % {valid_files: file_lists[:valid]}
  if !file_lists[:invalid].empty?
    logger.debug1 _("These files existed in the module's tar file, but are invalid filetypes and were not unpacked: %{invalid_files}") % {invalid_files: file_lists[:invalid]}
  end
  if !file_lists[:symlinks].empty?
    logger.warn _("Symlinks are unsupported and were not unpacked from the module tarball. %{release_slug} contained these ignored symlinks: %{symlinks}") % {release_slug: @forge_release.slug, symlinks: file_lists[:symlinks]}
  end
end

#verifyvoid

This method returns an undefined value.

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

Raises:

  • (PuppetForge::V3::Release::ChecksumMismatch)

    The downloaded module release checksum doesn’t match the expected Forge module release checksum.



83
84
85
86
# 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