Class: Puppet::Forge::Repository
- Includes:
- Errors
- Defined in:
- lib/puppet/forge/repository.rb
Overview
Repository
This class is a file for accessing remote repositories with modules.
Constant Summary collapse
- NET_HTTP_EXCEPTIONS =
List of Net::HTTP exceptions to catch
[ EOFError, Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EINVAL, Errno::ETIMEDOUT, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, SocketError, ]
Instance Attribute Summary collapse
- #cache ⇒ Object readonly
- #uri ⇒ Object readonly
Instance Method Summary collapse
-
#cache_key ⇒ Object
Return the cache key for this repository, this a hashed string based on the URI.
-
#get_http_object ⇒ Net::HTTP::Proxy
Return a Net::HTTP::Proxy object constructed from the settings provided accessing the repository.
-
#initialize(url, consumer_version) ⇒ Repository
constructor
Instantiate a new repository instance rooted at the
url. -
#make_http_request(request_path) ⇒ Object
Return a Net::HTTPResponse read for this
request_path. -
#read_response(request) ⇒ Net::HTTPResponse
Return a Net::HTTPResponse read from this HTTPRequest
request. -
#retrieve(release) ⇒ Object
Return the local file name containing the data downloaded from the repository at
release(e.g. “myuser-mymodule”). -
#to_s ⇒ Object
Return the URI string for this repository.
Constructor Details
#initialize(url, consumer_version) ⇒ Repository
Instantiate a new repository instance rooted at the url. The agent will report consumer_version in the User-Agent to the repository.
41 42 43 44 45 |
# File 'lib/puppet/forge/repository.rb', line 41 def initialize(url, consumer_version) @uri = url.is_a?(::URI) ? url : ::URI.parse(url) @cache = Cache.new(self) @consumer_version = consumer_version end |
Instance Attribute Details
#cache ⇒ Object (readonly)
18 19 20 |
# File 'lib/puppet/forge/repository.rb', line 18 def cache @cache end |
Instance Method Details
#cache_key ⇒ Object
Return the cache key for this repository, this a hashed string based on the URI.
119 120 121 122 123 124 |
# File 'lib/puppet/forge/repository.rb', line 119 def cache_key return @cache_key ||= [ @uri.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''), Digest::SHA1.hexdigest(@uri.to_s) ].join('-') end |
#get_http_object ⇒ Net::HTTP::Proxy
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.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/puppet/forge/repository.rb', line 88 def get_http_object proxy_class = Net::HTTP::Proxy(Puppet::Util::HttpProxy.http_proxy_host, Puppet::Util::HttpProxy.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 |
#make_http_request(request_path) ⇒ Object
Return a Net::HTTPResponse read for this request_path.
48 49 50 51 52 53 54 |
# File 'lib/puppet/forge/repository.rb', line 48 def make_http_request(request_path) request = Net::HTTP::Get.new(URI.escape(@uri.path + 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 |
#read_response(request) ⇒ Net::HTTPResponse
Return a Net::HTTPResponse read from this HTTPRequest request.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/puppet/forge/repository.rb', line 64 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. =~ /certificate verify failed/ raise SSLVerifyError.new(:uri => @uri.to_s, :original => e) else raise e end end |
#retrieve(release) ⇒ Object
Return the local file name containing the data downloaded from the repository at release (e.g. “myuser-mymodule”).
106 107 108 109 110 |
# File 'lib/puppet/forge/repository.rb', line 106 def retrieve(release) uri = @uri.dup uri.path = uri.path.chomp('/') + release return cache.retrieve(uri) end |
#to_s ⇒ Object
Return the URI string for this repository.
113 114 115 |
# File 'lib/puppet/forge/repository.rb', line 113 def to_s return @uri.to_s end |