bolt 0.21.1 → 0.21.2

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

Potentially problematic release.


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

Files changed (105) hide show
  1. checksums.yaml +5 -5
  2. data/lib/bolt/applicator.rb +56 -0
  3. data/lib/bolt/error.rb +6 -0
  4. data/lib/bolt/pal.rb +8 -1
  5. data/lib/bolt/transport/winrm.rb +4 -1
  6. data/lib/bolt/version.rb +1 -1
  7. data/libexec/apply_catalog.rb +61 -0
  8. data/{exe → libexec}/bolt_catalog +0 -0
  9. data/vendored/puppet/lib/puppet/application.rb +8 -1
  10. data/vendored/puppet/lib/puppet/application/device.rb +24 -28
  11. data/vendored/puppet/lib/puppet/application/doc.rb +4 -2
  12. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -2
  13. data/vendored/puppet/lib/puppet/datatypes.rb +1 -1
  14. data/vendored/puppet/lib/puppet/defaults.rb +2 -6
  15. data/vendored/puppet/lib/puppet/environments.rb +4 -10
  16. data/vendored/puppet/lib/puppet/error.rb +1 -1
  17. data/vendored/puppet/lib/puppet/etc.rb +4 -5
  18. data/vendored/puppet/lib/puppet/face/config.rb +1 -1
  19. data/vendored/puppet/lib/puppet/face/module/build.rb +5 -55
  20. data/vendored/puppet/lib/puppet/face/module/generate.rb +5 -247
  21. data/vendored/puppet/lib/puppet/gettext/config.rb +28 -5
  22. data/vendored/puppet/lib/puppet/indirector/catalog/compiler.rb +5 -7
  23. data/vendored/puppet/lib/puppet/indirector/rest.rb +7 -56
  24. data/vendored/puppet/lib/puppet/indirector/terminus.rb +1 -1
  25. data/vendored/puppet/lib/puppet/interface.rb +1 -1
  26. data/vendored/puppet/lib/puppet/interface/face_collection.rb +3 -1
  27. data/vendored/puppet/lib/puppet/metatype/manager.rb +2 -2
  28. data/vendored/puppet/lib/puppet/module_tool/applications.rb +0 -1
  29. data/vendored/puppet/lib/puppet/module_tool/applications/application.rb +1 -1
  30. data/vendored/puppet/lib/puppet/network/http/connection.rb +2 -23
  31. data/vendored/puppet/lib/puppet/network/http/factory.rb +2 -6
  32. data/vendored/puppet/lib/puppet/node.rb +1 -2
  33. data/vendored/puppet/lib/puppet/node/environment.rb +5 -1
  34. data/vendored/puppet/lib/puppet/parser/functions.rb +35 -3
  35. data/vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb +12 -0
  36. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -5
  37. data/vendored/puppet/lib/puppet/pops/model/ast.rb +107 -0
  38. data/vendored/puppet/lib/puppet/pops/model/factory.rb +11 -0
  39. data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +2 -0
  40. data/vendored/puppet/lib/puppet/pops/parser/eparser.rb +1519 -1485
  41. data/vendored/puppet/lib/puppet/pops/parser/lexer2.rb +1 -1
  42. data/vendored/puppet/lib/puppet/pops/puppet_stack.rb +1 -1
  43. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +1 -1
  44. data/vendored/puppet/lib/puppet/pops/types/p_binary_type.rb +1 -2
  45. data/vendored/puppet/lib/puppet/pops/types/types.rb +1 -24
  46. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +5 -0
  47. data/vendored/puppet/lib/puppet/pops/validation/tasks_checker.rb +31 -4
  48. data/vendored/puppet/lib/puppet/provider.rb +12 -1
  49. data/vendored/puppet/lib/puppet/provider/package/dnf.rb +2 -1
  50. data/vendored/puppet/lib/puppet/provider/selmodule/semodule.rb +1 -1
  51. data/vendored/puppet/lib/puppet/provider/service/base.rb +1 -1
  52. data/vendored/puppet/lib/puppet/provider/service/systemd.rb +3 -1
  53. data/vendored/puppet/lib/puppet/provider/service/upstart.rb +2 -0
  54. data/vendored/puppet/lib/puppet/reference/configuration.rb +6 -0
  55. data/vendored/puppet/lib/puppet/reports.rb +2 -2
  56. data/vendored/puppet/lib/puppet/resource/status.rb +2 -0
  57. data/vendored/puppet/lib/puppet/resource/type_collection.rb +1 -1
  58. data/vendored/puppet/lib/puppet/rest/client.rb +28 -24
  59. data/vendored/puppet/lib/puppet/rest/response.rb +5 -0
  60. data/vendored/puppet/lib/puppet/rest/route.rb +13 -31
  61. data/vendored/puppet/lib/puppet/rest/routes.rb +65 -5
  62. data/vendored/puppet/lib/puppet/rest/ssl_context.rb +13 -0
  63. data/vendored/puppet/lib/puppet/settings.rb +6 -0
  64. data/vendored/puppet/lib/puppet/settings/config_file.rb +1 -2
  65. data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +5 -1
  66. data/vendored/puppet/lib/puppet/ssl/host.rb +148 -43
  67. data/vendored/puppet/lib/puppet/ssl/oids.rb +1 -1
  68. data/vendored/puppet/lib/puppet/test/test_helper.rb +3 -0
  69. data/vendored/puppet/lib/puppet/transaction/event_manager.rb +3 -1
  70. data/vendored/puppet/lib/puppet/transaction/report.rb +1 -1
  71. data/vendored/puppet/lib/puppet/type.rb +2 -2
  72. data/vendored/puppet/lib/puppet/type/file/content.rb +2 -3
  73. data/vendored/puppet/lib/puppet/type/schedule.rb +33 -84
  74. data/vendored/puppet/lib/puppet/type/user.rb +1 -1
  75. data/vendored/puppet/lib/puppet/util.rb +5 -0
  76. data/vendored/puppet/lib/puppet/util/autoload.rb +39 -31
  77. data/vendored/puppet/lib/puppet/util/character_encoding.rb +0 -22
  78. data/vendored/puppet/lib/puppet/util/command_line.rb +0 -1
  79. data/vendored/puppet/lib/puppet/util/connection.rb +74 -0
  80. data/vendored/puppet/lib/puppet/util/feature.rb +2 -2
  81. data/vendored/puppet/lib/puppet/util/instance_loader.rb +1 -19
  82. data/vendored/puppet/lib/puppet/util/json.rb +0 -8
  83. data/vendored/puppet/lib/puppet/util/log/destinations.rb +1 -1
  84. data/vendored/puppet/lib/puppet/util/network_device/base.rb +1 -1
  85. data/vendored/puppet/lib/puppet/util/platform.rb +3 -0
  86. data/vendored/puppet/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +1 -1
  87. data/vendored/puppet/lib/puppet/util/reference.rb +2 -2
  88. data/vendored/puppet/lib/puppet/util/rubygems.rb +1 -13
  89. data/vendored/puppet/lib/puppet/util/ssl.rb +40 -1
  90. data/vendored/puppet/lib/puppet/util/windows.rb +1 -0
  91. data/vendored/puppet/lib/puppet/util/windows/file.rb +18 -0
  92. data/vendored/puppet/lib/puppet/util/windows/security.rb +26 -14
  93. metadata +8 -73
  94. data/vendored/puppet/lib/puppet/module_tool/applications/builder.rb +0 -152
  95. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/spec/spec_helper.rb +0 -1
  96. data/vendored/puppet/lib/puppet/provider/mailalias/aliases.rb +0 -50
  97. data/vendored/puppet/lib/puppet/provider/maillist/mailman.rb +0 -108
  98. data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +0 -108
  99. data/vendored/puppet/lib/puppet/provider/zone/solaris.rb +0 -364
  100. data/vendored/puppet/lib/puppet/provider/zpool/zpool.rb +0 -125
  101. data/vendored/puppet/lib/puppet/type/mailalias.rb +0 -46
  102. data/vendored/puppet/lib/puppet/type/maillist.rb +0 -62
  103. data/vendored/puppet/lib/puppet/type/zfs.rb +0 -154
  104. data/vendored/puppet/lib/puppet/type/zone.rb +0 -382
  105. data/vendored/puppet/lib/puppet/type/zpool.rb +0 -91
@@ -662,7 +662,7 @@ class Lexer2
662
662
  :line_lexical_start => 0
663
663
  }
664
664
  # Use of --tasks introduces the new keyword 'plan'
665
- @taskm_keywords = Puppet[:tasks] ? { 'plan' => [:PLAN, 'plan', 4] }.freeze : EMPTY_HASH
665
+ @taskm_keywords = Puppet[:tasks] ? { 'plan' => [:PLAN, 'plan', 4], 'apply' => [:APPLY, 'apply', 5] }.freeze : EMPTY_HASH
666
666
  end
667
667
 
668
668
  # Scans all of the content and returns it in an array
@@ -18,7 +18,7 @@ module Puppet::Pops
18
18
  #
19
19
  module PuppetStack
20
20
  # Pattern matching an entry in the ruby stack that is a puppet entry
21
- PP_ENTRY_PATTERN = /^(.*\.pp)?:([0-9]+):in (`stack'|`block in call_function')/
21
+ PP_ENTRY_PATTERN = /^(.*\.pp)?:([0-9]+):in (`stack'|`block in call_function'|`<eval>')/
22
22
 
23
23
  # Sends a message to an obj such that it appears to come from
24
24
  # file, line when calling stacktrace.
@@ -96,7 +96,7 @@ module Serialization
96
96
  end
97
97
  elsif value.instance_of?(Hash)
98
98
  process(value) do
99
- if value.keys.all? { |key| key.is_a?(String) }
99
+ if value.keys.all? { |key| key.is_a?(String) && key != PCORE_TYPE_KEY }
100
100
  result = {}
101
101
  value.each_pair { |key, elem| with(key) { result[key] = to_data(elem) } }
102
102
  result
@@ -91,8 +91,7 @@ class PBinaryType < PAnyType
91
91
  # @api private
92
92
  #
93
93
  def initialize(bin)
94
- # TODO: When Ruby 1.9.3 support is dropped change this to `bin.b` for binary encoding instead of force_encoding
95
- @binary_buffer = (bin.encoding.name == "ASCII-8BIT" ? bin : bin.dup.force_encoding("ASCII-8BIT")).freeze
94
+ @binary_buffer = (bin.encoding.name == "ASCII-8BIT" ? bin : bin.b).freeze
96
95
  end
97
96
 
98
97
  # Presents the binary content as a string base64 encoded string (without line breaks).
@@ -1703,30 +1703,7 @@ class PRegexpType < PScalarType
1703
1703
  # @param regexp [Regexp] the regular expression
1704
1704
  # @return [String] the Regexp as a string without escaped slash
1705
1705
  def self.regexp_to_s(regexp)
1706
- # Rubies < 2.0.0 retains escaped delimiters in the source string.
1707
- @source_retains_escaped_slash ||= Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
1708
- source = regexp.source
1709
- if @source_retains_escaped_slash && source.include?('\\')
1710
- # Restore corrupt string in rubies <2.0.0, i.e. turn '\/' into '/' but
1711
- # don't touch valid escapes such as '\s', '\{' etc.
1712
- escaped = false
1713
- bld = ''
1714
- source.each_codepoint do |codepoint|
1715
- if escaped
1716
- bld << 0x5c unless codepoint == 0x2f # '/'
1717
- bld << codepoint
1718
- escaped = false
1719
- elsif codepoint == 0x5c # '\'
1720
- escaped = true
1721
- elsif codepoint <= 0x7f
1722
- bld << codepoint
1723
- else
1724
- bld << [codepoint].pack('U')
1725
- end
1726
- end
1727
- source = bld
1728
- end
1729
- append_flags_group(source, regexp.options)
1706
+ append_flags_group(regexp.source, regexp.options)
1730
1707
  end
1731
1708
 
1732
1709
  def self.append_flags_group(rx_string, options)
@@ -1036,6 +1036,11 @@ class Checker4_0 < Evaluator::LiteralEvaluator
1036
1036
  true
1037
1037
  end
1038
1038
 
1039
+ def idem_ApplyExpression(o)
1040
+ return false if o.arguments.any? { |value| !idem(value) }
1041
+ idem(o.body)
1042
+ end
1043
+
1039
1044
  def idem_IfExpression(o)
1040
1045
  [o.test, o.then_expr, o.else_expr].all? {|e| idem(e) }
1041
1046
  end
@@ -4,6 +4,15 @@ module Validation
4
4
  # Validator that limits the set of allowed expressions to not include catalog related operations
5
5
  # @api private
6
6
  class TasksChecker < Checker4_0
7
+ def in_ApplyExpression?
8
+ top = container(0)
9
+ step = -1
10
+ until container(step) == top do
11
+ return true if container(step).is_a? Puppet::Pops::Model::ApplyBlockExpression
12
+ step -= 1
13
+ end
14
+ end
15
+
7
16
  def check_Application(o)
8
17
  illegalTasksExpression(o)
9
18
  end
@@ -25,15 +34,27 @@ class TasksChecker < Checker4_0
25
34
  end
26
35
 
27
36
  def check_RelationshipExpression(o)
28
- illegalTasksExpression(o)
37
+ if in_ApplyExpression?
38
+ super(o)
39
+ else
40
+ illegalTasksExpression(o)
41
+ end
29
42
  end
30
43
 
31
44
  def check_ResourceDefaultsExpression(o)
32
- illegalTasksExpression(o)
45
+ if in_ApplyExpression?
46
+ super(o)
47
+ else
48
+ illegalTasksExpression(o)
49
+ end
33
50
  end
34
51
 
35
52
  def check_ResourceExpression(o)
36
- illegalTasksExpression(o)
53
+ if in_ApplyExpression?
54
+ super(o)
55
+ else
56
+ illegalTasksExpression(o)
57
+ end
37
58
  end
38
59
 
39
60
  def check_ResourceOverrideExpression(o)
@@ -48,8 +69,14 @@ class TasksChecker < Checker4_0
48
69
  illegalTasksExpression(o)
49
70
  end
50
71
 
72
+ def check_ApplyExpression(o)
73
+ if in_ApplyExpression?
74
+ acceptor.accept(Issues::TASK_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, o, {:operation => o.class.to_s})
75
+ end
76
+ end
77
+
51
78
  def illegalTasksExpression(o)
52
- acceptor.accept(Issues::CATALOG_OPERATION_NOT_SUPPORTED_WHEN_SCRIPTING, o)
79
+ acceptor.accept(Issues::CATALOG_OPERATION_NOT_SUPPORTED_WHEN_SCRIPTING, o, {:operation => o.class.to_s})
53
80
  end
54
81
 
55
82
  def resource_without_title?(o)
@@ -278,7 +278,12 @@ class Puppet::Provider
278
278
  # @see Provider.defaultfor
279
279
  # @api private
280
280
  def self.default_match
281
- @defaults.find do |default|
281
+ return nil if some_default_match(@notdefaults) # Blacklist means this provider cannot be a default
282
+ some_default_match(@defaults)
283
+ end
284
+
285
+ def self.some_default_match(defaultlist)
286
+ defaultlist.find do |default|
282
287
  default.all? do |key, values|
283
288
  case key
284
289
  when :feature
@@ -329,6 +334,10 @@ class Puppet::Provider
329
334
  @defaults << hash
330
335
  end
331
336
 
337
+ def self.notdefaultfor(hash)
338
+ @notdefaults << hash
339
+ end
340
+
332
341
  # @return [Integer] Returns a numeric specificity for this provider based on how many requirements it has
333
342
  # and number of _ancestors_. The higher the number the more specific the provider.
334
343
  # The number of requirements is based on the hash size of the matching {Provider.defaultfor}.
@@ -346,6 +355,7 @@ class Puppet::Provider
346
355
  # complexity of a provider).
347
356
  match = default_match
348
357
  length = match ? match.length : 0
358
+
349
359
  (length * 100) + ancestors.select { |a| a.is_a? Class }.length
350
360
  end
351
361
 
@@ -353,6 +363,7 @@ class Puppet::Provider
353
363
  # @return [void]
354
364
  def self.initvars
355
365
  @defaults = []
366
+ @notdefaults = []
356
367
  @commands = {}
357
368
  end
358
369
 
@@ -28,7 +28,8 @@ Puppet::Type.type(:package).provide :dnf, :parent => :yum do
28
28
  end
29
29
  end
30
30
 
31
- defaultfor :operatingsystem => :fedora, :operatingsystemmajrelease => (22..30).to_a
31
+ defaultfor :operatingsystem => :fedora
32
+ notdefaultfor :operatingsystem => :fedora, :operatingsystemmajrelease => (19..21).to_a
32
33
 
33
34
  def self.update_command
34
35
  # In DNF, update is deprecated for upgrade
@@ -22,7 +22,7 @@ Puppet::Type.type(:selmodule).provide(:semodule) do
22
22
  self.debug "Checking for module #{@resource[:name]}"
23
23
  execpipe("#{command(:semodule)} --list") do |out|
24
24
  out.each_line do |line|
25
- if line =~ /#{@resource[:name]}\b/
25
+ if line =~ /^#{@resource[:name]}\b/
26
26
  return :true
27
27
  end
28
28
  end
@@ -46,7 +46,7 @@ Puppet::Type.type(:service).provide :base, :parent => :service do
46
46
  # If that fails, force to UTF-8 and then scrub as most uses are scanning
47
47
  # for ACII-compatible program names.
48
48
  table.force_encoding(Encoding::UTF_8) unless table.encoding == Encoding::UTF_8
49
- table = Puppet::Util::CharacterEncoding.scrub(table) unless table.valid_encoding?
49
+ table = table.scrub unless table.valid_encoding?
50
50
 
51
51
  table.each_line { |line|
52
52
  if regex.match(line)
@@ -25,7 +25,9 @@ Puppet::Type.type(:service).provide :systemd, :parent => :base do
25
25
  defaultfor :osfamily => :coreos
26
26
  defaultfor :operatingsystem => :amazon, :operatingsystemmajrelease => ["2"]
27
27
  defaultfor :operatingsystem => :debian, :operatingsystemmajrelease => ["8", "stretch/sid", "9", "buster/sid"]
28
- defaultfor :operatingsystem => :ubuntu, :operatingsystemmajrelease => ["15.04","15.10","16.04","16.10","17.04","17.10","18.04"]
28
+
29
+ defaultfor :operatingsystem => :ubuntu
30
+ notdefaultfor :operatingsystem => :ubuntu, :operatingsystemmajrelease => ["10.04", "12.04", "14.04", "14.10"] # These are using upstart
29
31
  defaultfor :operatingsystem => :cumuluslinux, :operatingsystemmajrelease => ["3"]
30
32
 
31
33
  def self.instances
@@ -16,6 +16,8 @@ Puppet::Type.type(:service).provide :upstart, :parent => :debian do
16
16
  Facter.value(:operatingsystem) == 'LinuxMint',
17
17
  ]
18
18
 
19
+ confine :exists => "/var/run/upstart-socket-bridge.pid"
20
+
19
21
  defaultfor :operatingsystem => :ubuntu, :operatingsystemmajrelease => ["10.04", "12.04", "14.04", "14.10"]
20
22
 
21
23
  commands :start => "/sbin/start",
@@ -54,6 +54,12 @@ config.header = <<EOT
54
54
 
55
55
  * Each of these settings can be specified in `puppet.conf` or on the
56
56
  command line.
57
+ * Puppet Enterprise (PE) and open source Puppet share the configuration settings
58
+ that are documented here. However, PE defaults for some settings differ from
59
+ the open source Puppet defaults. Some examples of settings that have different
60
+ PE defaults include `disable18n`, `environment_timeout`, `always_retry_plugins`,
61
+ and the Puppet Server JRuby `max-active-instances` setting. To verify PE
62
+ configuration defaults, check the `puppet.conf` file after installation.
57
63
  * When using boolean settings on the command line, use `--setting` and
58
64
  `--no-setting` instead of `--setting (true|false)`. (Using `--setting false`
59
65
  results in "Error: Could not parse application options: needless argument".)
@@ -73,7 +73,7 @@ class Puppet::Reports
73
73
  docs = ""
74
74
 
75
75
  # Use this method so they all get loaded
76
- instance_loader(:report).loadall
76
+ instance_loader(:report).loadall(Puppet.lookup(:current_environment))
77
77
  loaded_instances(:report).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
78
78
  mod = self.report(name)
79
79
  docs << "#{name}\n#{"-" * name.to_s.length}\n"
@@ -87,7 +87,7 @@ class Puppet::Reports
87
87
  # Lists each of the reports.
88
88
  # @api private
89
89
  def self.reports
90
- instance_loader(:report).loadall
90
+ instance_loader(:report).loadall(Puppet.lookup(:current_environment))
91
91
  loaded_instances(:report)
92
92
  end
93
93
  end
@@ -193,6 +193,7 @@ module Puppet
193
193
  @changed = data['changed']
194
194
  @skipped = data['skipped']
195
195
  @failed = data['failed']
196
+ @failed_to_restart = data['failed_to_restart']
196
197
  @corrective_change = data['corrective_change']
197
198
  @events = data['events'].map do |event|
198
199
  # Older versions contain tags that causes Psych to create instances directly
@@ -213,6 +214,7 @@ module Puppet
213
214
  'tags' => @tags.to_a,
214
215
  'time' => @time.iso8601(9),
215
216
  'failed' => @failed,
217
+ 'failed_to_restart' => self.failed_to_restart?,
216
218
  'changed' => @changed,
217
219
  'out_of_sync' => @out_of_sync,
218
220
  'skipped' => @skipped,
@@ -208,7 +208,7 @@ class Puppet::Resource::TypeCollection
208
208
  if environment.config_version.nil? || environment.config_version == ""
209
209
  @version = Time.now.to_i
210
210
  else
211
- @version = Puppet::Util::Execution.execute([environment.config_version]).strip
211
+ @version = Puppet::Util::Execution.execute([environment.config_version]).to_s.strip
212
212
  end
213
213
  end
214
214
 
@@ -3,18 +3,19 @@ require 'httpclient'
3
3
  require 'puppet'
4
4
  require 'puppet/rest/response'
5
5
  require 'puppet/rest/errors'
6
+ require 'puppet/util/ssl'
6
7
 
7
8
  module Puppet::Rest
8
9
  class Client
9
10
  attr_reader :dns_resolver
10
11
 
11
12
  # Create a new HTTP client for querying the given API.
12
- # @param [OpenSSL::X509::Store] ssl_store the SSL configuration for this client
13
+ # @param [Puppet::Rest::SSLContext] ssl_context the SSL configuration for this client
13
14
  # @param [Integer] receive_timeout how long in seconds this client will wait
14
15
  # for a response after making a request
15
16
  # @param [HTTPClient] client the third-party HTTP client wrapped by this
16
17
  # class. This param is only used for testing.
17
- def initialize(ssl_store: OpenSSL::X509::Store.new,
18
+ def initialize(ssl_context:,
18
19
  receive_timeout: Puppet[:http_read_timeout],
19
20
  client: HTTPClient.new(agent_name: nil,
20
21
  default_header: {
@@ -31,49 +32,52 @@ module Puppet::Rest
31
32
  @client.debug_dev = $stderr
32
33
  end
33
34
 
34
- @client.ssl_config.cert_store = ssl_store
35
-
36
- configure_verify_mode(@client.ssl_config)
35
+ @ca_path = Puppet[:ssl_client_ca_auth] || Puppet[:localcacert]
36
+ @verifier = Puppet::SSL::Validator::DefaultValidator.new(@ca_path)
37
+ configure_verify_mode(ssl_context)
37
38
 
38
39
  @dns_resolver = Puppet::Network::Resolver.new
39
40
  end
40
41
 
41
42
  # Make a GET request to the specified URL with the specified params.
42
- # @param [String] url the full path to query
43
+ # @param [URI::HTTPS] url the full path to query
43
44
  # @param [Hash] query any URL params to add to send to the endpoint
44
45
  # @param [Hash] header any additional entries to add to the default header
45
46
  # @yields [String] chunks of the response body
46
47
  # @raise [Puppet::Rest::ResponseError] if the response status is not OK
47
48
  def get(url, query: nil, header: nil, &block)
48
49
  begin
49
- @client.get_content(url, { query: query, header: header }) do |chunk|
50
+ @client.get_content(url.to_s, { query: query, header: header }) do |chunk|
50
51
  block.call(chunk)
51
52
  end
52
53
  rescue HTTPClient::BadResponseError => e
53
54
  raise Puppet::Rest::ResponseError.new(e.message, Puppet::Rest::Response.new(e.res))
55
+ rescue OpenSSL::OpenSSLError => e
56
+ Puppet::Util::SSL.handle_connection_error(e, @verifier, url.host)
54
57
  end
55
58
  end
56
59
 
57
- private
58
-
59
- # Checks for SSL certificates on disk and sets VERIFY_PEER
60
- # if they are found. Otherwise, sets VERIFY_NONE.
61
- def configure_verify_mode(ssl_config)
62
- # Either the path to an external CA or to our CA cert from the Puppet master
63
- # TODO We may be able to consolidate this with the current intermediate CA work?
64
- ca_path = Puppet[:ssl_client_ca_auth] || Puppet[:localcacert]
65
-
66
- if ssl_certificates_are_present?(ca_path)
67
- ssl_config.verify_mode = OpenSSL::SSL::VERIFY_PEER
68
- ssl_config.add_trust_ca(ca_path)
69
- ssl_config.set_client_cert_file(Puppet[:hostcert], Puppet[:hostprivkey])
70
- else
71
- ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
60
+ # Make a PUT request to the specified URL with the specified params.
61
+ # @param [URI::HTTPS] url the full path to query
62
+ # @param [String/Hash] body the contents of the PUT request
63
+ # @param [Hash] query any URL params to add to send to the endpoint
64
+ # @param [Hash] header any additional entries to add to the default header
65
+ # @return [Puppet::Rest::Response]
66
+ def put(url, body:, query: nil, header: nil)
67
+ begin
68
+ response = @client.put(url.to_s, body: body, query: query, header: header)
69
+ Puppet::Rest::Response.new(response)
70
+ rescue OpenSSL::OpenSSLError => e
71
+ Puppet::Util::SSL.handle_connection_error(e, @verifier, url.host)
72
72
  end
73
73
  end
74
74
 
75
- def ssl_certificates_are_present?(ca_path)
76
- Puppet::FileSystem.exist?(Puppet[:hostcert]) && Puppet::FileSystem.exist?(ca_path)
75
+ private
76
+
77
+ def configure_verify_mode(ssl_context)
78
+ @client.ssl_config.verify_callback = @verifier
79
+ @client.ssl_config.cert_store = ssl_context.cert_store
80
+ @client.ssl_config.verify_mode = ssl_context.verify_mode
77
81
  end
78
82
  end
79
83
  end
@@ -25,5 +25,10 @@ module Puppet::Rest
25
25
  def ok?
26
26
  @message.ok?
27
27
  end
28
+
29
+ def to_exception
30
+ message = _("Error %{code} on SERVER: %{returned_message}") % { code: status_code, returned_message: body }
31
+ Puppet::Rest::ResponseError.new(message, self)
32
+ end
28
33
  end
29
34
  end
@@ -1,21 +1,26 @@
1
1
  require 'uri'
2
+ require 'puppet/util/connection'
2
3
 
3
4
  module Puppet::Rest
4
5
  class Route
6
+ attr_reader :server
7
+
5
8
  # Create a Route containing information for querying the given API,
6
9
  # hosted at a server determined either by SRV service or by the
7
10
  # fallback server on the fallback port.
8
11
  # @param [String] api the path leading to the root of the API. Must
9
12
  # contain a trailing slash for proper endpoint path
10
13
  # construction
11
- # @param [String] default_server the fqdn of the fallback server
12
- # @param [Integer] port the fallback port
14
+ # @param [Symbol] server_setting the setting to check for special
15
+ # server configuration
16
+ # @param [Symbol] port_setting the setting to check for speical
17
+ # port configuration
13
18
  # @param [Symbol] srv_service the name of the service when using SRV
14
19
  # records
15
- def initialize(api:, default_server:, default_port:, srv_service:)
20
+ def initialize(api:, server_setting: :server, port_setting: :masterport, srv_service: :puppet)
16
21
  @api = api
17
- @default_server = default_server
18
- @default_port = default_port
22
+ @default_server = Puppet::Util::Connection.determine_server(server_setting)
23
+ @default_port = Puppet::Util::Connection.determine_port(port_setting, server_setting)
19
24
  @srv_service = srv_service
20
25
  end
21
26
 
@@ -60,32 +65,9 @@ module Puppet::Rest
60
65
  end
61
66
  end
62
67
 
63
- # If we have provided a specific server and port, use those.
64
- if @default_server && @default_port
65
- @server = @default_server
66
- @port = @default_port
67
- else
68
- # Otherwise, get server and port from default settings, taking
69
- # into account the server list for HA.
70
- bound_server = Puppet.lookup(:server) do
71
- if primary_server = Puppet.settings[:server_list][0]
72
- primary_server[0]
73
- else
74
- Puppet.settings[:server]
75
- end
76
- end
77
-
78
- bound_port = Puppet.lookup(:serverport) do
79
- if primary_server = Puppet.settings[:server_list][0]
80
- primary_server[1]
81
- else
82
- Puppet.settings[:masterport]
83
- end
84
- end
85
-
86
- @server = bound_server
87
- @port = bound_port
88
- end
68
+ # If not using SRV records, fall back to the defaults calculated above
69
+ @server = @default_server
70
+ @port = @default_port
89
71
 
90
72
  Puppet.debug "No more servers in SRV record, falling back to #{@server}:#{@port}" if Puppet[:use_srv_records]
91
73
  return yield(base_url)