class PuppetForge::V3::Release

Models a specific release version of a Puppet Module on the Forge.

Public Instance Methods

download(path) click to toggle source

Downloads the Release tarball to the specified file path.

@param path [Pathname] @return [void]

# File lib/puppet_forge/v3/release.rb, line 26
def download(path)
  resp = self.class.conn.get(download_url)
  path.open('wb') { |fh| fh.write(resp.body) }
rescue Faraday::ResourceNotFound => e
  raise PuppetForge::ReleaseNotFound, (_("The module release %{release_slug} does not exist on %{url}.") % {release_slug: slug, url: self.class.conn.url_prefix}), e.backtrace
rescue Faraday::ClientError => e
  if e.response && e.response[:status] == 403
    raise PuppetForge::ReleaseForbidden.from_response(e.response)
  else
    raise e
  end
end
download_url() click to toggle source

Returns a fully qualified URL for downloading this release from the Forge.

@return [String] fully qualified download URL for release

# File lib/puppet_forge/v3/release.rb, line 14
def download_url
  if URI.parse(file_uri).host.nil?
    URI.join(PuppetForge.host, file_uri[1..-1]).to_s
  else
    file_uri
  end
end
verify(path) click to toggle source

Verify that a downloaded module matches the checksum in the metadata for this release.

@param path [Pathname] @return [void]

# File lib/puppet_forge/v3/release.rb, line 43
def verify(path)
  expected_md5 = file_md5
  file_md5     = Digest::MD5.file(path).hexdigest
  if expected_md5 != file_md5
    raise ChecksumMismatch.new("Expected #{path} checksum to be #{expected_md5}, got #{file_md5}")
  end
end