class Puppet::Forge::Repository

Repository

This class is a file for accessing remote repositories with modules.

Attributes

cache[R]
uri[R]

Public Class Methods

new(host, for_agent) click to toggle source

Instantiate a new repository instance rooted at the url. The library will report for_agent in the User-Agent to the repository.

   # File lib/puppet/forge/repository.rb
19 def initialize(host, for_agent)
20   @host  = host
21   @agent = for_agent
22   @cache = Cache.new(self)
23   @uri   = URI.parse(host)
24 
25   ssl_provider = Puppet::SSL::SSLProvider.new
26   @ssl_context = ssl_provider.create_system_context(cacerts: [])
27 end

Public Instance Methods

cache_key() click to toggle source

Return the cache key for this repository, this a hashed string based on the URI.

   # File lib/puppet/forge/repository.rb
79 def cache_key
80   return @cache_key ||= [
81     @host.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''),
82     Digest::SHA1.hexdigest(@host.to_s)
83   ].join('-').freeze
84 end
forge_authorization() click to toggle source
   # File lib/puppet/forge/repository.rb
57 def forge_authorization
58   if Puppet[:forge_authorization]
59     Puppet[:forge_authorization]
60   elsif Puppet.features.pe_license?
61     PELicense.load_license_key.authorization_token
62   end
63 end
make_http_request(path, io = nil) click to toggle source

Return a Net::HTTPResponse read for this path.

   # File lib/puppet/forge/repository.rb
30 def make_http_request(path, io = nil)
31   raise ArgumentError, "Path must start with forward slash" unless path.start_with?('/')
32   begin
33     str = @uri.to_s
34     str.chomp!('/')
35     str += Puppet::Util.uri_encode(path)
36     uri = URI(str)
37 
38     headers = { "User-Agent" => user_agent }
39 
40     if forge_authorization
41       uri.user = nil
42       uri.password = nil
43       headers["Authorization"] = forge_authorization
44     end
45 
46     http = Puppet.runtime[:http]
47     response = http.get(uri, headers: headers, options: {ssl_context: @ssl_context})
48     io.write(response.body) if io.respond_to?(:write)
49     response
50   rescue Puppet::SSL::CertVerifyError => e
51     raise SSLVerifyError.new(:uri => @uri.to_s, :original => e.cause)
52   rescue => e
53     raise CommunicationError.new(:uri => @uri.to_s, :original => e)
54   end
55 end
retrieve(release) click to toggle source

Return the local file name containing the data downloaded from the repository at release (e.g. “myuser-mymodule”).

   # File lib/puppet/forge/repository.rb
67 def retrieve(release)
68   path = @host.chomp('/') + release
69   return cache.retrieve(path)
70 end
to_s() click to toggle source

Return the URI string for this repository.

   # File lib/puppet/forge/repository.rb
73 def to_s
74   "#<#{self.class} #{@host}>"
75 end

Private Instance Methods

user_agent() click to toggle source
   # File lib/puppet/forge/repository.rb
88 def user_agent
89   @user_agent ||= [
90     @agent,
91     Puppet[:http_user_agent]
92   ].join(' ').freeze
93 end