Class: Puppet::Forge::Repository Private

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/puppet/forge/repository.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Repository

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

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, for_agent) ⇒ Repository

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

API:

  • private



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

#cacheObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



16
17
18
# File 'lib/puppet/forge/repository.rb', line 16

def cache
  @cache
end

#uriObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



16
17
18
# File 'lib/puppet/forge/repository.rb', line 16

def uri
  @uri
end

Instance Method Details

#cache_keyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

API:

  • private



80
81
82
83
84
85
# File 'lib/puppet/forge/repository.rb', line 80

def cache_key
  return @cache_key ||= [
    @host.to_s.gsub(/[^[:alnum:]]+/, '_').sub(/_$/, ''),
    Digest::SHA1.hexdigest(@host.to_s)
  ].join('-').freeze
end

#forge_authorizationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



58
59
60
61
62
63
64
# File 'lib/puppet/forge/repository.rb', line 58

def forge_authorization
  if Puppet[:forge_authorization]
    Puppet[:forge_authorization]
  elsif Puppet.features.pe_license?
    PELicense.load_license_key.authorization_token
  end
end

#make_http_request(path, io = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a Net::HTTPResponse read for this path.

Raises:

API:

  • private



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
# 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 }

    if forge_authorization
      uri.user = nil
      uri.password = nil
      headers["Authorization"] = forge_authorization
    end

    http = Puppet.runtime[:http]
    response = http.get(uri, headers: headers, options: {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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

API:

  • private



68
69
70
71
# File 'lib/puppet/forge/repository.rb', line 68

def retrieve(release)
  path = @host.chomp('/') + release
  return cache.retrieve(path)
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the URI string for this repository.

API:

  • private



74
75
76
# File 'lib/puppet/forge/repository.rb', line 74

def to_s
  "#<#{self.class} #{@host}>"
end