Class: R10K::Forge::ModuleRelease
- Inherits:
-
Object
- Object
- R10K::Forge::ModuleRelease
- 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
Instance Attribute Summary collapse
-
#download_path ⇒ Pathname
Where the module tarball will be downloaded to.
-
#forge_release ⇒ Object
readonly
Returns the value of attribute forge_release.
-
#unpack_path ⇒ Pathname
Where the module will be unpacked to.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Remove all files created while downloading and unpacking the module.
-
#cleanup_download_path ⇒ Object
Remove the downloaded module release.
-
#cleanup_unpack_path ⇒ Object
Remove the temporary directory used for unpacking the module.
-
#download ⇒ void
Download the module release to #download_path.
-
#initialize(full_name, version) ⇒ ModuleRelease
constructor
A new instance of ModuleRelease.
-
#install(target_dir) ⇒ void
Download, unpack, and install this module release to the target directory.
-
#unpack(target_dir) ⇒ void
Unpack the module release at #download_path into the given target_dir.
-
#verify ⇒ void
Verify the module release downloaded to #download_path against the module release checksum given by the Puppet Forge.
Methods included from Logging
debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Methods included from Settings::Mixin
Constructor Details
#initialize(full_name, version) ⇒ ModuleRelease
Returns a new instance of ModuleRelease.
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_path ⇒ Pathname
Returns 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_release ⇒ Object (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_path ⇒ Pathname
Returns 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
#cleanup ⇒ Object
Remove all files created while downloading and unpacking the module.
108 109 110 111 |
# File 'lib/r10k/forge/module_release.rb', line 108 def cleanup cleanup_unpack_path cleanup_download_path end |
#cleanup_download_path ⇒ Object
Remove the downloaded module release.
121 122 123 124 125 |
# 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 ⇒ Object
Remove the temporary directory used for unpacking the module.
114 115 116 117 118 |
# File 'lib/r10k/forge/module_release.rb', line 114 def cleanup_unpack_path if unpack_path.exist? unpack_path.rmtree end end |
#download ⇒ void
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.
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
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# 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.debug1 "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 ⇒ void
This method returns an undefined value.
Verify the module release downloaded to #download_path against the module release checksum given by the Puppet Forge
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 |