puppet 6.13.0 → 6.14.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +7 -13
  3. data/Gemfile.lock +6 -6
  4. data/README.md +15 -22
  5. data/lib/puppet.rb +1 -1
  6. data/lib/puppet/application/agent.rb +9 -11
  7. data/lib/puppet/application/describe.rb +7 -5
  8. data/lib/puppet/application/device.rb +2 -2
  9. data/lib/puppet/application/filebucket.rb +14 -1
  10. data/lib/puppet/application/ssl.rb +1 -1
  11. data/lib/puppet/configurer.rb +30 -41
  12. data/lib/puppet/configurer/plugin_handler.rb +10 -1
  13. data/lib/puppet/defaults.rb +7 -1
  14. data/lib/puppet/face/plugin.rb +1 -1
  15. data/lib/puppet/functions/eyaml_lookup_key.rb +13 -8
  16. data/lib/puppet/http.rb +1 -0
  17. data/lib/puppet/http/client.rb +69 -34
  18. data/lib/puppet/http/resolver/server_list.rb +2 -2
  19. data/lib/puppet/http/resolver/settings.rb +1 -1
  20. data/lib/puppet/http/resolver/srv.rb +1 -1
  21. data/lib/puppet/http/response.rb +6 -1
  22. data/lib/puppet/http/service.rb +30 -11
  23. data/lib/puppet/http/service/ca.rb +8 -8
  24. data/lib/puppet/http/service/compiler.rb +41 -10
  25. data/lib/puppet/http/service/file_server.rb +40 -20
  26. data/lib/puppet/http/service/report.rb +12 -15
  27. data/lib/puppet/http/session.rb +39 -1
  28. data/lib/puppet/indirector/catalog/rest.rb +33 -0
  29. data/lib/puppet/indirector/facts/rest.rb +41 -0
  30. data/lib/puppet/indirector/file_content/rest.rb +30 -0
  31. data/lib/puppet/indirector/file_metadata/rest.rb +50 -0
  32. data/lib/puppet/indirector/node/rest.rb +23 -0
  33. data/lib/puppet/indirector/report/rest.rb +19 -0
  34. data/lib/puppet/indirector/rest.rb +6 -0
  35. data/lib/puppet/indirector/status/rest.rb +17 -0
  36. data/lib/puppet/loaders.rb +6 -0
  37. data/lib/puppet/network/http/base_pool.rb +1 -1
  38. data/lib/puppet/network/http/pool.rb +6 -1
  39. data/lib/puppet/provider/group/groupadd.rb +9 -4
  40. data/lib/puppet/runtime.rb +8 -1
  41. data/lib/puppet/settings.rb +2 -0
  42. data/lib/puppet/settings/http_extra_headers_setting.rb +25 -0
  43. data/lib/puppet/ssl/state_machine.rb +4 -0
  44. data/lib/puppet/test/test_helper.rb +3 -1
  45. data/lib/puppet/type/file.rb +13 -0
  46. data/lib/puppet/type/file/source.rb +47 -58
  47. data/lib/puppet/version.rb +1 -1
  48. data/locales/puppet.pot +167 -160
  49. data/man/man5/puppet.conf.5 +11 -3
  50. data/man/man8/puppet-agent.8 +6 -6
  51. data/man/man8/puppet-apply.8 +1 -1
  52. data/man/man8/puppet-catalog.8 +1 -1
  53. data/man/man8/puppet-config.8 +1 -1
  54. data/man/man8/puppet-describe.8 +1 -1
  55. data/man/man8/puppet-device.8 +2 -2
  56. data/man/man8/puppet-doc.8 +1 -1
  57. data/man/man8/puppet-epp.8 +1 -1
  58. data/man/man8/puppet-facts.8 +1 -1
  59. data/man/man8/puppet-filebucket.8 +17 -2
  60. data/man/man8/puppet-generate.8 +1 -1
  61. data/man/man8/puppet-help.8 +1 -1
  62. data/man/man8/puppet-key.8 +1 -1
  63. data/man/man8/puppet-lookup.8 +1 -1
  64. data/man/man8/puppet-man.8 +1 -1
  65. data/man/man8/puppet-module.8 +1 -1
  66. data/man/man8/puppet-node.8 +1 -1
  67. data/man/man8/puppet-parser.8 +1 -1
  68. data/man/man8/puppet-plugin.8 +1 -1
  69. data/man/man8/puppet-report.8 +1 -1
  70. data/man/man8/puppet-resource.8 +1 -1
  71. data/man/man8/puppet-script.8 +1 -1
  72. data/man/man8/puppet-ssl.8 +2 -2
  73. data/man/man8/puppet-status.8 +1 -1
  74. data/man/man8/puppet.8 +2 -2
  75. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_fetch_if_not_on_the_local_disk.yml +1 -67
  76. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_not_update_if_content_on_disk_is_up-to-date.yml +1 -69
  77. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_md5/should_update_if_content_differs_on_disk.yml +1 -69
  78. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_mtime_is_older_on_disk.yml +1 -67
  79. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_no_header_specified.yml +1 -65
  80. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_fetch_if_not_on_the_local_disk.yml +1 -67
  81. data/spec/fixtures/vcr/cassettes/Puppet_Type_File/when_sourcing/from_http/using_mtime/should_not_update_if_mtime_is_newer_on_disk.yml +1 -67
  82. data/spec/integration/faces/plugin_spec.rb +3 -1
  83. data/spec/integration/http/client_spec.rb +11 -0
  84. data/spec/integration/network/http_pool_spec.rb +9 -1
  85. data/spec/unit/application/describe_spec.rb +88 -50
  86. data/spec/unit/configurer/plugin_handler_spec.rb +36 -19
  87. data/spec/unit/configurer_spec.rb +16 -14
  88. data/spec/unit/face/plugin_spec.rb +12 -10
  89. data/spec/unit/functions/lookup_spec.rb +13 -0
  90. data/spec/unit/http/client_spec.rb +172 -1
  91. data/spec/unit/http/resolver_spec.rb +14 -2
  92. data/spec/unit/http/response_spec.rb +69 -0
  93. data/spec/unit/http/service/ca_spec.rb +28 -9
  94. data/spec/unit/http/service/compiler_spec.rb +151 -24
  95. data/spec/unit/http/service/file_server_spec.rb +65 -8
  96. data/spec/unit/http/service/report_spec.rb +17 -8
  97. data/spec/unit/http/service_spec.rb +92 -3
  98. data/spec/unit/http/session_spec.rb +104 -1
  99. data/spec/unit/indirector/catalog/rest_spec.rb +59 -2
  100. data/spec/unit/indirector/facts/rest_spec.rb +79 -24
  101. data/spec/unit/indirector/file_content/rest_spec.rb +53 -2
  102. data/spec/unit/indirector/file_metadata/rest_spec.rb +109 -2
  103. data/spec/unit/indirector/node/rest_spec.rb +57 -2
  104. data/spec/unit/indirector/report/rest_spec.rb +58 -51
  105. data/spec/unit/indirector/resource/ral_spec.rb +7 -8
  106. data/spec/unit/indirector/status/rest_spec.rb +43 -2
  107. data/spec/unit/network/http/pool_spec.rb +57 -11
  108. data/spec/unit/provider/group/groupadd_spec.rb +22 -8
  109. data/spec/unit/settings/autosign_setting_spec.rb +1 -1
  110. data/spec/unit/settings/http_extra_headers_spec.rb +64 -0
  111. data/spec/unit/ssl/state_machine_spec.rb +10 -0
  112. data/spec/unit/transaction_spec.rb +0 -2
  113. data/spec/unit/type/file/ensure_spec.rb +1 -2
  114. data/spec/unit/type/file/source_spec.rb +86 -35
  115. data/spec/unit/util/at_fork_spec.rb +1 -0
  116. data/spec/unit/util/pidlock_spec.rb +36 -24
  117. metadata +7 -3
  118. data/COMMITTERS.md +0 -244
@@ -6,4 +6,54 @@ class Puppet::Indirector::FileMetadata::Rest < Puppet::Indirector::REST
6
6
  desc "Retrieve file metadata via a REST HTTP interface."
7
7
 
8
8
  use_srv_service(:fileserver)
9
+
10
+ def find(request)
11
+ return super unless use_http_client?
12
+
13
+ url = URI.parse(Puppet::Util.uri_encode(request.uri))
14
+ session = Puppet.lookup(:http_session)
15
+ api = session.route_to(:fileserver, url: url)
16
+
17
+ api.get_file_metadata(
18
+ path: URI.unescape(url.path),
19
+ environment: request.environment.to_s,
20
+ links: request.options[:links],
21
+ checksum_type: request.options[:checksum_type],
22
+ source_permissions: request.options[:source_permissions]
23
+ )
24
+ rescue Puppet::HTTP::ResponseError => e
25
+ if e.response.code == 404
26
+ return nil unless request.options[:fail_on_404]
27
+
28
+ _, body = parse_response(e.response.nethttp)
29
+ msg = _("Find %{uri} resulted in 404 with the message: %{body}") % { uri: elide(e.response.url.path, 100), body: body }
30
+ raise Puppet::Error, msg
31
+ else
32
+ raise convert_to_http_error(e.response.nethttp)
33
+ end
34
+ end
35
+
36
+ def search(request)
37
+ return super unless use_http_client?
38
+
39
+ url = URI.parse(Puppet::Util.uri_encode(request.uri))
40
+ session = Puppet.lookup(:http_session)
41
+ api = session.route_to(:fileserver, url: url)
42
+
43
+ api.get_file_metadatas(
44
+ path: URI.unescape(url.path),
45
+ environment: request.environment.to_s,
46
+ recurse: request.options[:recurse],
47
+ recurselimit: request.options[:recurselimit],
48
+ ignore: request.options[:ignore],
49
+ links: request.options[:links],
50
+ checksum_type: request.options[:checksum_type],
51
+ source_permissions: request.options[:source_permissions],
52
+ )
53
+ rescue Puppet::HTTP::ResponseError => e
54
+ # since it's search, return empty array instead of nil
55
+ return [] if e.response.code == 404
56
+
57
+ raise convert_to_http_error(e.response.nethttp)
58
+ end
9
59
  end
@@ -4,4 +4,27 @@ require 'puppet/indirector/rest'
4
4
  class Puppet::Node::Rest < Puppet::Indirector::REST
5
5
  desc "Get a node via REST. Puppet agent uses this to allow the puppet master
6
6
  to override its environment."
7
+
8
+ def find(request)
9
+ return super unless use_http_client?
10
+
11
+ session = Puppet.lookup(:http_session)
12
+ api = session.route_to(:puppet)
13
+ api.get_node(
14
+ request.key,
15
+ environment: request.environment.to_s,
16
+ configured_environment: request.options[:configured_environment],
17
+ transaction_uuid: request.options[:transaction_uuid]
18
+ )
19
+ rescue Puppet::HTTP::ResponseError => e
20
+ if e.response.code == 404
21
+ return nil unless request.options[:fail_on_404]
22
+
23
+ _, body = parse_response(e.response.nethttp)
24
+ msg = _("Find %{uri} resulted in 404 with the message: %{body}") % { uri: elide(e.response.url.path, 100), body: body }
25
+ raise Puppet::Error, msg
26
+ else
27
+ raise convert_to_http_error(e.response.nethttp)
28
+ end
29
+ end
7
30
  end
@@ -7,6 +7,25 @@ class Puppet::Transaction::Report::Rest < Puppet::Indirector::REST
7
7
  use_port_setting(:report_port)
8
8
  use_srv_service(:report)
9
9
 
10
+ def save(request)
11
+ return super unless use_http_client?
12
+
13
+ session = Puppet.lookup(:http_session)
14
+ api = session.route_to(:report)
15
+ response = api.put_report(
16
+ request.key,
17
+ request.instance,
18
+ environment: request.environment.to_s
19
+ )
20
+ content_type, body = parse_response(response)
21
+ deserialize_save(content_type, body)
22
+ rescue Puppet::HTTP::ResponseError => e
23
+ return nil if e.response.code == 404
24
+
25
+ raise convert_to_http_error(e.response.nethttp)
26
+ end
27
+
28
+ # This is called by the superclass when not using our httpclient.
10
29
  def handle_response(request, response)
11
30
  if !response.is_a?(Net::HTTPSuccess)
12
31
  server_version = response[Puppet::Network::HTTP::HEADER_PUPPET_VERSION]
@@ -52,6 +52,12 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
52
52
  Puppet::Util::Connection.determine_port(port_setting, server_setting)
53
53
  end
54
54
 
55
+ # Should we use puppet's http client to make requests. Will return
56
+ # false when running in puppetserver
57
+ def use_http_client?
58
+ Puppet::Network::HttpPool.http_client_class == Puppet::Network::HTTP::Connection
59
+ end
60
+
55
61
  # Provide appropriate headers.
56
62
  def headers
57
63
  # yaml is not allowed on the network
@@ -6,4 +6,21 @@ class Puppet::Indirector::Status::Rest < Puppet::Indirector::REST
6
6
  desc "Get puppet master's status via REST. Useful because it tests the health
7
7
  of both the web server and the indirector."
8
8
 
9
+ def find(request)
10
+ return super unless use_http_client?
11
+
12
+ session = Puppet.lookup(:http_session)
13
+ api = session.route_to(:puppet)
14
+ api.get_status(request.key)
15
+ rescue Puppet::HTTP::ResponseError => e
16
+ if e.response.code == 404
17
+ return nil unless request.options[:fail_on_404]
18
+
19
+ _, body = parse_response(e.response.nethttp)
20
+ msg = _("Find %{uri} resulted in 404 with the message: %{body}") % { uri: elide(e.response.url.path, 100), body: body }
21
+ raise Puppet::Error, msg
22
+ else
23
+ raise convert_to_http_error(e.response.nethttp)
24
+ end
25
+ end
9
26
  end
@@ -1,3 +1,5 @@
1
+ require 'puppet/concurrent/synchronized'
2
+
1
3
  module Puppet
2
4
  module Pops
3
5
  require 'puppet/pops/loaders'
@@ -22,6 +24,10 @@ module Puppet
22
24
  require 'puppet/pops/loader/predefined_loader'
23
25
  require 'puppet/pops/loader/generic_plan_instantiator'
24
26
  require 'puppet/pops/loader/puppet_plan_instantiator'
27
+
28
+ # The implementation of synchronized applies it to all subclasses so we
29
+ # want to add it to be base class after any subclasses are created
30
+ Loader.include Puppet::Concurrent::Synchronized
25
31
  end
26
32
  end
27
33
 
@@ -4,7 +4,7 @@
4
4
  class Puppet::Network::HTTP::BasePool
5
5
  def start(site, verifier, http)
6
6
  Puppet.debug("Starting connection for #{site}")
7
- if verifier
7
+ if site.use_ssl?
8
8
  verifier.setup_connection(http)
9
9
  begin
10
10
  http.start
@@ -75,9 +75,14 @@ class Puppet::Network::HTTP::Pool < Puppet::Network::HTTP::BasePool
75
75
  # @api private
76
76
  def borrow(site, verifier)
77
77
  @pool[site] = active_sessions(site)
78
- index = @pool[site].index { |session| verifier.reusable?(session.verifier) }
78
+ index = @pool[site].index do |session|
79
+ (verifier.nil? && session.verifier.nil?) ||
80
+ (!verifier.nil? && verifier.reusable?(session.verifier))
81
+ end
79
82
  session = index ? @pool[site].delete_at(index) : nil
80
83
  if session
84
+ @pool.delete(site) if @pool[site].empty?
85
+
81
86
  Puppet.debug("Using cached connection for #{site}")
82
87
  session.connection
83
88
  else
@@ -74,6 +74,14 @@ Puppet::Type.type(:group).provide :groupadd, :parent => Puppet::Provider::NameSe
74
74
  cmd
75
75
  end
76
76
 
77
+ def validate_members(members)
78
+ members.each do |member|
79
+ member.split(',').each do |user|
80
+ Etc.getpwnam(user.strip)
81
+ end
82
+ end
83
+ end
84
+
77
85
  def modifycmd(param, value)
78
86
  if @resource.forcelocal? || @resource[:members]
79
87
  cmd = [command(:localmodify)]
@@ -83,6 +91,7 @@ Puppet::Type.type(:group).provide :groupadd, :parent => Puppet::Provider::NameSe
83
91
  end
84
92
 
85
93
  if param == :members
94
+ validate_members(value)
86
95
  value = members_to_s(value)
87
96
  purge_members if @resource[:auth_membership] && !members.empty?
88
97
  end
@@ -118,10 +127,6 @@ Puppet::Type.type(:group).provide :groupadd, :parent => Puppet::Provider::NameSe
118
127
  localmodify('-m', members_to_s(members), @resource.name)
119
128
  end
120
129
 
121
- def member_valid?(user)
122
- !!Etc.getpwnam(user)
123
- end
124
-
125
130
  private
126
131
 
127
132
  def findgroup(key, value)
@@ -5,7 +5,9 @@ class Puppet::Runtime
5
5
  include Singleton
6
6
 
7
7
  def initialize
8
- @runtime_services = {}
8
+ @runtime_services = {
9
+ 'http' => proc { Puppet::HTTP::Client.new }
10
+ }
9
11
  end
10
12
  private :initialize
11
13
 
@@ -23,4 +25,9 @@ class Puppet::Runtime
23
25
  def []=(name, impl)
24
26
  @runtime_services[name] = impl
25
27
  end
28
+
29
+ # for testing
30
+ def clear
31
+ initialize
32
+ end
26
33
  end
@@ -30,6 +30,7 @@ class Puppet::Settings
30
30
  require 'puppet/settings/value_translator'
31
31
  require 'puppet/settings/environment_conf'
32
32
  require 'puppet/settings/server_list_setting'
33
+ require 'puppet/settings/http_extra_headers_setting'
33
34
  require 'puppet/settings/certificate_revocation_setting'
34
35
 
35
36
  # local reference for convenience
@@ -727,6 +728,7 @@ class Puppet::Settings
727
728
  :priority => PrioritySetting,
728
729
  :autosign => AutosignSetting,
729
730
  :server_list => ServerListSetting,
731
+ :http_extra_headers => HttpExtraHeadersSetting,
730
732
  :certificate_revocation => CertificateRevocationSetting
731
733
  }
732
734
 
@@ -0,0 +1,25 @@
1
+ class Puppet::Settings::HttpExtraHeadersSetting < Puppet::Settings::BaseSetting
2
+
3
+ def type
4
+ :http_extra_headers
5
+ end
6
+
7
+ def munge(headers)
8
+ return headers if headers.is_a?(Hash)
9
+
10
+ headers = headers.split(/\s*,\s*/) if headers.is_a?(String)
11
+
12
+ raise ArgumentError, _("Expected an Array, String, or Hash, got a %{klass}") % { klass: headers.class } unless headers.is_a?(Array)
13
+
14
+ headers.map! { |header|
15
+ case header
16
+ when String
17
+ header.split(':')
18
+ when Array
19
+ header
20
+ else
21
+ raise ArgumentError, _("Expected an Array or String, got a %{klass}") % { klass: header.class }
22
+ end
23
+ }
24
+ end
25
+ end
@@ -278,6 +278,10 @@ class Puppet::SSL::StateMachine
278
278
  else
279
279
  Puppet.info(_("Will try again in %{time} seconds.") % {time: time})
280
280
 
281
+ # close persistent connections and session state before sleeping
282
+ Puppet.runtime['http'].close
283
+ @machine.session = nil
284
+
281
285
  Kernel.sleep(time)
282
286
 
283
287
  # our ssl directory may have been cleaned while we were
@@ -136,10 +136,12 @@ module Puppet::Test
136
136
  {
137
137
  trusted_information:
138
138
  Puppet::Context::TrustedInformation.new('local', 'testing', {}, { "trusted_testhelper" => true }),
139
- ssl_context: Puppet::SSL::SSLContext.new(cacerts: []).freeze
139
+ ssl_context: Puppet::SSL::SSLContext.new(cacerts: []).freeze,
140
+ http_session: proc { Puppet.runtime["http"].create_session }
140
141
  },
141
142
  "Context for specs")
142
143
 
144
+ Puppet.runtime.clear
143
145
  Puppet::Parser::Functions.reset
144
146
  Puppet::Application.clear!
145
147
  Puppet::Util::Profiler.clear
@@ -110,6 +110,19 @@ Puppet::Type.newtype(:file) do
110
110
  balancer to direct all filebucket traffic to a single master, or use
111
111
  something like an out-of-band rsync task to synchronize the content on all
112
112
  masters.
113
+
114
+ > **Note**: Enabling and using the backup option, and by extension the
115
+ filebucket resource, requires appropriate planning and management to ensure
116
+ that sufficient disk space is available for the file backups. Generally, you
117
+ can implement this using one of the following two options:
118
+ - Use a `find` command and `crontab` entry to retain only the last X days
119
+ of file backups. For example,
120
+
121
+ ```shell script
122
+ find /opt/puppetlabs/server/data/puppetserver/bucket -type f -mtime +45 -atime +45 -print0 | xargs -0 rm
123
+ ```
124
+
125
+ - Restrict the directory to a maximum size after which the oldest items are removed.
113
126
  EOT
114
127
 
115
128
  defaultto "puppet"
@@ -2,10 +2,7 @@ require 'puppet/file_serving/content'
2
2
  require 'puppet/file_serving/metadata'
3
3
  require 'puppet/file_serving/terminus_helper'
4
4
 
5
- require 'puppet/util/http_proxy'
6
- require 'puppet/network/http'
7
- require 'puppet/network/http/api/indirected_routes'
8
- require 'puppet/network/http/compression'
5
+ require 'puppet/http'
9
6
 
10
7
  module Puppet
11
8
  # Copy files from a local or remote source. This state *only* does any work
@@ -14,11 +11,6 @@ module Puppet
14
11
  # this state, during retrieval, modifies the appropriate other states
15
12
  # so that things get taken care of appropriately.
16
13
  Puppet::Type.type(:file).newparam(:source) do
17
- include Puppet::Network::HTTP::Compression.module
18
-
19
- BINARY_MIME_TYPES = [
20
- Puppet::Network::FormatHandler.format_for('binary').mime
21
- ].join(', ').freeze
22
14
 
23
15
  attr_accessor :source, :local
24
16
  desc <<-'EOT'
@@ -129,18 +121,6 @@ module Puppet
129
121
  metadata && metadata.checksum
130
122
  end
131
123
 
132
- # Look up (if necessary) and return local content.
133
- def content
134
- return @content if @content
135
- raise Puppet::DevError, _("No source for content was stored with the metadata") unless metadata.source
136
-
137
- tmp = Puppet::FileServing::Content.indirection.find(metadata.source, :environment => resource.catalog.environment_instance, :links => resource[:links])
138
- unless tmp
139
- self.fail "Could not find any content at %s" % metadata.source
140
- end
141
- @content = tmp.content
142
- end
143
-
144
124
  # Copy the values from the source to the resource. Yay.
145
125
  def copy_source_values
146
126
  devfail "Somehow got asked to copy source values without any metadata" unless metadata
@@ -273,63 +253,72 @@ module Puppet
273
253
  end
274
254
  end
275
255
 
276
- def each_chunk_from
277
- if Puppet[:default_file_terminus] == :file_server
278
- yield content
256
+ def each_chunk_from(&block)
257
+ if Puppet[:default_file_terminus] == :file_server && scheme == 'puppet' && (uri.host.nil? || uri.host.empty?)
258
+ chunk_file_from_disk(metadata.path, &block)
279
259
  elsif local?
280
- chunk_file_from_disk { |chunk| yield chunk }
260
+ chunk_file_from_disk(full_path, &block)
281
261
  else
282
- chunk_file_from_source { |chunk| yield chunk }
262
+ chunk_file_from_source(&block)
283
263
  end
284
264
  end
285
265
 
286
- def chunk_file_from_disk
287
- File.open(full_path, "rb") do |src|
266
+ def chunk_file_from_disk(local_path)
267
+ File.open(local_path, "rb") do |src|
288
268
  while chunk = src.read(8192) #rubocop:disable Lint/AssignmentInCondition
289
269
  yield chunk
290
270
  end
291
271
  end
292
272
  end
293
273
 
294
- def get_from_puppet_source(source_uri, content_uri, &block)
295
- options = { :environment => resource.catalog.environment_instance }
296
- if content_uri
297
- options[:code_id] = resource.catalog.code_id
298
- request = Puppet::Indirector::Request.new(:static_file_content, :find, content_uri, nil, options)
299
- else
300
- request = Puppet::Indirector::Request.new(:file_content, :find, source_uri, nil, options)
301
- end
274
+ def get_from_content_uri_source(url, &block)
275
+ session = Puppet.lookup(:http_session)
276
+ api = session.route_to(:fileserver, url: url)
302
277
 
303
- request.do_request(:fileserver) do |req|
304
- ssl_context = Puppet.lookup(:ssl_context)
305
- connection = Puppet::Network::HttpPool.connection(req.server, req.port, ssl_context: ssl_context)
306
- connection.request_get(Puppet::Network::HTTP::API::IndirectedRoutes.request_to_uri(req), add_accept_encoding({"Accept" => BINARY_MIME_TYPES}), &block)
307
- end
278
+ api.get_static_file_content(
279
+ path: URI.unescape(url.path),
280
+ environment: resource.catalog.environment_instance.to_s,
281
+ code_id: resource.catalog.code_id,
282
+ &block
283
+ )
308
284
  end
309
285
 
310
- def get_from_http_source(source_uri, &block)
311
- Puppet::Util::HttpProxy.request_with_redirects(URI(source_uri), :get, &block)
286
+ def get_from_source_uri_source(url, &block)
287
+ session = Puppet.lookup(:http_session)
288
+ api = session.route_to(:fileserver, url: url)
289
+
290
+ api.get_file_content(
291
+ path: URI.unescape(url.path),
292
+ environment: resource.catalog.environment_instance.to_s,
293
+ &block
294
+ )
312
295
  end
313
296
 
314
- def get_from_source(&block)
315
- source_uri = metadata.source
316
- if source_uri =~ /^https?:/
317
- get_from_http_source(source_uri, &block)
318
- else
319
- get_from_puppet_source(source_uri, metadata.content_uri, &block)
297
+ def get_from_http_source(url, &block)
298
+ client = Puppet.runtime['http']
299
+ client.get(url) do |response|
300
+ raise Puppet::HTTP::ResponseError.new(response) unless response.success?
301
+
302
+ response.read_body(&block)
320
303
  end
321
304
  end
322
305
 
323
- def chunk_file_from_source
324
- get_from_source do |response|
325
- case response.code
326
- when /^2/; uncompress(response) { |uncompressor| response.read_body { |chunk| yield uncompressor.uncompress(chunk) } }
327
- else
328
- # Raise the http error if we didn't get a 'success' of some kind.
329
- message = "Error #{response.code} on SERVER: #{(response.body||'').empty? ? response.message : uncompress_body(response)}"
330
- raise Net::HTTPError.new(message, response)
331
- end
306
+ def chunk_file_from_source(&block)
307
+ if uri.scheme =~ /^https?/
308
+ get_from_http_source(uri, &block)
309
+ elsif metadata.content_uri
310
+ content_url = URI.parse(Puppet::Util.uri_encode(metadata.content_uri))
311
+ get_from_content_uri_source(content_url, &block)
312
+ else
313
+ get_from_source_uri_source(uri, &block)
332
314
  end
315
+ rescue Puppet::HTTP::ResponseError => e
316
+ handle_response_error(e.response)
317
+ end
318
+
319
+ def handle_response_error(response)
320
+ message = "Error #{response.code} on SERVER: #{response.body.empty? ? response.reason : response.body}"
321
+ raise Net::HTTPError.new(message, response.nethttp)
333
322
  end
334
323
  end
335
324