bolt 0.20.3 → 0.20.5

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 (256) hide show
  1. checksums.yaml +4 -4
  2. data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +3 -3
  3. data/bolt-modules/boltlib/lib/puppet/functions/set_feature.rb +33 -0
  4. data/lib/bolt/inventory.rb +19 -1
  5. data/lib/bolt/target.rb +15 -0
  6. data/lib/bolt/transport/local.rb +6 -1
  7. data/lib/bolt/transport/orch.rb +2 -0
  8. data/lib/bolt/transport/ssh.rb +7 -2
  9. data/lib/bolt/transport/winrm.rb +6 -1
  10. data/lib/bolt/version.rb +1 -1
  11. data/modules/facts/plans/retrieve.pp +2 -26
  12. data/modules/facts/tasks/init.json +9 -0
  13. data/vendored/puppet/lib/hiera/puppet_function.rb +1 -1
  14. data/vendored/puppet/lib/hiera/scope.rb +24 -2
  15. data/vendored/puppet/lib/puppet.rb +4 -13
  16. data/vendored/puppet/lib/puppet/application.rb +2 -2
  17. data/vendored/puppet/lib/puppet/application/agent.rb +1 -1
  18. data/vendored/puppet/lib/puppet/application/apply.rb +1 -1
  19. data/vendored/puppet/lib/puppet/application/cert.rb +1 -1
  20. data/vendored/puppet/lib/puppet/application/device.rb +8 -8
  21. data/vendored/puppet/lib/puppet/application/face_base.rb +1 -1
  22. data/vendored/puppet/lib/puppet/application/lookup.rb +2 -2
  23. data/vendored/puppet/lib/puppet/application/resource.rb +2 -2
  24. data/vendored/puppet/lib/puppet/application/script.rb +1 -1
  25. data/vendored/puppet/lib/puppet/configurer.rb +47 -24
  26. data/vendored/puppet/lib/puppet/confine.rb +4 -1
  27. data/vendored/puppet/lib/puppet/context.rb +1 -1
  28. data/vendored/puppet/lib/puppet/defaults.rb +32 -44
  29. data/vendored/puppet/lib/puppet/error.rb +14 -7
  30. data/vendored/puppet/lib/puppet/external/dot.rb +23 -17
  31. data/vendored/puppet/lib/puppet/face/config.rb +58 -3
  32. data/vendored/puppet/lib/puppet/face/epp.rb +1 -1
  33. data/vendored/puppet/lib/puppet/face/module/build.rb +3 -3
  34. data/vendored/puppet/lib/puppet/face/module/install.rb +0 -4
  35. data/vendored/puppet/lib/puppet/face/module/list.rb +0 -5
  36. data/vendored/puppet/lib/puppet/face/module/search.rb +1 -1
  37. data/vendored/puppet/lib/puppet/face/module/uninstall.rb +0 -4
  38. data/vendored/puppet/lib/puppet/face/module/upgrade.rb +0 -4
  39. data/vendored/puppet/lib/puppet/face/status.rb +2 -2
  40. data/vendored/puppet/lib/puppet/file_serving/base.rb +5 -5
  41. data/vendored/puppet/lib/puppet/file_serving/metadata.rb +2 -1
  42. data/vendored/puppet/lib/puppet/forge.rb +7 -8
  43. data/vendored/puppet/lib/puppet/forge/errors.rb +3 -3
  44. data/vendored/puppet/lib/puppet/functions/abs.rb +61 -0
  45. data/vendored/puppet/lib/puppet/functions/all.rb +2 -2
  46. data/vendored/puppet/lib/puppet/functions/any.rb +2 -2
  47. data/vendored/puppet/lib/puppet/functions/assert_type.rb +3 -3
  48. data/vendored/puppet/lib/puppet/functions/break.rb +3 -7
  49. data/vendored/puppet/lib/puppet/functions/camelcase.rb +62 -0
  50. data/vendored/puppet/lib/puppet/functions/capitalize.rb +61 -0
  51. data/vendored/puppet/lib/puppet/functions/ceiling.rb +37 -0
  52. data/vendored/puppet/lib/puppet/functions/chomp.rb +57 -0
  53. data/vendored/puppet/lib/puppet/functions/chop.rb +67 -0
  54. data/vendored/puppet/lib/puppet/functions/compare.rb +125 -0
  55. data/vendored/puppet/lib/puppet/functions/convert_to.rb +3 -2
  56. data/vendored/puppet/lib/puppet/functions/dig.rb +21 -1
  57. data/vendored/puppet/lib/puppet/functions/downcase.rb +89 -0
  58. data/vendored/puppet/lib/puppet/functions/each.rb +2 -2
  59. data/vendored/puppet/lib/puppet/functions/empty.rb +1 -3
  60. data/vendored/puppet/lib/puppet/functions/eyaml_lookup_key.rb +4 -2
  61. data/vendored/puppet/lib/puppet/functions/filter.rb +2 -2
  62. data/vendored/puppet/lib/puppet/functions/floor.rb +37 -0
  63. data/vendored/puppet/lib/puppet/functions/get.rb +150 -0
  64. data/vendored/puppet/lib/puppet/functions/getvar.rb +87 -0
  65. data/vendored/puppet/lib/puppet/functions/hiera.rb +5 -5
  66. data/vendored/puppet/lib/puppet/functions/hiera_array.rb +5 -5
  67. data/vendored/puppet/lib/puppet/functions/hiera_hash.rb +6 -6
  68. data/vendored/puppet/lib/puppet/functions/hiera_include.rb +7 -7
  69. data/vendored/puppet/lib/puppet/functions/hocon_data.rb +1 -1
  70. data/vendored/puppet/lib/puppet/functions/json_data.rb +3 -3
  71. data/vendored/puppet/lib/puppet/functions/lest.rb +1 -1
  72. data/vendored/puppet/lib/puppet/functions/lookup.rb +3 -2
  73. data/vendored/puppet/lib/puppet/functions/lstrip.rb +58 -0
  74. data/vendored/puppet/lib/puppet/functions/map.rb +1 -1
  75. data/vendored/puppet/lib/puppet/functions/match.rb +11 -0
  76. data/vendored/puppet/lib/puppet/functions/max.rb +183 -0
  77. data/vendored/puppet/lib/puppet/functions/min.rb +182 -0
  78. data/vendored/puppet/lib/puppet/functions/next.rb +1 -8
  79. data/vendored/puppet/lib/puppet/functions/reduce.rb +1 -1
  80. data/vendored/puppet/lib/puppet/functions/return.rb +1 -8
  81. data/vendored/puppet/lib/puppet/functions/reverse_each.rb +1 -1
  82. data/vendored/puppet/lib/puppet/functions/round.rb +24 -0
  83. data/vendored/puppet/lib/puppet/functions/rstrip.rb +58 -0
  84. data/vendored/puppet/lib/puppet/functions/size.rb +15 -0
  85. data/vendored/puppet/lib/puppet/functions/sort.rb +74 -0
  86. data/vendored/puppet/lib/puppet/functions/step.rb +1 -1
  87. data/vendored/puppet/lib/puppet/functions/strftime.rb +1 -7
  88. data/vendored/puppet/lib/puppet/functions/strip.rb +58 -0
  89. data/vendored/puppet/lib/puppet/functions/then.rb +1 -1
  90. data/vendored/puppet/lib/puppet/functions/tree_each.rb +7 -7
  91. data/vendored/puppet/lib/puppet/functions/upcase.rb +89 -0
  92. data/vendored/puppet/lib/puppet/functions/with.rb +4 -4
  93. data/vendored/puppet/lib/puppet/functions/yaml_data.rb +4 -2
  94. data/vendored/puppet/lib/puppet/graph/simple_graph.rb +9 -5
  95. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/rest.rb +0 -11
  96. data/vendored/puppet/lib/puppet/indirector/indirection.rb +8 -12
  97. data/vendored/puppet/lib/puppet/indirector/node/exec.rb +1 -1
  98. data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +1 -1
  99. data/vendored/puppet/lib/puppet/indirector/request.rb +11 -11
  100. data/vendored/puppet/lib/puppet/indirector/rest.rb +11 -11
  101. data/vendored/puppet/lib/puppet/interface/action.rb +2 -5
  102. data/vendored/puppet/lib/puppet/metatype/manager.rb +0 -2
  103. data/vendored/puppet/lib/puppet/module.rb +7 -33
  104. data/vendored/puppet/lib/puppet/module/task.rb +0 -1
  105. data/vendored/puppet/lib/puppet/module_tool.rb +2 -5
  106. data/vendored/puppet/lib/puppet/module_tool/applications/application.rb +5 -5
  107. data/vendored/puppet/lib/puppet/module_tool/applications/builder.rb +2 -2
  108. data/vendored/puppet/lib/puppet/module_tool/applications/checksummer.rb +3 -3
  109. data/vendored/puppet/lib/puppet/module_tool/applications/installer.rb +6 -7
  110. data/vendored/puppet/lib/puppet/module_tool/applications/uninstaller.rb +1 -2
  111. data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +2 -2
  112. data/vendored/puppet/lib/puppet/module_tool/applications/upgrader.rb +5 -6
  113. data/vendored/puppet/lib/puppet/module_tool/dependency.rb +1 -1
  114. data/vendored/puppet/lib/puppet/module_tool/installed_modules.rb +2 -2
  115. data/vendored/puppet/lib/puppet/module_tool/local_tarball.rb +3 -3
  116. data/vendored/puppet/lib/puppet/module_tool/metadata.rb +3 -4
  117. data/vendored/puppet/lib/puppet/module_tool/shared_behaviors.rb +2 -2
  118. data/vendored/puppet/lib/puppet/network/authconfig.rb +0 -13
  119. data/vendored/puppet/lib/puppet/network/format_support.rb +1 -1
  120. data/vendored/puppet/lib/puppet/network/formats.rb +5 -7
  121. data/vendored/puppet/lib/puppet/network/http.rb +0 -2
  122. data/vendored/puppet/lib/puppet/network/http/api.rb +1 -10
  123. data/vendored/puppet/lib/puppet/network/http/api/master/v3/environment.rb +2 -2
  124. data/vendored/puppet/lib/puppet/network/http/api/master/v3/environments.rb +2 -2
  125. data/vendored/puppet/lib/puppet/network/http/compression.rb +1 -1
  126. data/vendored/puppet/lib/puppet/network/http/connection.rb +11 -3
  127. data/vendored/puppet/lib/puppet/network/http/error.rb +3 -3
  128. data/vendored/puppet/lib/puppet/network/http/factory.rb +3 -0
  129. data/vendored/puppet/lib/puppet/network/http/handler.rb +59 -27
  130. data/vendored/puppet/lib/puppet/network/resolver.rb +140 -67
  131. data/vendored/puppet/lib/puppet/node/environment.rb +2 -19
  132. data/vendored/puppet/lib/puppet/parameter.rb +12 -7
  133. data/vendored/puppet/lib/puppet/parser/ast.rb +4 -8
  134. data/vendored/puppet/lib/puppet/parser/ast/branch.rb +3 -3
  135. data/vendored/puppet/lib/puppet/parser/ast/leaf.rb +5 -0
  136. data/vendored/puppet/lib/puppet/parser/ast/pops_bridge.rb +18 -0
  137. data/vendored/puppet/lib/puppet/parser/compiler.rb +3 -4
  138. data/vendored/puppet/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +9 -2
  139. data/vendored/puppet/lib/puppet/parser/functions.rb +1 -1
  140. data/vendored/puppet/lib/puppet/parser/functions/assert_type.rb +3 -3
  141. data/vendored/puppet/lib/puppet/parser/functions/create_resources.rb +1 -7
  142. data/vendored/puppet/lib/puppet/parser/functions/each.rb +2 -2
  143. data/vendored/puppet/lib/puppet/parser/functions/filter.rb +1 -1
  144. data/vendored/puppet/lib/puppet/parser/functions/hiera.rb +4 -4
  145. data/vendored/puppet/lib/puppet/parser/functions/hiera_array.rb +5 -5
  146. data/vendored/puppet/lib/puppet/parser/functions/hiera_hash.rb +6 -6
  147. data/vendored/puppet/lib/puppet/parser/functions/hiera_include.rb +10 -11
  148. data/vendored/puppet/lib/puppet/parser/functions/inline_template.rb +1 -1
  149. data/vendored/puppet/lib/puppet/parser/functions/lest.rb +1 -1
  150. data/vendored/puppet/lib/puppet/parser/functions/lookup.rb +1 -1
  151. data/vendored/puppet/lib/puppet/parser/functions/map.rb +1 -1
  152. data/vendored/puppet/lib/puppet/parser/functions/reduce.rb +1 -1
  153. data/vendored/puppet/lib/puppet/parser/functions/return.rb +22 -1
  154. data/vendored/puppet/lib/puppet/parser/functions/reverse_each.rb +1 -1
  155. data/vendored/puppet/lib/puppet/parser/functions/step.rb +1 -1
  156. data/vendored/puppet/lib/puppet/parser/functions/then.rb +1 -1
  157. data/vendored/puppet/lib/puppet/parser/functions/with.rb +4 -4
  158. data/vendored/puppet/lib/puppet/parser/resource.rb +0 -1
  159. data/vendored/puppet/lib/puppet/parser/resource/param.rb +12 -5
  160. data/vendored/puppet/lib/puppet/parser/scope.rb +5 -7
  161. data/vendored/puppet/lib/puppet/pops/evaluator/compare_operator.rb +3 -1
  162. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +2 -7
  163. data/vendored/puppet/lib/puppet/pops/issues.rb +4 -0
  164. data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +2 -2
  165. data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +17 -12
  166. data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +73 -45
  167. data/vendored/puppet/lib/puppet/pops/lookup/lookup_adapter.rb +55 -6
  168. data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +2 -0
  169. data/vendored/puppet/lib/puppet/pops/parser/epp_parser.rb +1 -1
  170. data/vendored/puppet/lib/puppet/pops/parser/epp_support.rb +6 -2
  171. data/vendored/puppet/lib/puppet/pops/parser/lexer2.rb +1 -1
  172. data/vendored/puppet/lib/puppet/pops/pcore.rb +7 -7
  173. data/vendored/puppet/lib/puppet/pops/puppet_stack.rb +15 -1
  174. data/vendored/puppet/lib/puppet/pops/serialization.rb +2 -2
  175. data/vendored/puppet/lib/puppet/pops/serialization/from_data_converter.rb +2 -2
  176. data/vendored/puppet/lib/puppet/pops/serialization/json.rb +7 -7
  177. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +5 -5
  178. data/vendored/puppet/lib/puppet/pops/types/types.rb +8 -4
  179. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +73 -0
  180. data/vendored/puppet/lib/puppet/pops/validation/validator_factory_4_0.rb +4 -3
  181. data/vendored/puppet/lib/puppet/provider/augeas/augeas.rb +7 -0
  182. data/vendored/puppet/lib/puppet/provider/service/systemd.rb +1 -1
  183. data/vendored/puppet/lib/puppet/provider/user/aix.rb +2 -2
  184. data/vendored/puppet/lib/puppet/provider/yumrepo/inifile.rb +21 -9
  185. data/vendored/puppet/lib/puppet/reference/providers.rb +1 -1
  186. data/vendored/puppet/lib/puppet/reference/report.rb +1 -1
  187. data/vendored/puppet/lib/puppet/resource.rb +1 -1
  188. data/vendored/puppet/lib/puppet/resource/capability_finder.rb +4 -4
  189. data/vendored/puppet/lib/puppet/resource/catalog.rb +6 -3
  190. data/vendored/puppet/lib/puppet/resource/type.rb +6 -2
  191. data/vendored/puppet/lib/puppet/rest/client.rb +79 -0
  192. data/vendored/puppet/lib/puppet/rest/errors.rb +14 -0
  193. data/vendored/puppet/lib/puppet/rest/response.rb +29 -0
  194. data/vendored/puppet/lib/puppet/rest/route.rb +102 -0
  195. data/vendored/puppet/lib/puppet/rest/routes.rb +31 -0
  196. data/vendored/puppet/lib/puppet/settings.rb +9 -5
  197. data/vendored/puppet/lib/puppet/settings/config_file.rb +1 -1
  198. data/vendored/puppet/lib/puppet/settings/environment_conf.rb +10 -1
  199. data/vendored/puppet/lib/puppet/ssl.rb +0 -1
  200. data/vendored/puppet/lib/puppet/ssl/certificate.rb +6 -2
  201. data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +3 -3
  202. data/vendored/puppet/lib/puppet/ssl/host.rb +258 -19
  203. data/vendored/puppet/lib/puppet/ssl/validator/default_validator.rb +33 -19
  204. data/vendored/puppet/lib/puppet/syntax_checkers/json.rb +1 -1
  205. data/vendored/puppet/lib/puppet/transaction/event.rb +34 -7
  206. data/vendored/puppet/lib/puppet/transaction/report.rb +17 -14
  207. data/vendored/puppet/lib/puppet/type.rb +20 -12
  208. data/vendored/puppet/lib/puppet/type/file.rb +1 -1
  209. data/vendored/puppet/lib/puppet/type/file/content.rb +15 -2
  210. data/vendored/puppet/lib/puppet/type/file/ensure.rb +1 -1
  211. data/vendored/puppet/lib/puppet/type/schedule.rb +1 -1
  212. data/vendored/puppet/lib/puppet/type/stage.rb +1 -1
  213. data/vendored/puppet/lib/puppet/type/tidy.rb +5 -1
  214. data/vendored/puppet/lib/puppet/type/user.rb +35 -18
  215. data/vendored/puppet/lib/puppet/type/yumrepo.rb +8 -17
  216. data/vendored/puppet/lib/puppet/util.rb +0 -1
  217. data/vendored/puppet/lib/puppet/util/autoload.rb +1 -6
  218. data/vendored/puppet/lib/puppet/util/checksums.rb +0 -2
  219. data/vendored/puppet/lib/puppet/util/classgen.rb +0 -6
  220. data/vendored/puppet/lib/puppet/util/fileparsing.rb +27 -5
  221. data/vendored/puppet/lib/puppet/util/instance_loader.rb +3 -3
  222. data/vendored/puppet/lib/puppet/util/json.rb +77 -0
  223. data/vendored/puppet/lib/puppet/util/json_lockfile.rb +3 -3
  224. data/vendored/puppet/lib/puppet/util/ldap/connection.rb +7 -7
  225. data/vendored/puppet/lib/puppet/util/log/destinations.rb +2 -2
  226. data/vendored/puppet/lib/puppet/util/logging.rb +1 -1
  227. data/vendored/puppet/lib/puppet/util/plist.rb +1 -1
  228. data/vendored/puppet/lib/puppet/util/provider_features.rb +2 -5
  229. data/vendored/puppet/lib/puppet/util/reference.rb +5 -4
  230. data/vendored/puppet/lib/puppet/util/tagging.rb +16 -3
  231. data/vendored/puppet/lib/puppet/version.rb +1 -1
  232. metadata +44 -26
  233. data/vendored/puppet/lib/puppet/application/master.rb +0 -317
  234. data/vendored/puppet/lib/puppet/feature/rack.rb +0 -19
  235. data/vendored/puppet/lib/puppet/network/http/api/ca.rb +0 -2
  236. data/vendored/puppet/lib/puppet/network/http/api/ca/v1.rb +0 -11
  237. data/vendored/puppet/lib/puppet/network/http/rack.rb +0 -33
  238. data/vendored/puppet/lib/puppet/network/http/rack/rest.rb +0 -162
  239. data/vendored/puppet/lib/puppet/network/http/webrick.rb +0 -124
  240. data/vendored/puppet/lib/puppet/network/http/webrick/rest.rb +0 -114
  241. data/vendored/puppet/lib/puppet/network/server.rb +0 -39
  242. data/vendored/puppet/lib/puppet/ssl/configuration.rb +0 -61
  243. data/vendored/puppet/lib/puppet/util/methodhelper.rb +0 -32
  244. data/vendored/puppet/lib/puppet/vendor/load_semantic.rb +0 -1
  245. data/vendored/puppet/lib/puppet/vendor/load_semantic_puppet.rb +0 -1
  246. data/vendored/puppet/lib/puppet/vendor/semantic/lib/semantic.rb +0 -5
  247. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet.rb +0 -11
  248. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency.rb +0 -181
  249. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph.rb +0 -60
  250. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb +0 -117
  251. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/module_release.rb +0 -58
  252. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/source.rb +0 -25
  253. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/unsatisfiable_graph.rb +0 -31
  254. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/gem_version.rb +0 -3
  255. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version.rb +0 -203
  256. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version_range.rb +0 -758
@@ -97,7 +97,7 @@ module Puppet::Network::FormatSupport
97
97
  end
98
98
 
99
99
  def to_json(*args)
100
- to_data_hash.to_json(*args)
100
+ Puppet::Util::Json.dump(to_data_hash, *args)
101
101
  end
102
102
 
103
103
  def render(format = nil)
@@ -1,5 +1,5 @@
1
1
  require 'puppet/network/format_handler'
2
- require 'json'
2
+ require 'puppet/util/json'
3
3
 
4
4
  Puppet::Network::FormatHandler.create_serialized_formats(:msgpack, :weight => 20, :mime => "application/x-msgpack", :required_methods => [:render_method, :intern_method], :intern_method => :from_data_hash) do
5
5
 
@@ -101,19 +101,17 @@ end
101
101
 
102
102
  Puppet::Network::FormatHandler.create_serialized_formats(:json, :mime => 'application/json', :charset => Encoding::UTF_8, :weight => 15, :required_methods => [:render_method, :intern_method], :intern_method => :from_data_hash) do
103
103
  def intern(klass, text)
104
- data_to_instance(klass, JSON.parse(text))
104
+ data_to_instance(klass, Puppet::Util::Json.load(text))
105
105
  end
106
106
 
107
107
  def intern_multiple(klass, text)
108
- JSON.parse(text).collect do |data|
108
+ Puppet::Util::Json.load(text).collect do |data|
109
109
  data_to_instance(klass, data)
110
110
  end
111
111
  end
112
112
 
113
- # JSON monkey-patches Array, so this works.
114
- # https://github.com/ruby/ruby/blob/ruby_1_9_3/ext/json/generator/generator.c#L1416
115
113
  def render_multiple(instances)
116
- instances.to_json
114
+ Puppet::Util::Json.dump(instances)
117
115
  end
118
116
 
119
117
  # Unlike PSON, we do not need to unwrap the data envelope, because legacy 3.x agents
@@ -162,7 +160,7 @@ Puppet::Network::FormatHandler.create(:console,
162
160
  end
163
161
 
164
162
  # ...or pretty-print the inspect outcome.
165
- JSON.pretty_generate(datum, :quirks_mode => true)
163
+ Puppet::Util::Json.dump(datum, :pretty => true, :quirks_mode => true)
166
164
  end
167
165
 
168
166
  def render_multiple(data)
@@ -13,8 +13,6 @@ module Puppet::Network::HTTP
13
13
  require 'puppet/network/http/error'
14
14
  require 'puppet/network/http/route'
15
15
  require 'puppet/network/http/api'
16
- require 'puppet/network/http/api/ca'
17
- require 'puppet/network/http/api/ca/v1'
18
16
  require 'puppet/network/http/api/master'
19
17
  require 'puppet/network/http/api/master/v3'
20
18
  require 'puppet/network/http/handler'
@@ -20,8 +20,7 @@ class Puppet::Network::HTTP::API
20
20
  "or point them to a server running Puppet 3.\n\n" +
21
21
  "Master Info:\n" +
22
22
  " Puppet version: #{Puppet.version}\n" +
23
- " Supported /puppet API versions: #{Puppet::Network::HTTP::MASTER_URL_VERSIONS}\n" +
24
- " Supported /puppet-ca API versions: #{Puppet::Network::HTTP::CA_URL_VERSIONS}",
23
+ " Supported /puppet API versions: #{Puppet::Network::HTTP::MASTER_URL_VERSIONS}\n",
25
24
  Puppet::Network::HTTP::Issues::HANDLER_NOT_FOUND)
26
25
  end)
27
26
  end
@@ -33,12 +32,4 @@ class Puppet::Network::HTTP::API
33
32
  chain(Puppet::Network::HTTP::API::Master::V3.routes,
34
33
  Puppet::Network::HTTP::API.not_found)
35
34
  end
36
-
37
- def self.ca_routes
38
- ca_prefix = Regexp.new("^#{Puppet::Network::HTTP::CA_URL_PREFIX}/")
39
- Puppet::Network::HTTP::Route.path(ca_prefix).
40
- any.
41
- chain(Puppet::Network::HTTP::API::CA::V1.routes,
42
- Puppet::Network::HTTP::API.not_found)
43
- end
44
35
  end
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'puppet/util/json'
2
2
  require 'puppet/parser/environment_compiler'
3
3
 
4
4
  class Puppet::Network::HTTP::API::Master::V3::Environment
@@ -15,7 +15,7 @@ class Puppet::Network::HTTP::API::Master::V3::Environment
15
15
 
16
16
  env_graph = build_environment_graph(catalog)
17
17
 
18
- response.respond_with(200, "application/json", JSON.dump(env_graph))
18
+ response.respond_with(200, "application/json", Puppet::Util::Json.dump(env_graph))
19
19
  end
20
20
 
21
21
  def build_environment_graph(catalog)
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'puppet/util/json'
2
2
 
3
3
  class Puppet::Network::HTTP::API::Master::V3::Environments
4
4
  def initialize(env_loader)
@@ -6,7 +6,7 @@ class Puppet::Network::HTTP::API::Master::V3::Environments
6
6
  end
7
7
 
8
8
  def call(request, response)
9
- response.respond_with(200, "application/json", JSON.dump({
9
+ response.respond_with(200, "application/json", Puppet::Util::Json.dump({
10
10
  "search_paths" => @env_loader.search_paths,
11
11
  "environments" => Hash[@env_loader.list.collect do |env|
12
12
  [env.name, {
@@ -32,7 +32,7 @@ module Puppet::Network::HTTP::Compression
32
32
  end
33
33
 
34
34
  def uncompress(response)
35
- raise Net::HTTPError.new("No block passed") unless block_given?
35
+ raise Net::HTTPError.new("No block passed", response) unless block_given?
36
36
 
37
37
  case response['content-encoding']
38
38
  when 'gzip','deflate'
@@ -1,10 +1,10 @@
1
1
  require 'net/https'
2
2
  require 'puppet/ssl/host'
3
- require 'puppet/ssl/configuration'
4
3
  require 'puppet/ssl/validator'
5
4
  require 'puppet/network/http'
6
5
  require 'uri'
7
6
  require 'date'
7
+ require 'time'
8
8
 
9
9
  module Puppet::Network::HTTP
10
10
 
@@ -297,7 +297,14 @@ module Puppet::Network::HTTP
297
297
  end
298
298
 
299
299
  def execute_request(connection, request)
300
+ start = Time.now
300
301
  connection.request(request)
302
+ rescue EOFError => e
303
+ elapsed = (Time.now - start).to_f.round(3)
304
+ uri = @site.addr + request.path.split('?')[0]
305
+ eof = EOFError.new(_('request %{uri} interrupted after %{elapsed} seconds') % {uri: uri, elapsed: elapsed})
306
+ eof.set_backtrace(e.backtrace) unless e.backtrace.empty?
307
+ raise eof
301
308
  end
302
309
 
303
310
  def with_connection(site, &block)
@@ -314,8 +321,9 @@ module Puppet::Network::HTTP
314
321
  msg = error.message
315
322
  msg << ": [" + @verify.verify_errors.join('; ') + "]"
316
323
  raise Puppet::Error, msg, error.backtrace
317
- elsif peer_cert && !OpenSSL::SSL.verify_certificate_identity(peer_cert.content, site.host)
318
- valid_certnames = [peer_cert.name, *peer_cert.subject_alt_names].uniq
324
+ elsif peer_cert && !OpenSSL::SSL.verify_certificate_identity(peer_cert, site.host)
325
+ valid_certnames = [peer_cert.subject.to_s.sub(/.*=/, ''),
326
+ *Puppet::SSL::Certificate.subject_alt_names_for(peer_cert)].uniq
319
327
  if valid_certnames.size > 1
320
328
  expected_certnames = _("expected one of %{certnames}") % { certnames: valid_certnames.join(', ') }
321
329
  else
@@ -1,4 +1,4 @@
1
- require 'json'
1
+ require 'puppet/util/json'
2
2
 
3
3
  module Puppet::Network::HTTP::Error
4
4
  Issues = Puppet::Network::HTTP::Issues
@@ -13,7 +13,7 @@ module Puppet::Network::HTTP::Error
13
13
  end
14
14
 
15
15
  def to_json
16
- JSON({:message => message, :issue_kind => @issue_kind})
16
+ Puppet::Util::Json.dump({:message => message, :issue_kind => @issue_kind})
17
17
  end
18
18
  end
19
19
 
@@ -67,7 +67,7 @@ module Puppet::Network::HTTP::Error
67
67
  end
68
68
 
69
69
  def to_json
70
- JSON({:message => message, :issue_kind => @issue_kind})
70
+ Puppet::Util::Json.dump({:message => message, :issue_kind => @issue_kind})
71
71
  end
72
72
  end
73
73
  end
@@ -12,6 +12,8 @@ require 'puppet/util/http_proxy'
12
12
  class Puppet::Network::HTTP::Factory
13
13
  @@openssl_initialized = false
14
14
 
15
+ KEEP_ALIVE_TIMEOUT = 2**31 - 1
16
+
15
17
  def initialize
16
18
  # PUP-1411, make sure that openssl is initialized before we try to connect
17
19
  if ! @@openssl_initialized
@@ -37,6 +39,7 @@ class Puppet::Network::HTTP::Factory
37
39
  http.use_ssl = site.use_ssl?
38
40
  http.read_timeout = Puppet[:http_read_timeout]
39
41
  http.open_timeout = Puppet[:http_connect_timeout]
42
+ http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT if http.respond_to?(:keep_alive_timeout=)
40
43
 
41
44
  if Puppet[:sourceaddress]
42
45
  if http.respond_to?(:local_host)
@@ -44,42 +44,78 @@ module Puppet::Network::HTTP::Handler
44
44
  format.is_a?(Puppet::Network::Format) ? format.mime : format
45
45
  end
46
46
 
47
- # handle an HTTP request
48
- def process(request, response)
49
- new_response = Puppet::Network::HTTP::Response.new(self, response)
50
-
51
- request_headers = headers(request)
52
- request_params = params(request)
53
- request_method = http_method(request)
47
+ # Create a generic puppet request from the implementation-specific request
48
+ # created by the web server
49
+ def make_generic_request(request)
54
50
  request_path = path(request)
55
51
 
56
- new_request = Puppet::Network::HTTP::Request.new(request_headers, request_params, request_method, request_path, request_path, client_cert(request), body(request))
52
+ Puppet::Network::HTTP::Request.new(
53
+ headers(request),
54
+ params(request),
55
+ http_method(request),
56
+ request_path, # path
57
+ request_path, # routing_path
58
+ client_cert(request),
59
+ body(request)
60
+ )
61
+ end
62
+
63
+ def with_request_profiling(request)
64
+ profiler = configure_profiler(request.headers, request.params)
65
+
66
+ Puppet::Util::Profiler.profile(
67
+ _("Processed request %{request_method} %{request_path}") % { request_method: request.method, request_path: request.path },
68
+ [:http, request.method, request.path]
69
+ ) do
70
+ yield
71
+ end
72
+ ensure
73
+ remove_profiler(profiler) if profiler
74
+ end
57
75
 
58
- response[Puppet::Network::HTTP::HEADER_PUPPET_VERSION] = Puppet.version
76
+ # handle an HTTP request
77
+ def process(external_request, response)
78
+ # The response_wrapper stores the response and modifies it as a side effect.
79
+ # The caller will use the original response
80
+ response_wrapper = Puppet::Network::HTTP::Response.new(self, response)
81
+ request = make_generic_request(external_request)
59
82
 
60
- profiler = configure_profiler(request_headers, request_params)
83
+ set_puppet_version_header(response)
61
84
 
62
- Puppet::Util::Profiler.profile(_("Processed request %{request_method} %{request_path}") % { request_method: request_method, request_path: request_path }, [:http, request_method, request_path]) do
63
- if route = @routes.find { |r| r.matches?(new_request) }
64
- route.process(new_request, new_response)
65
- else
66
- raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new(_("No route for %{request} %{path}") % { request: new_request.method, path: new_request.path }, HANDLER_NOT_FOUND)
85
+ respond_to_errors(response_wrapper) do
86
+ with_request_profiling(request) do
87
+ find_route_or_raise(request).process(request, response_wrapper)
67
88
  end
68
89
  end
90
+ end
69
91
 
92
+ def respond_to_errors(response)
93
+ yield
70
94
  rescue Puppet::Network::HTTP::Error::HTTPError => e
71
95
  Puppet.info(e.message)
72
- new_response.respond_with(e.status, "application/json", e.to_json)
96
+ respond_with_http_error(response, e)
73
97
  rescue StandardError => e
74
98
  http_e = Puppet::Network::HTTP::Error::HTTPServerError.new(e)
75
- log_msg = [http_e.message, *e.backtrace].join("\n")
76
- Puppet.err(log_msg)
77
- new_response.respond_with(http_e.status, "application/json", http_e.to_json)
78
- ensure
79
- if profiler
80
- remove_profiler(profiler)
99
+ Puppet.err([http_e.message, *e.backtrace].join("\n"))
100
+ respond_with_http_error(response, http_e)
101
+ end
102
+
103
+ def respond_with_http_error(response, exception)
104
+ response.respond_with(exception.status, "application/json", exception.to_json)
105
+ end
106
+
107
+ def find_route_or_raise(request)
108
+ if route = @routes.find { |r| r.matches?(request) }
109
+ return route
110
+ else
111
+ raise Puppet::Network::HTTP::Error::HTTPNotFoundError.new(
112
+ _("No route for %{request} %{path}") % { request: request.method, path: request.path },
113
+ HANDLER_NOT_FOUND)
81
114
  end
82
- cleanup(request)
115
+ end
116
+
117
+ def set_puppet_version_header(response)
118
+ response[Puppet::Network::HTTP::HEADER_PUPPET_VERSION] = Puppet.version
83
119
  end
84
120
 
85
121
  # Set the response up, with the body and status.
@@ -131,10 +167,6 @@ module Puppet::Network::HTTP::Handler
131
167
  raise NotImplementedError
132
168
  end
133
169
 
134
- def cleanup(request)
135
- # By default, there is nothing to cleanup.
136
- end
137
-
138
170
  def decode_params(params)
139
171
  params.select { |key, _| allowed_parameter?(key) }.inject({}) do |result, ary|
140
172
  param, value = ary
@@ -1,85 +1,158 @@
1
1
  require 'resolv'
2
- module Puppet::Network; end
3
-
4
- module Puppet::Network::Resolver
5
- # Iterate through the list of servers that service this hostname
6
- # and yield each server/port since SRV records have ports in them
7
- # It will override whatever masterport setting is already set.
8
- def self.each_srv_record(domain, service_name = :puppet, &block)
9
- if (domain.nil? or domain.empty?)
10
- Puppet.debug "Domain not known; skipping SRV lookup"
11
- return
2
+
3
+ module Puppet::Network
4
+ class Resolver
5
+
6
+ class CacheEntry
7
+ attr_reader :records, :ttl, :resolution_time
8
+
9
+ def initialize(records)
10
+ @records = records
11
+ @resolution_time = Time.now
12
+ @ttl = choose_lowest_ttl(records)
13
+ end
14
+
15
+ def choose_lowest_ttl(records)
16
+ ttl = records.first.ttl
17
+ records.each do |rec|
18
+ if rec.ttl < ttl
19
+ ttl = rec.ttl
20
+ end
21
+ end
22
+ ttl
23
+ end
12
24
  end
13
25
 
14
- Puppet.debug "Searching for SRV records for domain: #{domain}"
26
+ def initialize
27
+ @resolver = Resolv::DNS.new
15
28
 
16
- case service_name
17
- when :puppet then service = '_x-puppet'
18
- when :ca then service = '_x-puppet-ca'
19
- when :report then service = '_x-puppet-report'
20
- when :file then service = '_x-puppet-fileserver'
21
- else service = "_x-puppet-#{service_name.to_s}"
29
+ # Stores DNS records per service, along with their TTL
30
+ # and the time at which they were resolved, for cache
31
+ # eviction.
32
+ @record_cache = {}
22
33
  end
23
- srv_record = "#{service}._tcp.#{domain}"
24
-
25
- resolver = Resolv::DNS.new
26
- records = resolver.getresources(srv_record, Resolv::DNS::Resource::IN::SRV)
27
- Puppet.debug "Found #{records.size} SRV records for: #{srv_record}"
28
-
29
- if records.size == 0 && service_name != :puppet
30
- # Try the generic :puppet service if no SRV records were found
31
- # for the specific service.
32
- each_srv_record(domain, :puppet, &block)
33
- else
34
- each_priority(records) do |priority, recs|
35
- while next_rr = recs.delete(find_weighted_server(recs))
36
- Puppet.debug "Yielding next server of #{next_rr.target.to_s}:#{next_rr.port}"
37
- yield next_rr.target.to_s, next_rr.port
34
+
35
+ # Iterate through the list of records for this service
36
+ # and yield each server and port pair. Records are only fetched
37
+ # via DNS query the first time and cached for the duration of their
38
+ # service's TTL thereafter.
39
+ # @param [String] domain the domain to search for
40
+ # @param [Symbol] service_name the key of the service we are querying
41
+ # @yields [String, Integer] server and port of selected record
42
+ def each_srv_record(domain, service_name = :puppet, &block)
43
+ if (domain.nil? or domain.empty?)
44
+ Puppet.debug "Domain not known; skipping SRV lookup"
45
+ return
46
+ end
47
+
48
+ Puppet.debug "Searching for SRV records for domain: #{domain}"
49
+
50
+ case service_name
51
+ when :puppet then service = '_x-puppet'
52
+ when :file then service = '_x-puppet-fileserver'
53
+ else service = "_x-puppet-#{service_name.to_s}"
54
+ end
55
+ record_name = "#{service}._tcp.#{domain}"
56
+
57
+ if @record_cache.has_key?(service_name) && !expired?(service_name)
58
+ records = @record_cache[service_name].records
59
+ Puppet.debug "Using cached record for #{record_name}"
60
+ else
61
+ records = @resolver.getresources(record_name, Resolv::DNS::Resource::IN::SRV)
62
+ if records.size > 0
63
+ @record_cache[service_name] = CacheEntry.new(records)
64
+ end
65
+ Puppet.debug "Found #{records.size} SRV records for: #{record_name}"
66
+ end
67
+
68
+ if records.size == 0 && service_name != :puppet
69
+ # Try the generic :puppet service if no SRV records were found
70
+ # for the specific service.
71
+ each_srv_record(domain, :puppet, &block)
72
+ else
73
+ each_priority(records) do |recs|
74
+ while next_rr = recs.delete(find_weighted_server(recs))
75
+ Puppet.debug "Yielding next server of #{next_rr.target.to_s}:#{next_rr.port}"
76
+ yield next_rr.target.to_s, next_rr.port
77
+ end
38
78
  end
39
79
  end
40
80
  end
41
- end
42
81
 
43
- def self.each_priority(records)
44
- pri_hash = records.inject({}) do |groups, element|
45
- groups[element.priority] ||= []
46
- groups[element.priority] << element
47
- groups
82
+ # Given a list of records of the same priority, chooses a random one
83
+ # from among them, favoring those with higher weights.
84
+ # @param [[Resolv::DNS::Resource::IN::SRV]] records a list of records
85
+ # of the same priority
86
+ # @return [Resolv::DNS::Resource::IN:SRV] the chosen record
87
+ def find_weighted_server(records)
88
+ return nil if records.nil? || records.empty?
89
+ return records.first if records.size == 1
90
+
91
+ # Calculate the sum of all weights in the list of resource records,
92
+ # This is used to then select hosts until the weight exceeds what
93
+ # random number we selected. For example, if we have weights of 1 8 and 3:
94
+ #
95
+ # |-|--------|---|
96
+ # ^
97
+ # We generate a random number 5, and iterate through the records, adding
98
+ # the current record's weight to the accumulator until the weight of the
99
+ # current record plus previous records is greater than the random number.
100
+ total_weight = records.inject(0) { |sum,record|
101
+ sum + weight(record)
102
+ }
103
+ current_weight = 0
104
+ chosen_weight = 1 + Kernel.rand(total_weight)
105
+
106
+ records.each do |record|
107
+ current_weight += weight(record)
108
+ return record if current_weight >= chosen_weight
109
+ end
48
110
  end
49
111
 
50
- pri_hash.keys.sort.each do |key|
51
- yield key, pri_hash[key]
112
+ def weight(record)
113
+ record.weight == 0 ? 1 : record.weight * 10
52
114
  end
53
- end
54
- private_class_method :each_priority
55
115
 
56
- def self.find_weighted_server(records)
57
- return nil if records.nil? || records.empty?
58
- return records.first if records.size == 1
116
+ # Returns TTL for the cached records for this service.
117
+ # @param [String] service_name the service whose TTL we want
118
+ # @return [Integer] the TTL for this service, in seconds
119
+ def ttl(service_name)
120
+ return @record_cache[service_name].ttl
121
+ end
59
122
 
60
- # Calculate the sum of all weights in the list of resource records,
61
- # This is used to then select hosts until the weight exceeds what
62
- # random number we selected. For example, if we have weights of 1 8 and 3:
63
- #
64
- # |-|---|--------|
65
- # ^
66
- # We generate a random number 5, and iterate through the records, adding
67
- # the current record's weight to the accumulator until the weight of the
68
- # current record plus previous records is greater than the random number.
69
-
70
- total_weight = records.inject(0) { |sum,record|
71
- sum + weight(record)
72
- }
73
- current_weight = 0
74
- chosen_weight = 1 + Kernel.rand(total_weight)
75
-
76
- records.each do |record|
77
- current_weight += weight(record)
78
- return record if current_weight >= chosen_weight
123
+ # Checks if the cached entry for the given service has expired.
124
+ # @param [String] service_name the name of the service to check
125
+ # @return [Boolean] true if the entry has expired, false otherwise.
126
+ # Always returns true if the record had no TTL.
127
+ def expired?(service_name)
128
+ if entry = @record_cache[service_name]
129
+ return Time.now > (entry.resolution_time + entry.ttl)
130
+ else
131
+ return true
132
+ end
79
133
  end
80
- end
81
134
 
82
- def self.weight(record)
83
- record.weight == 0 ? 1 : record.weight * 10
135
+ private
136
+
137
+ # Groups the records by their priority and yields the groups
138
+ # in order of highest to lowest priority (lowest to highest numbers),
139
+ # one at a time.
140
+ # { 1 => [records], 2 => [records], etc. }
141
+ #
142
+ # @param [[Resolv::DNS::Resource::IN::SRV]] records the list of
143
+ # records for a given service
144
+ # @yields [[Resolv::DNS::Resource::IN::SRV]] a group of records of
145
+ # the same priority
146
+ def each_priority(records)
147
+ pri_hash = records.inject({}) do |groups, element|
148
+ groups[element.priority] ||= []
149
+ groups[element.priority] << element
150
+ groups
151
+ end
152
+
153
+ pri_hash.keys.sort.each do |key|
154
+ yield pri_hash[key]
155
+ end
156
+ end
84
157
  end
85
158
  end