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.
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#cache_key ⇒ Object
Return the cache key for this repository, this a hashed string based on the URI.
- #forge_authorization ⇒ Object
-
#initialize(host, for_agent) ⇒ Repository
constructor
Instantiate a new repository instance rooted at the
url
. -
#make_http_request(path, io = nil) ⇒ Object
Return a Net::HTTPResponse read for this
path
. -
#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(host, for_agent) ⇒ Repository
Instantiate a new repository instance rooted at the url
. The library will report for_agent
in the User-Agent to the repository.
20 21 22 23 24 25 26 27 28 |
# File 'lib/puppet/forge/repository.rb', line 20 def initialize(host, for_agent) @host = host @agent = for_agent @cache = Cache.new(self) @uri = URI.parse(host) ssl_provider = Puppet::SSL::SSLProvider.new @ssl_context = ssl_provider.create_system_context(cacerts: []) end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
16 17 18 |
# File 'lib/puppet/forge/repository.rb', line 16 def cache @cache end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
16 17 18 |
# File 'lib/puppet/forge/repository.rb', line 16 def uri @uri end |
Instance Method Details
#cache_key ⇒ Object
Return the cache key for this repository, this a hashed string based on the URI.
84 85 86 87 88 89 |
# File 'lib/puppet/forge/repository.rb', line 84 def cache_key return @cache_key ||= [ @host.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''), Digest::SHA1.hexdigest(@host.to_s) ].join('-').freeze end |
#forge_authorization ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/puppet/forge/repository.rb', line 62 def if Puppet[:forge_authorization] Puppet[:forge_authorization] elsif Puppet.features.pe_license? PELicense.load_license_key. end end |
#make_http_request(path, io = nil) ⇒ Object
Return a Net::HTTPResponse read for this path
.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/forge/repository.rb', line 31 def make_http_request(path, io = nil) raise ArgumentError, "Path must start with forward slash" unless path.start_with?('/') begin str = @uri.to_s str.chomp!('/') str += Puppet::Util.uri_encode(path) uri = URI(str) headers = { "User-Agent" => user_agent } basic_auth = nil if headers["Authorization"] = elsif @uri.user && @uri.password basic_auth = { user: @uri.user, password: @uri.password } end http = Puppet.runtime[:http] response = http.get(uri, headers: headers, options: {basic_auth: basic_auth, ssl_context: @ssl_context}) io.write(response.body) if io.respond_to?(:write) response rescue Puppet::SSL::CertVerifyError => e raise SSLVerifyError.new(:uri => @uri.to_s, :original => e.cause) rescue => e raise CommunicationError.new(:uri => @uri.to_s, :original => e) end end |
#retrieve(release) ⇒ Object
Return the local file name containing the data downloaded from the repository at release
(e.g. “myuser-mymodule”).
72 73 74 75 |
# File 'lib/puppet/forge/repository.rb', line 72 def retrieve(release) path = @host.chomp('/') + release return cache.retrieve(path) end |
#to_s ⇒ Object
Return the URI string for this repository.
78 79 80 |
# File 'lib/puppet/forge/repository.rb', line 78 def to_s "#<#{self.class} #{@host}>" end |