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 20 def initialize(host, for_agent) 21 @host = host 22 @agent = for_agent 23 @cache = Cache.new(self) 24 @uri = URI.parse(host) 25 26 ssl_provider = Puppet::SSL::SSLProvider.new 27 @ssl_context = ssl_provider.create_system_context(cacerts: []) 28 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 80 def cache_key 81 return @cache_key ||= [ 82 @host.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''), 83 Digest::SHA1.hexdigest(@host.to_s) 84 ].join('-').freeze 85 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 31 def make_http_request(path, io = nil) 32 raise ArgumentError, "Path must start with forward slash" unless path.start_with?('/') 33 begin 34 str = @uri.to_s 35 str.chomp!('/') 36 str += Puppet::Util.uri_encode(path) 37 uri = URI(str) 38 39 headers = { "User-Agent" => user_agent } 40 41 if forge_authorization 42 uri.user = nil 43 uri.password = nil 44 headers["Authorization"] = forge_authorization 45 end 46 47 http = Puppet.runtime[:http] 48 response = http.get(uri, headers: headers, options: {ssl_context: @ssl_context}) 49 io.write(response.body) if io.respond_to?(:write) 50 response 51 rescue Puppet::SSL::CertVerifyError => e 52 raise SSLVerifyError.new(:uri => @uri.to_s, :original => e.cause) 53 rescue => e 54 raise CommunicationError.new(:uri => @uri.to_s, :original => e) 55 end 56 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 68 def retrieve(release) 69 path = @host.chomp('/') + release 70 return cache.retrieve(path) 71 end
to_s()
click to toggle source
Return the URI string for this repository.
# File lib/puppet/forge/repository.rb 74 def to_s 75 "#<#{self.class} #{@host}>" 76 end
Private Instance Methods
user_agent()
click to toggle source
# File lib/puppet/forge/repository.rb 89 def user_agent 90 @user_agent ||= [ 91 @agent, 92 Puppet[:http_user_agent] 93 ].join(' ').freeze 94 end