Class: Puppet::Forge Private

Inherits:
SemanticPuppet::Dependency::Source
  • Object
show all
Includes:
Errors
Defined in:
lib/puppet/forge.rb,
lib/puppet/forge/cache.rb,
lib/puppet/forge/repository.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Defined Under Namespace

Modules: Errors Classes: Cache, ModuleRelease, Repository

Constant Summary collapse

USER_AGENT =
"PMT/1.1.1 (v3; Net::HTTP)"
MODULE_RELEASE_EXCLUSIONS =
%w[readme changelog license uri module tags supported file_size downloads created_at updated_at deleted_at].join(',').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = Puppet[:module_repository]) ⇒ Forge

Returns a new instance of Forge.



27
28
29
30
# File 'lib/puppet/forge.rb', line 27

def initialize(host = Puppet[:module_repository])
  @host = host
  @repository = Puppet::Forge::Repository.new(host, USER_AGENT)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#repositoryObject (readonly)

Returns the value of attribute repository.



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

def repository
  @repository
end

Instance Method Details

#fetch(input) ⇒ Array<SemanticPuppet::Dependency::ModuleRelease>

Fetches ModuleRelease entries for each release of the named module.

Parameters:

  • the module name to look up

Returns:

  • a list of releases for the given name

See Also:

  • SemanticPuppet::Dependency::Source#fetch


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/puppet/forge.rb', line 95

def fetch(input)
  name = input.tr('/', '-')
  uri = "/v3/releases?module=#{name}&sort_by=version&exclude_fields=#{MODULE_RELEASE_EXCLUSIONS}"
  if Puppet[:module_groups]
    uri += "&module_groups=#{Puppet[:module_groups].tr('+', ' ')}"
  end
  releases = []

  while uri
    # make_http_request URI encodes parameters
    response = make_http_request(uri)

    if response.code == 200
      response = Puppet::Util::Json.load(response.body)
    else
      raise ResponseError.new(:uri => response.url, :response => response)
    end

    releases.concat(process(response['results']))
    uri = decode_uri(response['pagination']['next'])
  end

  releases
end

#make_http_request(*args) ⇒ Object



120
121
122
# File 'lib/puppet/forge.rb', line 120

def make_http_request(*args)
  @repository.make_http_request(*args)
end

#search(term) ⇒ Array

Return a list of module metadata hashes that match the search query. This return value is used by the module_tool face install search, and displayed to on the console.

Example return value:

[

{
  "author"      => "puppetlabs",
  "name"        => "bacula",
  "tag_list"    => ["backup", "bacula"],
  "releases"    => [{"version"=>"0.0.1"}, {"version"=>"0.0.2"}],
  "full_name"   => "puppetlabs/bacula",
  "version"     => "0.0.2",
  "project_url" => "https://github.com/puppetlabs/puppetlabs-bacula",
  "desc"        => "bacula"
}

]

Parameters:

  • search term

Returns:

  • modules found

Raises:

  • if there is a network related error

  • if there is a problem verifying the remote SSL certificate

  • if the repository returns a bad HTTP response



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/puppet/forge.rb', line 59

def search(term)
  matches = []
  uri = "/v3/modules?query=#{term}"
  if Puppet[:module_groups]
    uri += "&module_groups=#{Puppet[:module_groups].tr('+', ' ')}"
  end

  while uri
    # make_http_request URI encodes parameters
    response = make_http_request(uri)

    if response.code == 200
      result = Puppet::Util::Json.load(response.body)
      uri = decode_uri(result['pagination']['next'])
      matches.concat result['results']
    else
      raise ResponseError.new(:uri => response.url, :response => response)
    end
  end

  matches.each do |mod|
    mod['author'] = mod['owner']['username']
    mod['tag_list'] = mod['current_release']['tags']
    mod['full_name'] = "#{mod['author']}/#{mod['name']}"
    mod['version'] = mod['current_release']['version']
    mod['project_url'] = mod['homepage_url']
    mod['desc'] = mod['current_release']['metadata']['summary'] || ''
  end
end