puppet 5.5.16-universal-darwin → 5.5.17-universal-darwin

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +9 -9
  3. data/Gemfile.lock +18 -18
  4. data/ext/project_data.yaml +2 -2
  5. data/install.rb +3 -21
  6. data/lib/puppet/application/agent.rb +12 -0
  7. data/lib/puppet/application/device.rb +4 -4
  8. data/lib/puppet/application/resource.rb +4 -4
  9. data/lib/puppet/defaults.rb +4 -0
  10. data/lib/puppet/face/config.rb +10 -48
  11. data/lib/puppet/face/facts.rb +1 -1
  12. data/lib/puppet/face/plugin.rb +9 -2
  13. data/lib/puppet/module_tool/tar/mini.rb +11 -1
  14. data/lib/puppet/network/http/factory.rb +1 -11
  15. data/lib/puppet/parameter.rb +8 -0
  16. data/lib/puppet/provider/file/posix.rb +5 -0
  17. data/lib/puppet/provider/nameservice.rb +10 -3
  18. data/lib/puppet/provider/package/dnf.rb +1 -1
  19. data/lib/puppet/provider/package/rpm.rb +51 -13
  20. data/lib/puppet/provider/package/yum.rb +8 -4
  21. data/lib/puppet/provider/service/launchd.rb +20 -5
  22. data/lib/puppet/provider/service/systemd.rb +4 -9
  23. data/lib/puppet/provider/service/windows.rb +8 -0
  24. data/lib/puppet/provider/user/pw.rb +12 -3
  25. data/lib/puppet/provider/user/user_role_add.rb +4 -0
  26. data/lib/puppet/provider/user/useradd.rb +23 -7
  27. data/lib/puppet/resource.rb +17 -0
  28. data/lib/puppet/settings.rb +40 -0
  29. data/lib/puppet/type.rb +7 -0
  30. data/lib/puppet/type/exec.rb +14 -6
  31. data/lib/puppet/type/package.rb +10 -0
  32. data/lib/puppet/type/service.rb +7 -2
  33. data/lib/puppet/type/user.rb +1 -15
  34. data/lib/puppet/type/yumrepo.rb +3 -7
  35. data/lib/puppet/util/execution.rb +4 -3
  36. data/lib/puppet/util/http_proxy.rb +16 -2
  37. data/lib/puppet/util/selinux.rb +5 -1
  38. data/lib/puppet/util/windows/security.rb +2 -0
  39. data/lib/puppet/util/windows/service.rb +149 -4
  40. data/lib/puppet/util/windows/sid.rb +1 -0
  41. data/lib/puppet/version.rb +1 -1
  42. data/locales/puppet.pot +189 -193
  43. data/man/man5/puppet.conf.5 +10 -2
  44. data/man/man8/puppet-agent.8 +1 -1
  45. data/man/man8/puppet-apply.8 +1 -1
  46. data/man/man8/puppet-ca.8 +1 -1
  47. data/man/man8/puppet-catalog.8 +1 -1
  48. data/man/man8/puppet-cert.8 +1 -1
  49. data/man/man8/puppet-certificate.8 +1 -1
  50. data/man/man8/puppet-certificate_request.8 +1 -1
  51. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  52. data/man/man8/puppet-config.8 +1 -1
  53. data/man/man8/puppet-describe.8 +1 -1
  54. data/man/man8/puppet-device.8 +1 -1
  55. data/man/man8/puppet-doc.8 +1 -1
  56. data/man/man8/puppet-epp.8 +1 -1
  57. data/man/man8/puppet-facts.8 +1 -1
  58. data/man/man8/puppet-filebucket.8 +1 -1
  59. data/man/man8/puppet-generate.8 +1 -1
  60. data/man/man8/puppet-help.8 +1 -1
  61. data/man/man8/puppet-key.8 +1 -1
  62. data/man/man8/puppet-lookup.8 +1 -1
  63. data/man/man8/puppet-man.8 +1 -1
  64. data/man/man8/puppet-master.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-status.8 +1 -1
  73. data/man/man8/puppet.8 +2 -2
  74. data/spec/integration/provider/service/systemd_spec.rb +8 -5
  75. data/spec/integration/type/file_spec.rb +28 -0
  76. data/spec/integration/util/execution_spec.rb +27 -0
  77. data/spec/unit/application/agent_spec.rb +18 -0
  78. data/spec/unit/application/device_spec.rb +1 -1
  79. data/spec/unit/face/facts_spec.rb +9 -0
  80. data/spec/unit/face/plugin_spec.rb +8 -0
  81. data/spec/unit/module_tool/tar/mini_spec.rb +1 -1
  82. data/spec/unit/network/http/api/indirected_routes_spec.rb +26 -10
  83. data/spec/unit/network/http/factory_spec.rb +27 -5
  84. data/spec/unit/pops/validator/validator_spec.rb +7 -0
  85. data/spec/unit/provider/package/aptrpm_spec.rb +1 -1
  86. data/spec/unit/provider/package/dnf_spec.rb +7 -0
  87. data/spec/unit/provider/package/rpm_spec.rb +150 -16
  88. data/spec/unit/provider/package/yum_spec.rb +7 -0
  89. data/spec/unit/provider/service/launchd_spec.rb +28 -0
  90. data/spec/unit/provider/service/windows_spec.rb +20 -0
  91. data/spec/unit/provider/user/pw_spec.rb +37 -0
  92. data/spec/unit/provider/user/useradd_spec.rb +42 -0
  93. data/spec/unit/resource_spec.rb +26 -1
  94. data/spec/unit/transaction_spec.rb +18 -0
  95. data/spec/unit/type/exec_spec.rb +9 -0
  96. data/spec/unit/type/file/source_spec.rb +4 -4
  97. data/spec/unit/type/schedule_spec.rb +3 -1
  98. data/spec/unit/type/service_spec.rb +16 -0
  99. data/spec/unit/type/user_spec.rb +13 -13
  100. data/spec/unit/type/yumrepo_spec.rb +30 -0
  101. data/spec/unit/type_spec.rb +40 -0
  102. data/spec/unit/util/http_proxy_spec.rb +24 -1
  103. data/spec/unit/util/log_spec.rb +27 -1
  104. data/spec/unit/util/windows/service_spec.rb +9 -0
  105. metadata +3 -7
  106. data/ext/windows/eventlog/Rakefile +0 -32
  107. data/ext/windows/eventlog/puppetres.dll +0 -0
  108. data/ext/windows/eventlog/puppetres.mc +0 -18
@@ -172,9 +172,10 @@ class Puppet::Provider::NameService < Puppet::Provider
172
172
  end
173
173
 
174
174
  begin
175
- execute(self.addcmd, {:failonfail => true, :combine => true, :custom_environment => @custom_environment})
175
+ sensitive = has_sensitive_data?
176
+ execute(self.addcmd, {:failonfail => true, :combine => true, :custom_environment => @custom_environment, :sensitive => sensitive})
176
177
  if feature?(:manages_password_age) && (cmd = passcmd)
177
- execute(cmd, {:failonfail => true, :combine => true, :custom_environment => @custom_environment})
178
+ execute(cmd, {:failonfail => true, :combine => true, :custom_environment => @custom_environment, :sensitive => sensitive})
178
179
  end
179
180
  rescue Puppet::ExecutionFailure => detail
180
181
  raise Puppet::Error, _("Could not create %{resource} %{name}: %{detail}") % { resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace
@@ -276,13 +277,19 @@ class Puppet::Provider::NameService < Puppet::Provider
276
277
  self.class.validate(param, value)
277
278
  cmd = modifycmd(param, munge(param, value))
278
279
  raise Puppet::DevError, _("Nameservice command must be an array") unless cmd.is_a?(Array)
280
+ sensitive = has_sensitive_data?(param)
279
281
  begin
280
- execute(cmd, {:failonfail => true, :combine => true, :custom_environment => @custom_environment})
282
+ execute(cmd, {:failonfail => true, :combine => true, :custom_environment => @custom_environment, :sensitive => sensitive})
281
283
  rescue Puppet::ExecutionFailure => detail
282
284
  raise Puppet::Error, _("Could not set %{param} on %{resource}[%{name}]: %{detail}") % { param: param, resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace
283
285
  end
284
286
  end
285
287
 
288
+ #Derived classes can override to declare sensitive data so a flag can be passed to execute
289
+ def has_sensitive_data?(property = nil)
290
+ false
291
+ end
292
+
286
293
  # From overriding Puppet::Property#insync? Ruby Etc::getpwnam < 2.1.0 always
287
294
  # returns a struct with binary encoded string values, and >= 2.1.0 will return
288
295
  # binary encoded strings for values incompatible with current locale charset,
@@ -9,7 +9,7 @@ Puppet::Type.type(:package).provide :dnf, :parent => :yum do
9
9
  These options should be specified as a string (e.g. '--flag'), a hash (e.g. {'--flag' => 'value'}),
10
10
  or an array where each element is either a string or a hash."
11
11
 
12
- has_feature :install_options, :versionable, :virtual_packages
12
+ has_feature :install_options, :versionable, :virtual_packages, :install_only
13
13
 
14
14
  commands :cmd => "dnf", :rpm => "rpm"
15
15
 
@@ -14,6 +14,7 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
14
14
  has_feature :install_options
15
15
  has_feature :uninstall_options
16
16
  has_feature :virtual_packages
17
+ has_feature :install_only
17
18
 
18
19
  # Note: self:: is required here to keep these constants in the context of what will
19
20
  # eventually become this Puppet::Type::Package::ProviderRpm class.
@@ -21,6 +22,7 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
21
22
  self::NEVRA_FORMAT = %Q{%{NAME} %|EPOCH?{%{EPOCH}}:{0}| %{VERSION} %{RELEASE} %{ARCH}\\n}
22
23
  self::NEVRA_REGEX = %r{^'?(\S+) (\S+) (\S+) (\S+) (\S+)$}
23
24
  self::NEVRA_FIELDS = [:name, :epoch, :version, :release, :arch]
25
+ self::MULTIVERSION_SEPARATOR = "; "
24
26
 
25
27
  ARCH_LIST = [
26
28
  'noarch',
@@ -80,12 +82,9 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
80
82
 
81
83
  # list out all of the packages
82
84
  begin
83
- execpipe("#{command(:rpm)} -qa #{nosignature} #{nodigest} --qf '#{self::NEVRA_FORMAT}'") { |process|
85
+ execpipe("#{command(:rpm)} -qa #{nosignature} #{nodigest} --qf '#{self::NEVRA_FORMAT}' | sort") { |process|
84
86
  # now turn each returned line into a package object
85
- process.each_line { |line|
86
- hash = nevra_to_hash(line)
87
- packages << new(hash) unless hash.empty?
88
- }
87
+ nevra_to_multiversion_hash(process).each { |hash| packages << new(hash) }
89
88
  }
90
89
  rescue Puppet::ExecutionFailure
91
90
  raise Puppet::Error, _("Failed to list packages"), $!.backtrace
@@ -101,7 +100,7 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
101
100
  #NOTE: Prior to a fix for issue 1243, this method potentially returned a cached value
102
101
  #IF YOU CALL THIS METHOD, IT WILL CALL RPM
103
102
  #Use get(:property) to check if cached values are available
104
- cmd = ["-q", @resource[:name], "#{self.class.nosignature}", "#{self.class.nodigest}", "--qf", "'#{self.class::NEVRA_FORMAT}'"]
103
+ cmd = ["-q", @resource[:name], "#{self.class.nosignature}", "#{self.class.nodigest}", "--qf", "#{self.class::NEVRA_FORMAT}"]
105
104
 
106
105
  begin
107
106
  output = rpm(*cmd)
@@ -118,9 +117,7 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
118
117
  return nil
119
118
  end
120
119
  end
121
- # FIXME: We could actually be getting back multiple packages
122
- # for multilib and this will only return the first such package
123
- @property_hash.update(self.class.nevra_to_hash(output))
120
+ @property_hash.update(self.class.nevra_to_multiversion_hash(output))
124
121
 
125
122
  @property_hash.dup
126
123
  end
@@ -131,8 +128,8 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
131
128
  @resource.fail _("RPMs must specify a package source")
132
129
  end
133
130
 
134
- cmd = [command(:rpm), "-q", "--qf", "'#{self.class::NEVRA_FORMAT}'", "-p", source]
135
- h = self.class.nevra_to_hash(execute(cmd))
131
+ cmd = [command(:rpm), "-q", "--qf", "#{self.class::NEVRA_FORMAT}", "-p", source]
132
+ h = self.class.nevra_to_multiversion_hash(execute(cmd))
136
133
  h[:ensure]
137
134
  rescue Puppet::ExecutionFailure => e
138
135
  raise Puppet::Error, e.message, e.backtrace
@@ -169,7 +166,11 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
169
166
  if @resource[:name].start_with? nav
170
167
  identifier = nav
171
168
  else
172
- identifier = name
169
+ if @resource[:install_only]
170
+ identifier = get(:ensure).split(self.class::MULTIVERSION_SEPARATOR).map { |ver| "#{name}-#{ver}" }
171
+ else
172
+ identifier = name
173
+ end
173
174
  end
174
175
  end
175
176
  # If an arch is specified in the resource, uninstall that arch,
@@ -309,8 +310,12 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
309
310
 
310
311
  def insync?(is)
311
312
  return false if [:purged, :absent].include?(is)
313
+ return false if is.include?(self.class::MULTIVERSION_SEPARATOR) && !@resource[:install_only]
314
+
312
315
  should = resource[:ensure]
313
- 0 == rpm_compareEVR(rpm_parse_evr(should), rpm_parse_evr(is))
316
+ is.split(self.class::MULTIVERSION_SEPARATOR).any? do |version|
317
+ 0 == self.rpm_compareEVR(rpm_parse_evr(should), rpm_parse_evr(version))
318
+ end
314
319
  end
315
320
 
316
321
  # parse a rpm "version" specification
@@ -413,4 +418,37 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
413
418
 
414
419
  return hash
415
420
  end
421
+
422
+ # @param line [String] multiple lines of rpm package query information
423
+ # @return list of [Hash] of NEVRA_FIELDS strings parsed from package info
424
+ # or an empty list if we failed to parse
425
+ # @api private
426
+ def self.nevra_to_multiversion_hash(multiline)
427
+ list = []
428
+ multiversion_hash = {}
429
+ multiline.each_line do |line|
430
+ hash = self.nevra_to_hash(line)
431
+ if !hash.empty?
432
+ if multiversion_hash.empty?
433
+ multiversion_hash = hash.dup
434
+ next
435
+ end
436
+
437
+ if multiversion_hash[:name] != hash[:name]
438
+ list << multiversion_hash
439
+ multiversion_hash = hash.dup
440
+ next
441
+ end
442
+
443
+ if !multiversion_hash[:ensure].include?(hash[:ensure])
444
+ multiversion_hash[:ensure].concat("#{self::MULTIVERSION_SEPARATOR}#{hash[:ensure]}")
445
+ end
446
+ end
447
+ end
448
+ list << multiversion_hash if multiversion_hash
449
+ if list.size == 1
450
+ return list[0]
451
+ end
452
+ return list
453
+ end
416
454
  end
@@ -9,7 +9,7 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
9
9
  These options should be specified as a string (e.g. '--flag'), a hash (e.g. {'--flag' => 'value'}),
10
10
  or an array where each element is either a string or a hash."
11
11
 
12
- has_feature :install_options, :versionable, :virtual_packages
12
+ has_feature :install_options, :versionable, :virtual_packages, :install_only
13
13
 
14
14
  commands :cmd => "yum", :rpm => "rpm"
15
15
 
@@ -203,7 +203,10 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
203
203
  end
204
204
  current_package = self.query
205
205
  if current_package
206
- if rpm_compareEVR(rpm_parse_evr(should), rpm_parse_evr(current_package[:ensure])) < 0
206
+ if @resource[:install_only]
207
+ self.debug "Updating package #{@resource[:name]} from version #{current_package[:ensure]} to #{should} as install_only packages are never downgraded"
208
+ operation = update_command
209
+ elsif rpm_compareEVR(rpm_parse_evr(should), rpm_parse_evr(current_package[:ensure])) < 0
207
210
  self.debug "Downgrading package #{@resource[:name]} from version #{current_package[:ensure]} to #{should}"
208
211
  operation = :downgrade
209
212
  elsif rpm_compareEVR(rpm_parse_evr(should), rpm_parse_evr(current_package[:ensure])) > 0
@@ -228,10 +231,11 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
228
231
  is = self.query
229
232
  raise Puppet::Error, _("Could not find package %{name}") % { name: self.name } unless is
230
233
 
234
+ version = is[:ensure]
231
235
  # FIXME: Should we raise an exception even if should == :latest
232
236
  # and yum updated us to a version other than @param_hash[:ensure] ?
233
- vercmp_result = rpm_compareEVR(rpm_parse_evr(should), rpm_parse_evr(is[:ensure]))
234
- raise Puppet::Error, _("Failed to update to version %{should}, got version %{version} instead") % { should: should, version: is[:ensure] } if vercmp_result != 0
237
+ raise Puppet::Error, _("Failed to update to version %{should}, got version %{version} instead") % { should: should, version: version } unless
238
+ insync?(version)
235
239
  end
236
240
  end
237
241
 
@@ -240,12 +240,20 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
240
240
  def status
241
241
  if @resource && ((@resource[:hasstatus] == :false) || (@resource[:status]))
242
242
  return super
243
- else
244
- if @property_hash[:status].nil?
245
- :absent
243
+ elsif @property_hash[:status].nil?
244
+ # property_hash was flushed so the service changed status
245
+ service_name = @resource[:name]
246
+ # Updating services with new statuses
247
+ job_list = self.class.job_list
248
+ # if job is present in job_list, return its status
249
+ if job_list.key?(service_name)
250
+ job_list[service_name]
251
+ # if job is no longer present in job_list, it was stopped
246
252
  else
247
- @property_hash[:status]
253
+ :stopped
248
254
  end
255
+ else
256
+ @property_hash[:status]
249
257
  end
250
258
  end
251
259
 
@@ -313,7 +321,14 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
313
321
  job_plist_disabled = nil
314
322
  overrides_disabled = nil
315
323
 
316
- _, job_plist = plist_from_label(resource[:name])
324
+ begin
325
+ _, job_plist = plist_from_label(resource[:name])
326
+ rescue Puppet::Error => err
327
+ # if job does not exist, log the error and return false as on other platforms
328
+ Puppet.log_exception(err)
329
+ return :false
330
+ end
331
+
317
332
  job_plist_disabled = job_plist["Disabled"] if job_plist.has_key?("Disabled")
318
333
 
319
334
  if FileTest.file?(self.class.launchd_overrides) and overrides = self.class.read_overrides
@@ -1,5 +1,7 @@
1
1
  # Manage systemd services using systemctl
2
2
 
3
+ require 'puppet/file_system'
4
+
3
5
  Puppet::Type.type(:service).provide :systemd, :parent => :base do
4
6
  desc "Manages `systemd` services using `systemctl`.
5
7
 
@@ -9,14 +11,7 @@ Puppet::Type.type(:service).provide :systemd, :parent => :base do
9
11
 
10
12
  commands :systemctl => "systemctl"
11
13
 
12
- if Facter.value(:osfamily).downcase == 'debian'
13
- # With multiple init systems on Debian, it is possible to have
14
- # pieces of systemd around (e.g. systemctl) but not really be
15
- # using systemd. We do not do this on other platforms as it can
16
- # cause issues when running in a chroot without /run mounted
17
- # (PUP-5577)
18
- confine :exists => "/run/systemd/system"
19
- end
14
+ confine :true => Puppet::FileSystem.exist?('/proc/1/comm') && Puppet::FileSystem.read('/proc/1/comm').include?('systemd')
20
15
 
21
16
  defaultfor :osfamily => [:archlinux]
22
17
  defaultfor :osfamily => :redhat, :operatingsystemmajrelease => ["7", "8"]
@@ -24,7 +19,7 @@ Puppet::Type.type(:service).provide :systemd, :parent => :base do
24
19
  defaultfor :osfamily => :suse
25
20
  defaultfor :osfamily => :coreos
26
21
  defaultfor :operatingsystem => :amazon, :operatingsystemmajrelease => ["2"]
27
- defaultfor :operatingsystem => :debian, :operatingsystemmajrelease => ["8", "stretch/sid", "9", "buster/sid"]
22
+ defaultfor :operatingsystem => :debian, :operatingsystemmajrelease => ["8", "stretch/sid", "9", "buster/sid", "10", "bullseye/sid"]
28
23
  defaultfor :operatingsystem => :ubuntu, :operatingsystemmajrelease => ["15.04","15.10","16.04","16.10","17.04","17.10","18.04"]
29
24
  defaultfor :operatingsystem => :cumuluslinux, :operatingsystemmajrelease => ["3"]
30
25
 
@@ -34,6 +34,12 @@ Puppet::Type.type(:service).provide :windows, :parent => :service do
34
34
  raise Puppet::Error.new(_("Cannot enable %{resource_name} for manual start, error was: %{detail}") % { resource_name: @resource[:name], detail: detail }, detail )
35
35
  end
36
36
 
37
+ def delayed_start
38
+ Puppet::Util::Windows::Service.set_startup_mode( @resource[:name], :SERVICE_AUTO_START, true )
39
+ rescue => detail
40
+ raise Puppet::Error.new(_("Cannot enable %{resource_name} for delayed start, error was: %{detail}") % { resource_name: @resource[:name], detail: detail }, detail )
41
+ end
42
+
37
43
  def enabled?
38
44
  return :false unless Puppet::Util::Windows::Service.exists?(@resource[:name])
39
45
 
@@ -46,6 +52,8 @@ Puppet::Type.type(:service).provide :windows, :parent => :service do
46
52
  :true
47
53
  when :SERVICE_DEMAND_START
48
54
  :manual
55
+ when :SERVICE_DELAYED_AUTO_START
56
+ :delayed
49
57
  when :SERVICE_DISABLED
50
58
  :false
51
59
  else
@@ -66,11 +66,11 @@ Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService::
66
66
 
67
67
  # use pw to update password hash
68
68
  def password=(cryptopw)
69
- Puppet.debug "change password for user '#{@resource[:name]}' method called with hash '#{cryptopw}'"
69
+ Puppet.debug "change password for user '#{@resource[:name]}' method called with hash [redacted]"
70
70
  stdin, _, _ = Open3.popen3("pw user mod #{@resource[:name]} -H 0")
71
71
  stdin.puts(cryptopw)
72
72
  stdin.close
73
- Puppet.debug "finished password for user '#{@resource[:name]}' method called with hash '#{cryptopw}'"
73
+ Puppet.debug "finished password for user '#{@resource[:name]}' method called with hash [redacted]"
74
74
  end
75
75
 
76
76
  # get password from /etc/master.passwd
@@ -78,10 +78,19 @@ Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService::
78
78
  Puppet.debug "checking password for user '#{@resource[:name]}' method called"
79
79
  current_passline = `getent passwd #{@resource[:name]}`
80
80
  current_password = current_passline.chomp.split(':')[1] if current_passline
81
- Puppet.debug "finished password for user '#{@resource[:name]}' method called : '#{current_password}'"
81
+ Puppet.debug "finished password for user '#{@resource[:name]}' method called : [redacted]"
82
82
  current_password
83
83
  end
84
84
 
85
+ def has_sensitive_data?(property = nil)
86
+ #Check for sensitive values?
87
+ properties = property ? [property] : Puppet::Type.type(:user).validproperties
88
+ properties.any? do |prop|
89
+ p = @resource.parameter(prop)
90
+ p && p.respond_to?(:is_sensitive) && p.is_sensitive
91
+ end
92
+ end
93
+
85
94
  # Get expiry from system and convert to Puppet-style date
86
95
  def expiry
87
96
  expiry = self.get(:expiry)
@@ -202,6 +202,10 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd, :source =>
202
202
  shadow_entry[5].empty? ? -1 : shadow_entry[5]
203
203
  end
204
204
 
205
+ def has_sensitive_data?(property = nil)
206
+ false
207
+ end
208
+
205
209
  # Read in /etc/shadow, find the line for our used and rewrite it with the
206
210
  # new pw. Smooth like 80 grit sandpaper.
207
211
  #
@@ -147,19 +147,35 @@ Puppet::Type.type(:user).provide :useradd, :parent => Puppet::Provider::NameServ
147
147
  # validproperties is a list of properties in undefined order
148
148
  # sort them to have a predictable command line in tests
149
149
  Puppet::Type.type(:user).validproperties.sort.each do |property|
150
- next if property == :ensure
151
- next if property_manages_password_age?(property)
152
- next if (property == :groups) && @resource.forcelocal?
153
- next if (property == :expiry) && @resource.forcelocal?
150
+ value = get_value_for_property(property)
151
+ next if value.nil?
154
152
  # the value needs to be quoted, mostly because -c might
155
153
  # have spaces in it
156
- if (value = @resource.should(property)) && (value != "")
157
- cmd << flag(property) << munge(property, value)
158
- end
154
+ cmd << flag(property) << munge(property, value)
159
155
  end
160
156
  cmd
161
157
  end
162
158
 
159
+ def get_value_for_property(property)
160
+ return nil if property == :ensure
161
+ return nil if property_manages_password_age?(property)
162
+ return nil if property == :groups and @resource.forcelocal?
163
+ return nil if property == :expiry and @resource.forcelocal?
164
+ value = @resource.should(property)
165
+ return nil if !value || value == ""
166
+
167
+ value
168
+ end
169
+
170
+ def has_sensitive_data?(property = nil)
171
+ #Check for sensitive values?
172
+ properties = property ? [property] : Puppet::Type.type(:user).validproperties
173
+ properties.any? do |prop|
174
+ p = @resource.parameter(prop)
175
+ p && p.respond_to?(:is_sensitive) && p.is_sensitive
176
+ end
177
+ end
178
+
163
179
  def addcmd
164
180
  if @resource.forcelocal?
165
181
  cmd = [command(:localadd)]
@@ -410,6 +410,8 @@ class Puppet::Resource
410
410
  end
411
411
 
412
412
  # Convert our resource to yaml for Hiera purposes.
413
+ #
414
+ # @deprecated Use {to_hiera_hash} instead.
413
415
  def to_hierayaml
414
416
  # Collect list of attributes to align => and move ensure first
415
417
  attr = parameters.keys
@@ -429,6 +431,21 @@ class Puppet::Resource
429
431
  " %s:\n%s" % [self.title, attributes]
430
432
  end
431
433
 
434
+ # Convert our resource to a hiera hash suitable for serialization.
435
+ def to_hiera_hash
436
+ # to_data_hash converts to safe Data types, e.g. no symbols, unicode replacement character
437
+ h = to_data_hash
438
+
439
+ params = h['parameters'] || {}
440
+ value = params.delete('ensure')
441
+
442
+ res = {}
443
+ res['ensure'] = value if value
444
+ res.merge!(Hash[params.sort])
445
+
446
+ return { h['title'] => res }
447
+ end
448
+
432
449
  # Convert our resource to Puppet code.
433
450
  def to_manifest
434
451
  # Collect list of attributes to align => and move ensure first
@@ -84,6 +84,46 @@ class Puppet::Settings
84
84
  "puppet.conf"
85
85
  end
86
86
 
87
+ def stringify_settings(section, settings = :all)
88
+ values_from_the_selected_section =
89
+ values(nil, section.to_sym)
90
+
91
+ loader_settings = {
92
+ :environmentpath => values_from_the_selected_section.interpolate(:environmentpath),
93
+ :basemodulepath => values_from_the_selected_section.interpolate(:basemodulepath),
94
+ }
95
+
96
+ Puppet.override(Puppet.base_context(loader_settings),
97
+ _("New environment loaders generated from the requested section.")) do
98
+ # And now we can lookup values that include those from environments configured from
99
+ # the requested section
100
+ values = values(Puppet[:environment].to_sym, section.to_sym)
101
+
102
+ to_be_rendered = {}
103
+ settings = Puppet.settings.to_a.collect(&:first) if settings == :all
104
+ settings.sort.each do |setting_name|
105
+ to_be_rendered[setting_name] = values.print(setting_name.to_sym)
106
+ end
107
+
108
+ stringifyhash(to_be_rendered)
109
+ end
110
+ end
111
+
112
+ def stringifyhash(hash)
113
+ newhash = {}
114
+ hash.each do |key, val|
115
+ key = key.to_s
116
+ if val.is_a? Hash
117
+ newhash[key] = stringifyhash(val)
118
+ elsif val.is_a? Symbol
119
+ newhash[key] = val.to_s
120
+ else
121
+ newhash[key] = val
122
+ end
123
+ end
124
+ newhash
125
+ end
126
+
87
127
  # Create a new collection of config settings.
88
128
  def initialize
89
129
  @config = {}