Class: PuppetForge::V3::ModuleRelease

Inherits:
Object
  • Object
show all
Includes:
Connection
Defined in:
lib/shared/puppet_forge/v3/module_release.rb

Overview

Access metadata and downloads for a specific module release.

Defined Under Namespace

Classes: ChecksumMismatch

Constant Summary

Constants included from Connection

Connection::USER_AGENT

Instance Attribute Summary collapse

Attributes included from Connection

#conn

Instance Method Summary collapse

Methods included from Connection

authorization, authorization=, #make_connection

Constructor Details

#initialize(full_name, version) ⇒ ModuleRelease

Returns a new instance of ModuleRelease.

Parameters:

  • full_name (String)

    The name of the module, will be normalized to a hyphen delimited name.

  • version (String)


23
24
25
26
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 23

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

Instance Attribute Details

#full_nameObject (readonly)

Returns the value of attribute full_name.



14
15
16
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 14

def full_name
  @full_name
end

#versionObject (readonly)

Returns the value of attribute version.



18
19
20
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 18

def version
  @version
end

Instance Method Details

#dataHash

Returns The complete Forge response for this release.

Returns:

  • (Hash)

    The complete Forge response for this release.



29
30
31
32
33
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 29

def data
  @data ||= conn.get(resource_url).body
rescue Faraday::ResourceNotFound => e
  raise PuppetForge::ModuleReleaseNotFound, "The module release #{slug} does not exist on #{conn.url_prefix}.", e.backtrace
end

#download(path) ⇒ void

This method returns an undefined value.

Download this module release to the specified path.

Parameters:

  • path (Pathname)


44
45
46
47
48
49
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 44

def download(path)
  resp = conn.get(file_url)
  path.open('wb') { |fh| fh.write(resp.body) }
rescue Faraday::ResourceNotFound => e
  raise PuppetForge::ModuleReleaseNotFound, "The module release #{slug} does not exist on #{conn.url_prefix}.", e.backtrace
end

#slugString

Returns The unique identifier for this module release.

Returns:

  • (String)

    The unique identifier for this module release.



36
37
38
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 36

def slug
  "#{full_name}-#{version}"
end

#verify(path) ⇒ void

This method returns an undefined value.

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

Parameters:

  • path (Pathname)


55
56
57
58
59
60
61
# File 'lib/shared/puppet_forge/v3/module_release.rb', line 55

def verify(path)
  expected_md5 = data['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