This class is a file for accessing remote repositories with modules.
List of Net::HTTP exceptions to catch
Instantiate a new repository instance rooted at the url. The
agent will report consumer_version in the User-Agent to the
repository.
# File lib/puppet/forge/repository.rb, line 34 def initialize(url, consumer_version) @uri = url.is_a?(::URI) ? url : ::URI.parse(url) @cache = Cache.new(self) @consumer_version = consumer_version end
Return the cache key for this repository, this a hashed string based on the URI.
# File lib/puppet/forge/repository.rb, line 146 def cache_key return @cache_key ||= [ @uri.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''), Digest::SHA1.hexdigest(@uri.to_s) ].join('-') end
Return a Net::HTTP::Proxy object constructed from the settings provided accessing the repository.
This method optionally configures SSL correctly if the URI scheme is ‘https’, including setting up the root certificate store so remote server SSL certificates can be validated.
@return [Net::HTTP::Proxy] object constructed from repo settings
# File lib/puppet/forge/repository.rb, line 117 def get_http_object proxy_class = Net::HTTP::Proxy(http_proxy_host, http_proxy_port) proxy = proxy_class.new(@uri.host, @uri.port) if @uri.scheme == 'https' cert_store = OpenSSL::X509::Store.new cert_store.set_default_paths proxy.use_ssl = true proxy.verify_mode = OpenSSL::SSL::VERIFY_PEER proxy.cert_store = cert_store end proxy end
Read HTTP proxy configurationm from Puppet’s config file, or the http_proxy environment variable.
# File lib/puppet/forge/repository.rb, line 42 def http_proxy_env proxy_env = ENV["http_proxy"] || ENV["HTTP_PROXY"] || nil begin return URI.parse(proxy_env) if proxy_env rescue URI::InvalidURIError return nil end return nil end
# File lib/puppet/forge/repository.rb, line 52 def http_proxy_host env = http_proxy_env if env and env.host then return env.host end if Puppet.settings[:http_proxy_host] == 'none' return nil end return Puppet.settings[:http_proxy_host] end
# File lib/puppet/forge/repository.rb, line 66 def http_proxy_port env = http_proxy_env if env and env.port then return env.port end return Puppet.settings[:http_proxy_port] end
Return a Net::HTTPResponse read for this request_path.
# File lib/puppet/forge/repository.rb, line 77 def make_http_request(request_path) request = Net::HTTP::Get.new(request_path, { "User-Agent" => user_agent }) if ! @uri.user.nil? && ! @uri.password.nil? request.basic_auth(@uri.user, @uri.password) end return read_response(request) end
Return a Net::HTTPResponse read from this HTTPRequest request.
@param request [Net::HTTPRequest] request to make @return [Net::HTTPResponse] response from request @raise [Puppet::Forge::Errors::CommunicationError] if there is a network
related error
@raise [Puppet::Forge::Errors::SSLVerifyError] if there is a problem
verifying the remote SSL certificate
# File lib/puppet/forge/repository.rb, line 93 def read_response(request) http_object = get_http_object http_object.start do |http| http.request(request) end rescue *NET_HTTP_EXCEPTIONS => e raise CommunicationError.new(:uri => @uri.to_s, :original => e) rescue OpenSSL::SSL::SSLError => e if e.message =~ /certificate verify failed/ raise SSLVerifyError.new(:uri => @uri.to_s, :original => e) else raise e end end
Return the local file name containing the data downloaded from the
repository at release (e.g. “myuser-mymodule”).
# File lib/puppet/forge/repository.rb, line 135 def retrieve(release) return cache.retrieve(@uri + release) end
Return the URI string for this repository.
# File lib/puppet/forge/repository.rb, line 140 def to_s return @uri.to_s end