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.

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.



21
22
23
24
25
26
27
28
29
# File 'lib/puppet/forge/repository.rb', line 21

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.



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

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.



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

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.



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

def cache_key
  @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.



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

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:

  • (ArgumentError)


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
# File 'lib/puppet/forge/repository.rb', line 32

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”).



70
71
72
73
# File 'lib/puppet/forge/repository.rb', line 70

def retrieve(release)
  path = @host.chomp('/') + release
  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.



76
77
78
# File 'lib/puppet/forge/repository.rb', line 76

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