Class: R10K::Forge::ModuleRelease
- Inherits:
-
Object
- Object
- R10K::Forge::ModuleRelease
- 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
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.
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_path ⇒ Pathname
Returns 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_release ⇒ Object (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_path ⇒ Pathname
Returns 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
#cleanup ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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 |
#download ⇒ void
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.
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
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 |
#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
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 |