Class: R10K::Forge::ModuleRelease

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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



41
42
43
44
45
46
47
48
49
50
# File 'lib/r10k/forge/module_release.rb', line 41

def initialize(full_name, version)
  @full_name = PuppetForge::V3.normalize_name(full_name)
  @version   = version

  @forge_release = PuppetForge::V3::ModuleRelease.new(@full_name, @version)
  @forge_release.conn.proxy(proxy)

  @download_path = Pathname.new(Dir.mktmpdir) + (slug + '.tar.gz')
  @unpack_path   = Pathname.new(Dir.mktmpdir) + 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.



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

def download_path
  @download_path
end

#forge_releaseObject (readonly)

Returns the value of attribute forge_release.



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

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.



37
38
39
# File 'lib/r10k/forge/module_release.rb', line 37

def unpack_path
  @unpack_path
end

Instance Method Details

#cleanupObject

Remove all files created while downloading and unpacking the module.



110
111
112
113
# File 'lib/r10k/forge/module_release.rb', line 110

def cleanup
  cleanup_unpack_path
  cleanup_download_path
end

#cleanup_download_pathObject

Remove the downloaded module release.



123
124
125
126
127
# File 'lib/r10k/forge/module_release.rb', line 123

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.



116
117
118
119
120
# File 'lib/r10k/forge/module_release.rb', line 116

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



73
74
75
76
# File 'lib/r10k/forge/module_release.rb', line 73

def download
  logger.debug1 "Downloading #{@forge_release.slug} from #{@forge_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.



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

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.



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/r10k/forge/module_release.rb', line 95

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

#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:



85
86
87
88
# File 'lib/r10k/forge/module_release.rb', line 85

def verify
  logger.debug1 "Verifying that #{download_path} matches checksum #{data['file_md5']}"
  @forge_release.verify(download_path)
end